K
K
ksshk2018-04-02 15:13:41
metadata
ksshk, 2018-04-02 15:13:41

How to display a list of records belonging to a specific label (tag)?

Tell me please.
There is a heading "recreation places", in which there are several tags: "parks", "cafes", "beaches" and so on.
The output of entries from the rubric is done.
It would be desirable that at the top of the page for this rubric a list of tags for this rubric was displayed and there were corresponding links. Labels are rendered using the following code:

$cat_id = get_query_var('cat'); // получаем ID текущей категории   
    $tags = get_tags_in_cat($cat_id);
    foreach($tags as $tag_id => $tag_name)
        $tags_print[] = '<a href="' .get_tag_link($tag_id). '">' .$tag_name. '</a>';
    echo implode($tags_print);

function get_tags_in_cat($cat_id)
{
    $posts = get_posts( array('category' => $cat_id, 'numberposts' => -1) );
    $tags = array();
  
    foreach($posts as $post)
    {
        $post_tags = get_the_tags($post->ID);
        if( !empty($post_tags) )
            foreach($post_tags as $tag)
                $tags[$tag->term_id] = $tag->name;
      
    }
    asort($tags);
    return $tags;
}

But when you click on the label link, it does not display a list of all entries for this label, but one of the entries.
Please help me fix it.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question