Wordpress Theme Featured Posts
post_id: 59 / post_date: 2011-06-26
[tab: PS]
I'm modifying the wordpress plugin to include a custom Ordering and expose a method cs_get_featured_posts which wraps query_posts for use directly in a theme. I need this for letting the theme customize the results instead of simply using the widget provided in the original. Browse source.
Changelog
- Add featuredOrder to the add_featured method.
- add cs_get_featured_posts method.
- hook the query_posts to include custom joins and order by to make it more readable than trying to pass all as parameters.
To Arrive at this, I had to try WP_DEBUG and realised that the suggested get_meta_sql doesnt work by looking at query.php.
TODO:
- Check accusation of javascript site hacking.
- Contact Original Author GdnGroups via forum.
- Ask them to merge this / create new plugin.
- What is purpose of featured-post.php?
[tab: SS]
In my theme, to get the picture:
I've only to add the lines below:
cs_get_featured_posts(); while ( have_posts() ) { the_post(); $id = get_the_ID(); echo '<a href="' . get_permalink($id) . '">'; the_title(); echo "</a><br/>"; }
And to configure it, the edit post looks like so.
[tab: php]
function cs_get_featured_posts() { //add filters for posts_join_paged, posts_where_paged, posts_orderby query_posts('posts_per_page=10&showposts=10'); //remove filters } function featposts_join_sql( $meta_sql ) { return " LEFT JOIN wp_postmeta as pmF ON (wp_posts.ID = pmF.post_id AND pmF.meta_key = 'featured') " .= " LEFT JOIN wp_postmeta as pmO ON (wp_posts.ID = pmO.post_id AND pmO.meta_key = 'featuredOrder') "; } function featposts_where_sql( $meta_sql ) { return " AND (pmF.meta_value = 1)"; } function featposts_order_sql( $orderby ) { return 'pmO.meta_value ASC'; }
[tab: source]
[iframe src="http://cselian.com/d/code/serve.php?file=./apps/feat-posts/cs-wp-featured-posts.php"]