Displaying search term (Tag/Archive) in WordPress

I am currently using a sidebar in WordPress, and displaying ‘Archive’ and ‘Popular Tags’ in the side column.

For Example – Archive code

Read More
  <div class="populartags">
    <?php
    $tags = get_tags();
    $html = '<div class="post_tags">';
    foreach ( $tags as $tag ) {
      $tag_link = get_tag_link( $tag->term_id );

      $html .= "<a style='color:#333;' href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
      $html .= "{$tag->name}</a>";
    }
    $html .= '</div>';
    echo $html;
    ?>
  </div>

This displays any tags which have been used on a post.
I also have Archive (Dates) –

<?php wp_get_archives(); ?>

These pages, go to archive.php, which is great.
What I am tyring to achieve. Is a line of text, which says

‘ Here are the posts for (Archive / Tag).’

So, If I viewed posts from May 2015. It would say ‘Here are the posts for May 2015’

Anyone got any ideas?

Related posts

2 comments

  1. You need to edit archive.php

    Just add

    <?php if( is_month() ) { ?> // Check if month based archive
        <?php echo 'Here are the posts for'; ?>
        <?php the_time('F Y'); 
    } ?>
    
  2. This displays either the date, or the tag and the number of results incase people are still looking:

        <?php echo 'Search Results'; ?>
        <?php echo 'Displaying ' . count($posts) . ' results for '; ?>
        <?php echo $tag ?>
        <?php if( is_month() ) { ?>
        <?php the_time('F Y'); 
      } ?>
    

Comments are closed.