Display search query (tag / archive) in WordPress

I am currently using the sidebar in WordPress and displaying "Archive" and "Popular Tags" in the side column.

Example - Archive Code

  <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>

The tags that were used in the message are displayed here. I also have an Archive (Dates) -

<?php wp_get_archives(); ?>

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

'Here are the posts for (Archive / Tag).

So, if I looked at the posts from May 2015. He would say: β€œHere are the messages for May 2015”

Does anyone have any ideas?

+2
source share
2 answers

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'); 
} ?>
0
source

, , :

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

Source: https://habr.com/ru/post/1589021/


All Articles