I assume you mean “recent” posts… Also, by page_id you mean a Page (Write > Write Page) in WordPress.
The following uses the WP_Query() class (it accepts the same arguments as query_posts()) that will display the titles for the last 3 posts in category 3. It’s more beneficial than using query_posts() as it will not whack the default $posts object on a page:
<?php
$recent = new WP_Query('cat=3&showposts=3');
while ( $recent->have_posts() ) : $recent->the_post();
?>
<div class="post2" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
</div>
<?php endwhile; ?>
Works the same for calling up a Page:
<?php
$mypage = new WP_Query('page_id=10');
while ( $mypage->have_posts() ) : $mypage->the_post();
?>
<div class="page" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
</div>
<?php endwhile; ?>
I tryed the code above and I get this
Parse error: syntax error, unexpected T_WHILE in
???
Sorry, little coding slip on my part. The statements above have been corrected.
Well it works but I get this msg also
Fatal error: Call to a member function on a non-object in /home.php on line 20
This is what I have…I am not sure if this is the correct way to code this.
<?php get_header();?>
<div id=”main”>
<div id=”content”>
Latest News – see all
<?php
$recent = new WP_Query(‘cat=3&showposts=3’);
while ( $recent->have_posts() ) : $recent->the_post();
?>
<div class=”post2″ id=”post-<?php the_ID(); ?>”>
</div>
<?php endwhile; ?>
<?php
$page = new WP_Query(‘page_id=5’);
//this is the line where it said the error is\\ while ( $page->have_posts() ) : $page->the_post();
?>
<div class=”page” id=”post-<?php the_ID(); ?>”>
<h2><?php the_title(); ?></h2>
</div>
<?php endwhile; ?>
</div>
<?php get_sidebar();?>
<?php get_footer();?>
Would this be loop problem?
The first loop works fine but the second loop has an error but it does show the page.
Can you run a second loop on the same page (static home.php)
When I try I get an error like:
error msg:Call to a member function on a non-object in /home.php line 21
line21( on the second loop): while ( $page->have_posts() ) : $page->the_post();
?>
Is there something I need to do to support two loops on the same page.
Hmm. My suggested var name ($page) is conflicting with something in WordPress. So change the Page query code to:
<?php
$mypage = new WP_Query('page_id=1008');
while ( $mypage->have_posts() ) : $mypage->the_post();
?>
That appears to have no problems. (Lesson for the day: Make everything unique…)
Thanks alot that worked great.
There is the code for displaying recent posts and displaying a specific “page” on a static home page
<?php get_header();?>
<div id=”main”>
<div id=”content”>
Latest News – see all
<?php rewind_posts(); ?>
<?php
$recent = new WP_Query(‘cat=3&showposts=3’);
while ( $recent->have_posts() ) : $recent->the_post();
?>
<div class=”post2″ id=”post-<?php the_ID(); ?>”>
- ” rel=”bookmark”><?php the_title(); ?> | Posted: <?php the_time(‘F j, Y’); ?>
</div>
<?php endwhile; ?>
<?php
$mypage = new WP_Query(‘page_id=5’);
while ( $mypage->have_posts() ) : $mypage->the_post();
?>
<div class=”page” id=”post-<?php the_ID(); ?>”>
<h2><?php the_title(); ?></h2>
<div class=”entry”>
<?php the_content(__(‘Continue Reading »’)); ?></div>
</div>
<?php endwhile; ?>
</div>
<?php get_sidebar();?>
<?php get_footer();?>
thanks again