0
votes

In my archives.php file in my custom WordPress theme, I have the following code:

<div class="page-title">
<?php
                if ( is_day() ) :
                    printf( __( 'Daily Archives: %s', 'sturd' ),     '<span>' . get_the_date() . '</span>' );
                elseif ( is_month() ) :
                    printf( __( 'Monthly Archives: %s', 'sturd' ), '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'sturd' ) ) . '</span>' );
                elseif ( is_year() ) :
                    printf( __( 'Yearly Archives: %s', 'sturd' ), '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'sturd' ) ) . '</span>' );
                else :
                    _e( 'Archives', 'sturd' );
                endif;
            ?>
</div>

I want there to be another statement so that if this is a category page, it displays just the category title in the page title div, and not just the word Archives (as it does currently).

I hope this is posted in the correct section.

Thanks in advance.

Sam

1
In the future, you might prefer to post WP related questions at WordPress Answers. - yelly

1 Answers

1
votes

First of all, I suggest you get aquainted with the WP template hierarchy. I would usually suggest using a separate category.php template file for displaying categories, and using single_cat_title() for displaying the category name.

If you want to use the main archive.php template, you can add an is_category() clause and then use single_cat_title() to get the name.