WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how-to: list of post titles, matching certain tag - in sidebar? (7 posts)

  1. trehug
    Member
    Posted 6 years ago #

    hi -
    i am just trying to figure out how to create a list of links in my sidebar that show posts that have been given a certain tag.

    in so doing, i could just create a new post, give it a tag, and then it would show up in my sidebar as a new link.

    for example, if i have tagged 3 posts with "cats" - i would like to have a list in my sidebar with a title "Cats" that shows each post name as a link...like so:

    Cats
    ----

    tabby (link to post)
    calico (link to post)
    abyssinian (link to post)

    any advice please?!
    thanks kindly, tre.

  2. Kafkaesqui

    Posted 6 years ago #

    A little code to play with:

    <?php
    $tags = 'cats'; // separate multiple tags with comma
    $numposts = '5'; // -1 for all
    $myquery = new WP_Query("tag=$tags&showposts=$numposts");
    ?>
    <?php if($myquery->have_posts()) : ?>
    <ul><li><h2><?php echo ucwords(strtolower($tags)); ?></h2>
    	<ul>
    <?php while($myquery->have_posts()) : $myquery->the_post(); ?>
    	<li><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    	</ul>
    </li></ul>
    <?php endif; ?>
  3. trehug
    Member
    Posted 6 years ago #

    thanks a lot!!

  4. MichaelH
    Member
    Posted 6 years ago #

    Thanks for that code Kaf.

    Interesting, there a number of new additions to the query variables (e.g. tag=) and some of those are explained in Ryan's Taxonomy Intersections and Unions post.

  5. hesam
    Member
    Posted 6 years ago #

    Hi

    when I use this code, in the article page, it just list the posts of the category that the post of that page is in.

    How I can retrieve other categories' posts?

    this is what I am using:

    rewind_posts();

    $recent = new WP_Query("tag=righttab&showposts=10"); while($recent->have_posts()) : $recent->the_post();?>

    " target="_blank"><?php the_title(); ?>
    <?php endwhile; ?>

    but only it gives me the page category articles not other categories?

  6. lexthoonen
    Member
    Posted 6 years ago #

    Ok, I’m new to the tag business: but here’s my question: If I add certain tags to a post, I’d like to see underneath my post, say the last 5 posts of which the tags match as much as possible, with the best match on top. Is something like that possible and if so, how? Thanks!

  7. dylan
    Member
    Posted 6 years ago #

    Kafkaesqui, your code was useful to me.

    I was trying to get a list of posts to show up within a wordpress page. Those posts all had a tag in common. So I combined the runPHP plugin with your code, and it worked like a charm!

Topic Closed

This topic has been closed to new replies.

About this Topic