0

I don't consider myself to be a newb, I've had a loop of all the pages work before, but right now one of my custom loops on my page template (which is used as the index page of the site), will not show a list of 'pages'.

<?php get_header(); ?>

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> // first I want to call the information for the page itself -- i've tried removing this and it has no effect.
<div class="about"><?php the_content(); ?></div>


<?php endwhile; 
wp_reset_query(); 

// end frontpage while ?>

    <div id="featured" >  
        <ul class="ui-tabs-nav">  
            <li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-1"><a href="#fragment-1"><span>About the film festival</span></a></li>  


        <?php    
        $get_pages =    ( //the loop to get all the pages on the site
                array(

                    'post_type' => 'page',
                    'posts_per_page' => -1,

                ));
                query_posts( $get_pages );

        if ( have_posts() ) while ( have_posts() ) : the_post(); 
?> 

// this here is what I want to happen for each page, but it shows up for anything aside from page

 <li class="ui-tabs-nav-item" id="nav-fragment-2"><a href="#fragment-2"><span><?php the_title() ?></span></a></li>  

    <?php endwhile; //end pages while
                wp_reset_query(); 
                wp_reset_postdata();     ?>

Am I missing something crucial? Is there a stupid mistake? I am clueless at the moment. Tanks for anything that might help here.

2 Answers 2

1

This is not the place to use query_posts. query_posts should only be used if you need to change the main loop. There is also no need to reset the query and your missing endif on both loops.

I would use get_pages instead of running a new WP_Query.

$pages = get_pages();
foreach ( $pages as $page ) { ?>

<li class="ui-tabs-nav-item" id="nav-fragment-2"><a href="#fragment-2"><span><?php echo $page->post_title; ?></span></a></li> 

    <?php }
1
  • grand. thanks for that! i didn't realise there was a specific difference between the two methods of querying there. Anywho. This worked like a charm and I've tidied up all my other queries accordingly. Tanks.
    – josh
    Apr 18, 2012 at 13:37
0

Nothing is jumping out at me as being outright wrong (though you have some spotty use of brackets in a few places), but it's not good practice to use query_posts() like this (twice in a page, with wp_reset_query()), and it's possible that some sort of related global conflict is causing your issue. Try using WP_Query instead:

$page_args = array(
    'post_type' => 'page',
    'posts_per_page' => -1,
));
$page_query = new WP_Query( $page_args );

if ( $page_query->have_posts() ) :
    while ( $page_query->have_posts() ) :
        the_post();
        ?>
         <li class="ui-tabs-nav-item" id="nav-fragment-2"><a href="#fragment-2"><span><?php the_title() ?></span></a></li>
        <?php
    endwhile;
endif;
1
  • I tried switching here and got the following error: 'Notice: Undefined offset: 1 in /Users/joshuef/Development/onfilm/wp-includes/query.php on line 2772 '
    – josh
    Apr 18, 2012 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.