Support » Plugins » [Plugin: WordPress.com Popular Posts] Could you Add a Shortcode?

  • Resolved Tim Nicholson

    (@timnicholson)


    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Many thanks for your contribution! I will sure add this feature in the next version of wppp! 🙂

    frasten, that’s great! I always think its best to get any enhancements rolled into the original plugin, as long as they are of general value to other users. That way we don’t have to worry about upgrading when a new version comes out.

    BTW, kudos to you for your well-written code that this was so easy to do and also for including the cache feature.

    What about thumbnail for popular posts? I’m searching any way to get thumbnail next to popular posts in widget :\

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: WordPress.com Popular Posts] Could you Add a Shortcode?’ is closed to new replies.