Support » Themes and Templates » Insert current Tag into a query_posts

  • Resolved theApe

    (@theape)


    I’m using query_post with multiply loops to create a very irregular layout for a theme I’m working on.

    Does anyone have any pointers on how I can insert the current Tag as stated by the URL into a query_post?

    I’ve been doing what I want with the Categories and Dates, but hit a brick wall when it came to the Tags. Here’s an example of what I’m using for Categories.

    <?php  if( is_category() ) {
    foreach((get_the_category()) as $category) { }
    query_posts('showposts=1&category_name=' . $category->category_nicename . '');
    } ?>

    Any help with code that does something similar for Tags would be appreciated.

Viewing 8 replies - 1 through 8 (of 8 total)
  • theApe

    (@theape)

    I’m doing this before and outside of the loop, by the way.

    MichaelH

    (@michaelh)

    theApe

    (@theape)

    Thank you Michael!

    I had the is_tag() and the tag=, but, I’ve no idea on how to use the get_terms with them and I’m not sure if I need an array as I only want to call the one tag at a time. I was also looking at single_tag_title, but my problem is how I pull the output into the parameters of the query_posts.

    Am I on the right track with the code below.

    <?php  if( is_tag() ) {
    $tags = get_terms('post_tag');
    query_posts('showposts=1&tag=' . $tags . '');
    } ?>
    MichaelH

    (@michaelh)

    Not sure why you would need to query for a specific tag if you are dealing with a tag archive.

    Related:
    Tag Templates

    MichaelH

    (@michaelh)

    Just for reference, this returns the current queried tag.

    <?php
    if (is_tag( )) {
      $tag = get_query_var('tag');
    }
    ?>
    theApe

    (@theape)

    Every fifth post in the theme archive has a unique style. So I have a loop which calls the first post, then another loop which calls the next four using offset, then another one, then another four and so on. Each loop is called by including a single php file with its own unique query_post above it to control the output.

    Thank you for all your help so far, but I’m still getting stuck on how to insert the current tag into the query_post parameters.

    If this calls the current queried tag…

    <?php
    if (is_tag( )) {
      $tag = get_query_var('tag');
    }
    ?>

    how do I make the current tag replace ‘Something’ in the query?
    query_posts('showposts=1&tag=Something');

    MichaelH

    (@michaelh)

    <?php
    if (is_tag( )) {
      $tag = get_query_var('tag');
    query_posts('showposts=1&tag='.$tag);
    }
    ?>

    Also
    http://www.google.com/search?q=wordpress+styling+each+post+differently

    theApe

    (@theape)

    Thank you! Thank you! Thank you!

    You’re a genius!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Insert current Tag into a query_posts’ is closed to new replies.