Saturday, November 8, 2008

Make “recent posts” dinamic in wordpress

Dinamic in meaning in general something that fluctuates as according to condition/conditon. well, such also with theme that discussed here, that is is displaying articles kini (recent posts) without is enclosing article that being mobile/readed. in engine wordpress, display articles kini dinamicly this very easy. because fungsi- provided by wordpress. we only live to use and accustom it appropriate need.

here i shall use get_posts(). may be there that ask around, “kenapa doesn't use query_posts()? “. simple, query_posts() doesn't has parameter to filtered (exclude) id from a post. wanted routine addition to do screening.

furthermore information hit query_posts() can be seen here and get_posts() there. : )
global variable post->id

with is making use global variable post->id (that keeps id from article that read/mobile), we can do screening in another article data taking. i shall give 2 scenarioes:
1. simple

in this scenario, i want to display 7 articles kini without supplement other.

code example:
id. ’&numberposts=7? ); ? >

”>post_title? >

parameter exclude=$post->id used to filtered output data. all articles will displayed except article that has id=$post->id.
2. category equal to article

same like on, only in this scenario is that wants me display articles that has category equal to article that read/mobile. to detect id category from mobile article, i use get_the_category() then keep it in variable cat_id.

code example:
cat_id;
recents = get_posts(’category=’. cat_id. ’&exclude=’. post->id. ’&numberposts=7? ); ? >

post_title;
post_link = get_permalink($recent->id); ? >


not difficult kan?
you can direct insert code on into file sidebar. php.

0 comments:

TIPS © 2008 Template by:
SkinCorner