I
I
Igor Pushkarsky2015-11-07 13:11:28
WordPress
Igor Pushkarsky, 2015-11-07 13:11:28

How to make a post page template on a selected tag in WP?

There is a function wp_tag_cloud() , it displays a list of tags used in articles.
Outputs in the form of links, but it is necessary in the form

<ul class="lyrics-search ul-search-scroll" itemscope
                    itemtype="http://schema.org/BreadcrumbList">
                    <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
                        <div class="lyrics-search-image"><img itemprop="image"
                                                              src="<?=get_bloginfo('template_url')?>/images/lyrics-search/vesh.jpg"
                                                              alt="Иллюстрация к настроению Вещь"/>
                        </div>
                        <a href="#" itemprop="item">Вещь!</a>
                    </li>
                    <li>
                        <div class="lyrics-search-image"><img src="<?=get_bloginfo('template_url')?>/images/lyrics-search/porzhat.jpg"
                                                              alt="Иллюстрация к настроению Вещь"/>
                        </div>
                        <a href="#">Поржать!</a>
                    </li>
                    <li>
                        <div class="lyrics-search-image"><img src="<?=get_bloginfo('template_url')?>/images/lyrics-search/glum.jpg"
                                                              alt="Иллюстрация к настроению Вещь"/>
                        </div>
                        <a href="#">За-жизнь!</a>
                    </li>
                    <li>
                        <div class="lyrics-search-image"><img src="<?=get_bloginfo('template_url')?>/images/lyrics-search/vesh.jpg"
                                                              alt="Иллюстрация к настроению Вещь"/>
                        </div>
                        <a href="#">Глум!</a>
                    </li>
                    <li>
                        <div class="lyrics-search-image"><img src="<?=get_bloginfo('template_url')?>/images/lyrics-search/mat-peremat.jpg"
                                                              alt="Иллюстрация к настроению Вещь"/>
                        </div>
                        <a href="#">Мать-перемать!</a>
                    </li>
                    <li>
                        <div class="lyrics-search-image"><img src="<?=get_bloginfo('template_url')?>/images/lyrics-search/vesh.jpg"
                                                              alt="Иллюстрация к настроению Вещь"/>
                        </div>
                        <a href="#">Детям до 16-ти!</a>
                    </li>
                    <li>
                        <div class="lyrics-search-image"><img src="<?=get_bloginfo('template_url')?>/images/lyrics-search/vesh.jpg"
                                                              alt="Иллюстрация к настроению Вещь"/>
                        </div>
                        <a href="#">Минор!</a>
                    </li>
                    <li>
                        <div class="lyrics-search-image"><img src="<?=get_bloginfo('template_url')?>/images/lyrics-search/vesh.jpg"
                                                              alt="Иллюстрация к настроению Вещь"/>
                        </div>
                        <a href="#">Заумь!</a>
                    </li>
                    <li>
                        <div class="lyrics-search-image"><img src="<?=get_bloginfo('template_url')?>/images/lyrics-search/vesh.jpg"
                                                              alt="Иллюстрация к настроению Вещь"/>
                        </div>
                        <a href="#">Нудёж!</a>
                    </li>
                    <li>
                        <div class="lyrics-search-image"><img src="<?=get_bloginfo('template_url')?>/images/lyrics-search/vesh.jpg"
                                                              alt="Иллюстрация к настроению Вещь"/>
                        </div>
                        <a href="#">Заморочиться!</a>
                    </li>
                </ul>

When you click on which should go to some kind of template, a list of all posts that match the selected tag.
So this is how to create it, and how to display posts that match the selected tag there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2015-11-07
@RainMEN

Use the get_terms() function to get the tags (which is what wp_tag_cloud() also uses). And for output in the desired html format, use your foreach().
As for "go to some template, a list of all posts that match the selected tag" - just form the links in your arbitrary html above correctly. They should be of the form domain.com/tag/tag_slug. When you click on this link, WordPress will automatically parse the query and get the posts from the database. He will display them in one of the templates, according to the hierarchy .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question