I want to show 5 random posts from 2 categories (ID no. 4 & 7)
for this I use this code :
$rand_posts = get_posts('numberposts=5&orderby=rand&cat=4,7');
It worked ofcourse.
Now I want to give 10 specific ID's of posts instead of those two above mentioned categories.
How can it be possible?
this might work:
<?php $post_list = array( 1,1029,188,185,171,170,233,167,169,168);
shuffle($post_list);
$rand_list = array_slice($post_list, 0, 5);
$rand_posts = get_posts(array( 'include' => $rand_list, 'orderby' => 'rand' ));
It works like charm !!
Thanks a lot.
one more question please:
how can I get the author name (Display name) [with hyperlink] of the specific random post?
I used this:
<?php get_the_author_link(); ?>
but it didnt work.
I have used both of these :
<?php the_author_link(); ?>
<?php echo get_the_author_link(); ?>
but ...... not working !!
The Author's display name doesn't show.
is anything showing?
is the code used in the loop?
as you are working with 'get_posts()', have you used 'setup_postdata()' in your code?
http://codex.wordpress.org/Template_Tags/get_posts
you could paste the full code of your template into a http://wordpress.pastebin.com/ and post the link to it here.
can you post a link to your site to illustrate the iisue?
The code is for showing "Featured posts" from current month.
I have pasted this code here at pastebin :
Random posts with Title/Date/Author/Category links
after this line:
foreach( $rand_posts as $post ) :
insert:
setup_postdata($post);
if you read the 'get_posts()' link to the codex docu it is all shown in there.
Thanks !
I have inserted that code as you advise & it works.
But the Author name is without hyperlink. any suggestion?
sorry to disturb you.
http://codex.wordpress.org/Function_Reference/the_author_link
the_author_link() would link to the authors website -
maybe none is entered, then there is no link.
or where do you expect the link to link to?
if you want the author's name to link to his/her posts, try to use:
http://codex.wordpress.org/Function_Reference/the_author_posts_link
You really deserves an award for your nice helping nature. :)
yeah, i mean the same, i.e.: author's name to link to his/her posts
which i got from :
<?php the_author_posts_link(); ?>