[Plugin: WordPress.com Popular Posts] Could you Add a Shortcode?
-
Would you be willing to add a shortcode for us to be able to display our most popular posts in a page? This would allow us to easily create a dedicated “Top 10 Posts” page or whatever.
Here’s the code to add to your plugin:
function WPPP_shortcode_popular_posts( $user_args = '' ) { $wppp = new WPPP(); $args = shortcode_atts( $wppp->defaults, $user_args ); $wppp->widget( $args ); } add_shortcode('wp_popular_posts', 'WPPP_shortcode_popular_posts');
It creates a simple function similar to your direct embed function for sidebars, but the arguments for shortcodes are in a different format, so you have to use a different parse function: shortcode_atts().
For users, here is an example that displays a nice top 10 list, complete with title, number of views, excerpt, and its cached for performance. Just be SURE you paste this into the WP page in HTML or the editor will screw up the HTML formatting in the format= parameter.
[wp_popular_posts title='' number=10 list_tag=ol format='<a href="%post_permalink%" title="%post_title_attribute%">%post_title%</a> (%post_views% views)<p>%post_excerpt%</p>' excerpt_length=200 cachename=popular-posts-page]
Feel free to add the magic_number= parameter if you aren’t getting a full 10 posts returned.
- The topic ‘[Plugin: WordPress.com Popular Posts] Could you Add a Shortcode?’ is closed to new replies.