• Resolved xdesi

    (@xdesi)


    Hi i have been reading the article https://codex.www.ads-software.com/Template_Tags/query_posts and i have two questions i need help with:

    1. How do i combine a category with a tag. For instance i want to show all posts from cat 3 with the tag cooking. I really did try but can’t get it to work.

    2. Secondly is it possible to have multiple loops, well i mean to say have a box to first display all posts from cat 3 with a certain tag in a box, then underneath display all posts from cat 4 with a certain tag in a different box. Is this possible?

    Many Thanks in advance i really hope both questions can be answered.

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

    (@simonj)

    Dear xdesi

    If you had search this forum for “query_posts category tag”

    You should had find this wonderful thread

    https://www.ads-software.com/support/topic/152904?replies=26

    Where we found that there is a bug in WP when you query Cat and Tag…

    There is a workaround in this thread…

    For your second question, yes, it’s totally possible. Juste make multiple loops with the workaround you will find in the thread I just linked here…

    S.

    Thread Starter xdesi

    (@xdesi)

    Many Thanks for the link you provided it was just what i was looking for.
    Now i just need a bit of help with part 2 of my question. You see i was wondering whether it was possible to do multiple loops inside a post (single.php), display whatever i wish from the post and also have comments at the bottom as usual.
    I can’t find where to put the:

    <?php rewind_posts(); ?>
     <?php my query?>
      <?php while (have_posts()) : the_post(); ?>
    My Content to show
      <?php endwhile; ?>

    inside the single.php, as this has different layout. (default kubrick single.php i am talking about btw.)

    Again many thanks for such a quick and effective response i really appreicate it!!!

    Thread Starter xdesi

    (@xdesi)

    Sorry for the bump but here is where I am currently at:

    <?php rewind_posts(); ?>
    <?php My Query?>
    <?php while (have_posts()) : the_post(); ?>
    Display whatever
    <?php endwhile; ?>
    <?php rewind_posts(); ?>
    <?php My Query 2?>
    <?php while (have_posts()) : the_post(); ?>
    Display whatever
    <?php endwhile; ?>

    I can repeat this and put it in my single.php, but it seems to mess up my footer, and also no comment box is displayed at the bottom?

    SimonJ

    (@simonj)

    I dont understand what you are tryng to do…

    Do you want ? :

    – The post you are reading (single.php) –

    – The comments for this post –

    – Some other loops to display other posts –

    S.

    Thread Starter xdesi

    (@xdesi)

    OK basically on my site i have like 3 sections: videos, pictures, bio.

    When i write a post about a person in the BIO section, underneath the content but before the comments i want to display the thumnbail of posts about this person from the other two sections (videos and images).
    So the layout of single.php fot the bio secton will be:

    —THE MAIN CONTENT OF THE BIO DESCRIPTION OF THE PERSON—

    —THEN I USE QUERY TO RETREIEVE THUMBNAILS AND TITLES OF VIDEOS RELATING TO THIS PERSON—

    —THEN I USE QUERY TO RETREIEVE THUMBNAILS OF IMAGES AND TITLES RELATING TO THIS PERSON—

    —THEN I WANT COMMENTS FORM FOR THE BIO—

    I try to put my queries in before the comments section on single.php and it displays the thumbnails as expected but then the comments form does not display and also my footer seems to mess up?

    SimonJ

    (@simonj)

    Ok…

    Try this :

    FIRST LOOP :

    <?php while (have_posts()) : the_post(); ?>
    --- YOUR STUFF FOR THE SINGLE POST ---
    <?php endwhile; ?>

    SECOND LOOP WITH QUERY_POSTS :
    — YOUR STUFF FOR THIS LOOP —
    <?php endwhile; ?>

    THIRD LOOP WITH QUERY_POSTS :
    — YOUR STUFF FOR THIS LOOP —
    <?php endwhile; ?>

    LAST LOOP WITH QUERY_POSTS :
    — YOUR STUFF FOR THIS LOOP —

    <?php endwhile; ?>
    <?php wp_reset_query(); ?>

    THEN JUST RELOOP AN EMPTY LOOP TO RETREIVE THE COMMENTS:

    <?php while (have_posts()) : the_post(); ?>
    <?php endwhile; ?>
    <?php comments_template(); ?>

    NOTE THE : <?php wp_reset_query(); ?> in the last loop with query_posts.

    What we are doing here, is just put a “fake” last loop to retreive the comment template for the post we are reading in single.php…

    For the mess in the footer, you probably miss a div somewhere…

    S.

    Thread Starter xdesi

    (@xdesi)

    Thankyou very much this has worked a charm the comments box now appears and footer was missing a div as you suggested.

    I can only thankyou for your help at this time Simon if i ever get rich i will be sure to donate in the future!

    Many Thanks.

    SimonJ

    (@simonj)

    ??

    Glad it works…!

    It’s a good example here that you have to understand how WP does think… Then, you can ask him anything… You just have to know how. ??

    S.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Query Posts Combination and Repeat Help’ is closed to new replies.