Insert "Category" Dynamically on Archive Page
-
Hi everyone,
I am using a theme for WordPress that allows me to display excerpts of a custom post type. The pages involved use the archive.php template.
Here’s an example. In this case, I’m displaying all of the entires for a particular custom post type/taxonomy, specifically “publication/topic/evolution”.
Here’s a link to the page in question:
http://complexsystems.org/topic/evolution/
Here’s my dilemma. The archive.php uses a static title that displays the word “Archive”. I have a number of these archive pages on the site. So if it is at all possible, I would like to display the actual label, such as “Evolution” instead of the word “Archive”.
I need this to be dynamically generated, because there are several different archives.
Here’s the code the php page. And here’s my question. Is there an easy way to replace the static word “Archive” with a dynamic call that will display the currently selected custom post type/taxonomy?
——————————-
start code
——————————–
<?php get_header(); ?><div class=”main-content-wrap”>
<div class=”main-content”><div class=”archive-taxonomy”>
<?php
$archive_info = “”;
$archive_title = __( ‘Archive’, ‘sundak’ );
if( is_category() ) {
$archive_info = __( ‘Category’, ‘sundak’ );
$archive_title = single_cat_title( ”, false );
} elseif( is_tag() ) {
$archive_info = __( ‘Tag’, ‘sundak’ );
$archive_title = single_tag_title( ”, false );
} elseif( is_author() ) {
$archive_info = __( ‘Author’, ‘sundak’ );
$archive_title = get_the_author();
} elseif( is_year() ) {
$archive_info = __( ‘Year’, ‘sundak’ );
$archive_title = get_the_date( ‘Y’ );
} elseif( is_month() ) {
$archive_info = __( ‘Month’, ‘sundak’ );
$archive_title = get_the_date( ‘F Y’ );
} elseif( is_day() ) {
$archive_info = __( ‘Day’, ‘sundak’ );
$archive_title = get_the_date( ‘F j, Y’ );
} else {
$archive_title = __( ‘Archive’, ‘sundak’ );
}
?>
<h2>
<span><?php echo esc_attr( $archive_info ); ?></span>
<?php echo esc_attr( $archive_title ); ?>
</h2>
</div><?php
if( have_posts() ) {
echo ‘<div class=”posts-wrap posts-wrap-grid row”>’;
while( have_posts() ) {
the_post();// load the content
echo ‘<div class=”col-6″>’;
get_template_part( ‘content’ );
echo ‘</div>’;
}
echo ‘</div>’;// pagination
sundak_pagination();
} else {
get_template_part( ‘content’, ‘none’ );
}
?></div>
</div><?php get_sidebar(); ?>
<?php get_footer(); ?>
The topic ‘Insert "Category" Dynamically on Archive Page’ is closed to new replies.