WordPress.org

Forums

[resolved] My second loop doesn't work (22 posts)

  1. ganzua
    Member
    Posted 9 years ago #

    Hi there!

    I created a template for a page (wp static page) with two loops. The first loop will show the last post of the blog. The second loop will show the content of the page.

    The first loop code goes like this;

    <?php query_posts('posts_per_page=1'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    <div...

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

    --> so far so good, it works! but then I insert the second loop and it doesn't work. I must be missing anything;

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <h2><?php the_title(); ?></h2>
    <div class="entrytext">
    <?php the_content('<p class="serif">read »'); ?>

    <?php link_pages('Paginas: ', '', 'number'); ?>

    </div>
    </div>
    <?php endwhile; endif; ?>
    <?php edit_post_link('Edit.', '', ''); ?>

    --> What I'm doing wrong? I have read I need to re-set the second loop but not sure how to do it?

    Please, help!

  2. ganzua
    Member
    Posted 9 years ago #

    up!

  3. MichaelH
    Member
    Posted 9 years ago #

    Might consider the rewind_posts()

    See this for other possible solutions:
    The_Loop#Multiple_Loops

  4. ganzua
    Member
    Posted 9 years ago #

    Hi MichaelH;

    Thank you for answering.

    I tried before, but rewind_posts() recovers the first post of the blog again and I want the content of the wp static page.

    I have to set the second loop so it recovers the content of that particular id page.

  5. TechGnome
    Moderator
    Posted 9 years ago #

    Take a look at Loop Example 1......
    The part that maybe of the most use starts off with "If you need to keep the original query around, you can create a new query object."

    -tg

  6. ganzua
    Member
    Posted 9 years ago #

    Hi TechGnome;

    I tried this one;

    <?php $my_query = new WP_Query(); ?>

    but it didn't work. I need to query a page and I don't know which is the call;

    First loop -> calls first post in the blog (working)

    Second loop-> calls content of page_id=5 (not working)

  7. ganzua
    Member
    Posted 9 years ago #

    up

  8. MichaelH
    Member
    Posted 9 years ago #

    Will add this for your consideration:

    Template_Tags/query_posts#Retrieve_a_Particular_Page

  9. moshu
    Member
    Posted 9 years ago #

    Instead of the second loop you could use thsi plugin:
    http://guff.szub.net/2005/01/27/get-a-post/
    (if it is for only one particular Page/post)

  10. ganzua
    Member
    Posted 9 years ago #

    Thanks MichaelH and moshu again;

    This one;

    <?php
    query_posts('page_id=7');
    ?>

    worked in my computer ... but not in the host on the internet, odd thing.

  11. ganzua
    Member
    Posted 9 years ago #

    I checked the page id

  12. ganzua
    Member
    Posted 9 years ago #

    Do I miss anything in this code?

    <?php
    query_posts('page_id=7');
    ?>

    Now it is not working

  13. ganzua
    Member
    Posted 9 years ago #

    get-a-post didn't work either

  14. nearlythere
    Member
    Posted 9 years ago #

    ganzua, i'm trying help expand the codex page for query_posts; this would be a good thing to add if you figure out a solution. (you can edit the codex too, if you like).

    but i can't read your code, so i can't figure out how to help. do you know how to insert code into your posts? you need to use 'backticks' around each line. (see the message under the "send post" button below)...

    at any rate, the thing you're searching for is referred to as "multiple loops", this may help in your searching.

    I don't really understand the inner workings of the issue, but I keep coming across it, there are recommendations to "Try resetting the query to the default after using your custom queries."

    I saw this on the codex:

    <?php $temp_query = $wp_query; ?>

    <?php query_posts('category_name=special_cat&showposts=10'); ?>

    <?php while (have_posts()) : the_post(); ?>
    <!-- Do special_cat stuff... -->
    <?php endwhile; ?>

    <?php $wp_query = $temp_query; ?>

    try that for each of your query loops, and tell us how it comes along!

  15. ganzua
    Member
    Posted 9 years ago #

    Hey nearlythere! Thanks for your response.

    I was trying to solve this issue before uploading my site. I just can't find out a solution.

    You can read my code now here; http://90plan.ovh.net/~covenmys/wordpress/?page_id=3

    (web is in spanish since I live in Spain, sorry)

    If you go through the code you'll find some text dummie there which is the page content, but it doesn't appear in the browser.

    Besides, on bottom of the page there is an iclude fetching last phpbb posts and links are missreaded, I think by the server's fault because in my own Apache installation they work fine.

    It might be an .htaccess of the server causing all this problems, I don't know.

  16. clarke1866
    Member
    Posted 9 years ago #

    Your code is not viewable on that page. Copy the php code to a text file, and post a link to that. Thats what I would do.

  17. ganzua
    Member
    Posted 9 years ago #

    Ok, here is the header; (hope it works);

    http://90plan.ovh.net/~covenmys/header.txt

    By the way, I just realized that the site is not compatible with firefox at all, it seems firefox is not loading wordpress sidebar.

  18. nearlythere
    Member
    Posted 9 years ago #

    i quickly scanned that file, and noted that you have two comments in your file, but one is not closed. look for the comment which does not close:

    <!-- Index inicio
    Page template

    you need to close this with:
    -->

    i also noted that on your page i see a stray end of comment line here:

    Archivos
    * Octubre 2005
    -->

    i'm not entirely sure if this will solve your problem, but can you fix that comment by closing it --> and run the code and come back to tell us how it came along?

  19. ganzua
    Member
    Posted 9 years ago #

    Thanks nearlythere, it is very kind of you.

    In the header I commented the second loop because it wasn't working and I wanted to try the query_posts('page_id=3')tag.

    The second one; * Octubre 2005 comes from the sidebar. I commented this one to stop showing archives in the sidebar.

    I checked them with my php editor and I think the commented lines are ok, all of them appear in grey.

  20. nearlythere
    Member
    Posted 9 years ago #

    sorry, ganzua i don't understand then. you said your "second loop doesn't work"

    still looks to me like an open HTML comment!

    this is what i see: i see two loops, preceded by two queries:

    first:
    <?php query_posts('posts_per_page=1'); ?>

    second:
    <?php
    query_posts('page_id=3');
    ?>

    and the second one is 'hidden' inside an unclosed HTML comment tag. and if i look at the HTML source, the code was still 'run' but it isn't appearing, because it is hidden in HTMl comment.

    <!-- Index inicio
    Page template

    <div class="post" id="post-3">
    <h2>Inicio</h2>
    <div class="entrytext">
    Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
    Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.


    </div>
    </div>

    <!-- Index inicio
    Page template -->

    so after the first:

    <!-- Index inicio
    Page template

    you need to close the comment. and it should look like this:
    <!-- Index inicio
    Page template -->

    i don't mind where you do it, but you have to close it somewhere. that's about as clear as i can make it.

    if this isn't the solution to your problem, sorry i can't help further!

  21. ganzua
    Member
    Posted 9 years ago #

    Hey nearlythere!

    I'm back. I got it working now! You were right; query_posts('page_id=3') plus the second loop worked. I had it commented because I thought all what I needed was the query_posts('page_id=3') with no loop behind.

    Thank you very much for your help and good luck with your japanese.

    会���� ?

  22. nearlythere
    Member
    Posted 9 years ago #

    *phew* i'm glad that worked out!

    日本語ã?Œã?§ã??ã?¾ã?™ã?‹ï¼Ÿ
    not that i can! but i'm trying :)

Topic Closed

This topic has been closed to new replies.

About this Topic