Page 1 of 1

get_posts from loop in Wordpress

Posted: Tue Jan 11, 2011 2:55 pm
by aghast
I need code that will grab 2 specific categories from my loop and post in on a static page or a page template. I have looked through all the documentation on wordpress involving loops and get_posts as well as query_posts and in there forum and other help sites but I can't get anything working for me. Has anyone done this before?

I need a home page that shows two categories.

Featured artist and Gigs

there will be a separate page called Blog which is where the normal loop with all the categories will be.

cheers,

-ag

Re: get_posts from loop in Wordpress

Posted: Wed Jan 12, 2011 9:15 am
by aghast
This is actually something that works very well when I put it in the static page as content, it would show 1 category and 5 permalinks. But I think it's meant to function with the blog loop not on a static page and I can't get it to show 2 categories. There must be a better way.

Code: Select all

<ul>
<?php
global $post;
$args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :    setup_postdata($post); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>