Display Archive year only if an archive is selected
-
Hello,
I have a custom arvhive list that shows archives by year instead of month. I am using the following code to do it:<ul> <?php $years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts ORDER BY post_date"); foreach($years as $year) : ?> <li><a href="<?php echo get_year_link($year); ?> "><?php echo $year; ?></a></li> <?php endforeach; ?> </ul>
When a person goes to that archive I would like to show the year that they are in. I used the following code to echo the year:
<?php echo $year; ?>
My problem is that if no year is selected it shows: 0. I would like it to say: “All” instead if no year is selected. How would I make it do that?
Thanks
- The topic ‘Display Archive year only if an archive is selected’ is closed to new replies.