Still cant seem to find the right information, any ideas?
<?php
//get 3 posts from category 5 or 7, display title
$args=array(
'showposts' => 3,
'category__in' => array(5,7),
'caller_get_posts'=>1
);
$posts=get_posts($args);
if ($posts) {
foreach($posts as $post) {
setup_postdata($post); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
} // foreach($posts
} // if ($posts
?>
Related:
Stepping Into Template Tags
Stepping Into Templates
Template Hierarchy
query_posts()
get_posts()
Thanks for that, however i couldn’t get it to work even with modifying the array. I actually couldnt get a post to display with that at all.
I did get one display by
<?php
//get 3 posts from category 5 or 7, display title
$args=array(
'showposts' => 1,
'category__in' => array(1,2),
'caller_get_posts'=>1
);
$lastposts = get_posts('numberposts=1');
foreach($lastposts as $post) :
setup_postdata($post);
?>
<h2><a>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endforeach; ?>
However im pretty sure category code isnt doing anything. Is there a way i can literally define which category? Like ‘Events’ or ‘News’
Ok I found the code I was looking for query_posts('category_name=Events');
I’m just not sure where to input within
<?php
$lastposts = get_posts('numberposts=1');
foreach($lastposts as $post) :
setup_postdata($post);
?>
<h2><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endforeach; ?>
still cant figure it out :/
Okay what are the category IDs of the categories you want posts from?
How many posts do you want from those categories?
If you don’t know the category IDs install this plugin:
http://ww.wp.xz.cn/extend/plugins/reveal-ids-for-wp-admin-25/
Cool, thanks for the plugin! The ID i need to specify is 16…all of the other categories are lumped into 1
$args=array(
'category__in' => array(16),
'showposts' => 1,
'caller_get_posts'=>1
);
$lastposts = get_posts($args);
Brilliant. Worked great. I even got this to work..
<?php
$args=array(
'category__not_in' => array(16),
'showposts' => 1,
'caller_get_posts'=>1
);
$lastposts = get_posts($args);
foreach($lastposts as $post) :
setup_postdata($post);
?>