Query recent posts
-
Hey guys so currently on my homepage I have it setup so it first shows the most recent 10 posts (of all categories) and then that’s followed by the most recent 10 posts of each individual category.
But I want to add one more thing and cant figure out how to do it. I want to first show the 1 most recent post from only specific categories and then followed by the rest as it already is. Am I asking too much lol Here’s the code (Thank you guys so much in advance!):
<?php
$args = array(
'posts_per_page' => 10,
);
$customQuery = new WP_Query( $args );
if ( $customQuery->have_posts()) {
echo '<div class="all-cats">';
while ( $customQuery->have_posts()) : $customQuery->the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div id="humbnail">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</div>
<?php the_content('Read More »'); ?>
<?php
endwhile;
echo ' </div>
</div>
<div id="posts_clear">
<div id="posts_over"><!-- .all-cats -->';
} //endif
$allcats = get_categories('child_of='.get_query_var('cat'));
foreach ($allcats as $cat) :
$args = array(
'posts_per_page' => 10, // max number of post per category
'category__in' => array($cat->term_id)
);
$customInCatQuery = new WP_Query($args);
if ($customInCatQuery->have_posts()) :
echo '<div>';
echo '<div id="posts-header-container"><h1><span>Recently from '.$cat->name.'</span></h1></div>';
echo '';
while ($customInCatQuery->have_posts()) : $customInCatQuery->the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div id="humbnail">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</div>
<?php the_content('Read More »'); ?>
<?php
endwhile;
echo '</div>';
?>
<?php else :
echo 'No post published in:'.$cat->name;
endif;
wp_reset_query();
endforeach;
?>The page I need help with: [log in to see the link]
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Query recent posts’ is closed to new replies.