See the Codex on The Loop, especially the section ‘Multiple Loops in Action’.
Thanks for the link to the right section of the codex…
As I’m not much of a coder, I took the snippet and changed the category name using the slug to grab a post from a specific category.
I must have it in the wrong place because I either end up with the post and not the content of the “page” or the content of the page and not the post entry…
Do you have two Loops now? Can you post the section of code involved and a link to your site?
OK… Here’s the relevant snippet… I’m working with a template file, not the main page.php, if that’s relevant I’m not sure…
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<table width="100%" cellpadding="5" cellspacing="0" border="1">
<tr>
<td>static content on the page</td></tr></table>
<div class="entry">
<?php the_content('Read the rest of this entry »'); ?>
</div>
</div>
<?php endwhile; ?>
The snippet from the codex isn’t here, but if I put it in after the endwhile it doesn’t pull the post, if I put it above, the post pulls in but not the static content I typed in on the edit/create page.
Seems like I didn’t use query’s before, it was just a one line snippet that looked for x number of posts from a category… all this query stuff is beyond my comprehension… if it matters, I’m using php5.
This is TOTALLY UNTESTED, but it should be close. Put this part just ahead of the code you posted above. It is the first loop (while loop), your code above is the second loop.
<?php $my_query = new WP_Query('category_name=featured&posts_per_page=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>
<div class="post" id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<table width="100%" cellpadding="5" cellspacing="0" border="1">
<tr>
<td>static content on the page</td></tr></table>
<div class="entry">
<?php the_content('Read the rest of this entry »'); ?>
</div>
</div>
<?php endwhile; ?>
Then put this line just after the line containing ‘while (have_posts())’ in your code:
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
Thanks so much for all your help, I sincerely appreciate it.
J
If that fixed the problem, please mark this topic Resolved.