Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
WP_Query() in Wordpress
Old 09-24-2009, 06:32 PM WP_Query() in Wordpress
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
I'm using a WP_Query object to create two loops. The goal is to have a full post on the first page, with 3 excerpts following it.
The rest of the pages are then to display only excerpts. The first page works fine, but then each page that follows displays only the excerpts that were on the first page!
If anyone could tell me where I'm going wrong that'd be great.
Here are the loops I'm using:
PHP Code:
<?php
        
if ($paged == 0) :
            
$posts = new WP_Query();
            
$posts->query('showposts=1&cat=-10&orderby=date');
        
?>

        <?php if($posts->have_posts()) : ?><?php while($posts->have_posts()) : $posts->the_post(); ?>
                    <div class="entry">
                        <div id="h1-wrapper">
                          <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <span class="date"><?php the_date(); ?></span></h1>
                        </div>
                        <div class="detail">Filed under <?php the_category(', '); ?>, posted by <a href="#">Matt</a></div>
                        <div class="content">
                            <?php the_content(); ?>
                        </div>
                    </div>
        <?php endwhile; ?>
        <?php endif; ?>   

        <?php endif; ?>   

        <?php
            $posts 
= new WP_Query();
            
$posts->query('cat=-10&offset=1&orderby=date');
        
?>

        <?php if($posts->have_posts()) : ?><?php while($posts->have_posts()) : $posts->the_post(); ?>
                    <div class="entry">
                        <div id="h2-wrapper">
                          <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <span class="date"><?php the_date(); ?></span></h2>
                        </div>
                        <div class="detail">Filed under <?php the_category(', '); ?>, posted by <a href="#">Matt</a></div>
                        <div class="content">
                            <?php the_excerpt(); ?>
                        </div>
                    </div>
        <?php endwhile; ?>
        <?php endif; ?>        

        <div id="post-nav">
          <?php posts_nav_link('&nbsp;''Previous''Next'); ?>
        </div>
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is online now
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 09-24-2009, 10:09 PM Re: WP_Query() in Wordpress
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Check the page on The Loop at the WordPress Codex. About midway down the page it talks about multiple loops.

I think all you need to do is use different variable names each time you call WP_Query() instead of setting both to $posts. If not try calling rewind_posts(); before calling the second loop

Also don't hold me to this, but I think if you let the first loop run without calling WP_Query() and then do what you're doing in the second post it will work.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 09-24-2009, 10:48 PM Re: WP_Query() in Wordpress
racer x's Avatar
Ultra Talker

Posts: 457
Name: Randy
Location: Northern Wisconsin
Trades: 0
Your paging is not working properly because you have <?php posts_nav_link('&nbsp;', 'Previous', 'Next'); ?> after the last <?php endif; ?>. Everything you want to do with a loop must be done within the loop.

Try this:
<?php endwhile; ?>
<div id="post-nav">
<?php posts_nav_link('&nbsp;', 'Previous', 'Next'); ?>
</div>
<?php endif; ?>
racer x is offline
Reply With Quote
View Public Profile Visit racer x's homepage!
 
Reply     « Reply to WP_Query() in Wordpress
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.70513 seconds with 12 queries