• Resolved gero_007

    (@gero_007)


    Hi there everyone. I am new at wordpress and hope anyone can help…
    I have one category (catID=12) with 10 posts in it. What I want to do is to print the 5 recent posts in the same page (let’s say in my homepage), but in different positions of the page. What i am doing is:

    $category_number = '12';
    $same_cat_posts = get_posts("numberposts=5&category={$category_number}");

    This will print the 5 posts I need, but all of them in the same part of the website – my question: Is there anyway that helps me get, for example “Post one”, “post two” etc. as different variables and after that print the post where I want? (maybe any kind of array or so on?)
    Thanx a lot in advance 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • $same_cat_posts is an array.

    Thread Starter gero_007

    (@gero_007)

    Thanks for your reply Peter_L, i know it’s an array and I can print it’s values by the following code:

    <?php foreach($same_cat_posts as $post) :?>
    <a href="#"><a href="<?php the_permalink(); ?>">
    <?php the_title(); ?> </a>
    <?php endforeach; ?>

    But, how can i print the_content(); in this case? Any idea? It doesn’t print anything when I try it…??It prints the the_permalink() and the_title() but there is NO OUTPUT for the_content() or the_excerpt()…
    Thanx again!

    http://codex.wordpress.org/Template_Tags/get_posts
    http://codex.wordpress.org/Template_Tags/get_posts#Examples

    try and add setup_postdata($post); to your code; then you should be able to use the_content(); etc.

    Thread Starter gero_007

    (@gero_007)

    thank you alchymyth, thanx a lot! This is how it’s working now…

    $args = array( 'numberposts' => 1, 'order'=> 'ASC', 'orderby' => 'title', 'category' => 12 );
    $postslist = get_posts( $args );
    foreach ($postslist as $post) :  setup_postdata($post); ?>
    <a href="<?php the_permalink(); ?>">
    <?php the_title(); ?> </a>
    <?php the_excerpt(); ?>
    <?php echo "Posted on: " ;
    the_date(); ?></p>'
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Need to display specific posts from one category’ is closed to new replies.