gero_007
Member
Posted 1 year ago #
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 :)
$same_cat_posts is an array.
gero_007
Member
Posted 1 year ago #
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!
gero_007
Member
Posted 1 year ago #
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>'