Reputation: 69
I need your help.. i've two categories in wordpress to display post 1. News 2. Projects
now i want to display last 3 post from both category like below..
post1. post2. post3. post1. post2. post3.
Thank you guys..
Upvotes: 1
Views: 2515
Reputation: 69
Thank you guys for helping me... I found solution which is working.. Thanks a lot for support..
$args1 = array( 'posts_per_page' => 3, 'offset'=> 0, 'category' => 3,'post_type'=> 'post','post_status'=>'publish','orderby'=> 'post_date','order'=> 'DESC','suppress_filters' => true);?>
Upvotes: 1
Reputation: 115
<?php
$categoryids = array(add news category id,add projects category id);
$args = array(
'numberposts' => 3,
'category__in' => $categoryids,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'give the name of post types',
'post_status' => 'publish' );
$posts_array = get_posts( $args );
foreach ($posts_array as $posts) {
....................
}
?>
Upvotes: 0
Reputation: 8809
you can try something like below code it will fetch 3 post from each category
<?php
wp_reset_query();
$cats = get_categories('');
foreach ($cats as $cat) :
if($cat->category_parent) continue;
$args = array(
'posts_per_page' => 3,
'category_name' => $cat->slug,);
query_posts($args);
if (have_posts()) :
echo '<h2>Latest Posts in '.$cat->name.' Category</h2>';
?>
<?php while (have_posts()) : the_post(); ?>
<div>
<h2>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
</div>
<?php
if ( is_category($vidcat) ) { the_content(); }
else { echo strip_tags(get_the_excerpt(), '<a><strong>'); }
?>
<!-- this area is for the display of your posts the way you want it -->
<!-- i.e. title, exerpt(), etc. -->
<?php endwhile; ?>
<?php else : echo '<h2>No Posts for '.$cat->name.' Category</h2>';?>
<?php endif; wp_reset_query; ?>
<?php endforeach; ?>
if you want to fetch exclude any category than pass the argument like this.
$args = array(
'exclude' => '' //pass category id which your don't want to include.
)
$cats = get_categories($args);
Upvotes: 1