Custom archive page titles
-
Im trying to use the following code in the header on the archive.php page.
So that i can have different page titles depending on whether the page is viewed by category or date for example. But am struggling to get this to work.
I have removed the get_header function and have added a custom header which works fine. But this code will not work if placed in the header section.
Any ideas would be most appreciated.
Thanks Alex
<?php if (have_posts()) : ?>
<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
<?php /* If this is a category archive */ if (is_category()) { ?>
<title>Archived Travel posts, <?php echo single_cat_title(); ?>’- Alex’s Travel Blog</title><?php /* If this is a daily archive */ } elseif (is_day()) { ?>
<title>Archived Travel posts, <?php the_time(‘F jS, Y’); ?> – Alex’s Travel Blog</title><?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
<title>Archived Travel posts, <?php the_time(‘F, Y’); ?> – Alex’s Travel Blog</title><?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
<title>Archived Travel posts, <?php the_time(‘Y’); ?> – Alex’s Travel Blog</title><?php /* If this is a search */ } elseif (is_search()) { ?>
<title>Archived Travel posts, Search Results – Alex’s Travel Blog</title><?php } ?>
- The topic ‘Custom archive page titles’ is closed to new replies.