I would like to make my home page in such a way it shows the most viewed, random and recent posts by thre differents part by limitin the number of posts......give me at least some hints or idea to try it. Thank you in advance
2 Answers
I've implemented this before with custom queries and widgets. You have to be tracking all of these stats, of course, but if you are, it's a rather simple matter to build a widget that displays it and drop it in. If you're not using widgets, you can do the same, it will just take a bit more coding on your part, but use the same concept. Without specifics, I don't think I can go much deeper on implementation for most viewed, but I can give you the other two.
To get random posts, you can just do a get_posts()
query with your orderby
set to rand
and everything else set as normal, voilà , random posts.
Same deal for most recent posts, get_posts()
, set your order_by
to post_date
and your order to DESC
...which is actually the default behavior for get_posts()
.
Docs: get_posts()
-
thank yu. I tried the code from yur link but the out put is post titles and its perma link. What should i do to get the thumbnail of the post?. If yu tell me how to get the post, i could get the thumbnail preview of those posts.– FelixJan 17, 2012 at 10:56
-
My link was a codex page...there were lots of code examples and they all centered solely on getting the post. I really don't understand what you're asking.– mor7iferJan 17, 2012 at 11:42
-
I should admit that i am confusing myself and all.Here we go, i used the code from the link which yu specified link but i got the post tittle alone. I want it to show the posts instead of tittle. Hope this time i dint or least confused yu. BTW thank yu very much for spendin yur valuable time for me.– FelixJan 17, 2012 at 12:26
-
Once you get the post object, you can display posts either by initiating a loop and using functions like
the_title()
or by calling the fields directly from the post object, like so,$post_object->post_title
.get_posts()
will return an array of post objects, which you can then use however suits you.– mor7iferJan 17, 2012 at 12:29 -
if yu dnt mind, would yu tell me the exact code which is should put in order to get the post instead of tittle???– FelixJan 17, 2012 at 12:57
You can also create a 'sidebar' that is visible only on your home page using:
<?php if(is_home()) {
// Sidebar code here
}
Register the sidebar and use the existing widgets to place the required widgets into the new sidebar.
-
But i dont want to show them in my side bars.i want it to display in my home page.– FelixJan 17, 2012 at 10:22