Support » Fixing WordPress » how-to: list of post titles, matching certain tag – in sidebar?

  • Resolved trehug

    (@trehug)


    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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; ?>
    Thread Starter trehug

    (@trehug)

    thanks a lot!!

    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.

    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?

    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!

    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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘how-to: list of post titles, matching certain tag – in sidebar?’ is closed to new replies.