show only posts for a tag
-
hello everyone
i have tried to handle this myself by reading lots of documentation but i seem not to be able to solve it, so here i am asking for some help.i am trying to create a page that will show all the posts that have a certain tag, like “vacation”.
i have read this doc here
https://codex.www.ads-software.com/Template_Tags/query_postsso i created a template page called “tag.php” and put the following code in it
<?php /** * Show latest post for Tags * * @return * @param object $tag * @param object $show[optional] */ function show_title_tag( $tag, $show=10 ) { global $post; $posts = query_posts('tag=' . $tag . '&showposts=' . $show ); echo "<ul>"; foreach ($posts as $post ) : setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></li> <?php endforeach; echo "</ul>"; } ?>
then i created a new page, associated this page with the template page called “tag”.
at this point, i don’t know how i can recall the page that shows the posts with a certain tag.
i am not sure i did everything as i was supposed to, maybe i just don’t understand where i should put the code with the query_posts() and how i should recall the page with the parameters.
any help? thank you!
- The topic ‘show only posts for a tag’ is closed to new replies.