lookupandy
Member
Posted 2 years ago #
Hey,
I'm still getting my head around WordPress, but have a question about how posts are displayed:
What I am trying to achieve is a webpage that shows 4 posts- the first post from category 6 AND 12, and the remaining 3 posts only from category 6 shown below it.
I've searched many websites and doc files, but can't seem to find something that works.
Any help would be much appreciated!
Cheers,
Andy
Didn't test this but...would need two loops:
<?php
$post_ids=array();
$args=array(
'category__and' => array(6,12),
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'List of one Post in cat 6 and 12';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
$post_ids[]=$my_query->post->ID;
the_content();
endwhile;
}
$args=array(
'post__not_in' => $post_ids,
'cat' => 6,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 3,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'List of 3 Posts in cat 6';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
$post_ids[]=$my_query->post->ID;
the_content();
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
lookupandy
Member
Posted 2 years ago #
Hi Michael,
Thanks, that looks great. I'll give it a try.
So, I'm guessing it's not possible to do it in a single loop?