Working with the Popular Articles Widget

This widget shows a number of articles from all knowledge bases based on their number of likes.

[iconheading type=”h2″ style=”glyphicon-cog”]Widget Settings[/iconheading]

Popular Articles Widget Settings

Popular Articles Widget Settings

Simply go to Appearance Widgets and drag and drop the widget to your desired location. The settings will ask you for the title and the number of articles to show.

[iconheading type=”h2″ style=”glyphicon-eye-open”]Widget Output[/iconheading]

Popular Articles Widget Output

Popular Articles Widget Output

The screenshot above shows the output of the widget.

[iconheading type=”h2″ style=”glyphicon-plus”]Extending the Widget[/iconheading]

The argument that goes inside theĀ WP_Query instantiation is filtered. So you can change it from outside using a plugin. The usage is something like this.

[php]
/**
* Modify the popular widget query parameters
*
* @see http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* @param array $arg The default query parameters
* @return array Modified query parameters.
*/
function my_popular_widget_ext( $arg ) {
// Conditionally add the category parameter
// for category archive pages
// This will make the popular widget to show articles
// only under the current category
if ( is_category() ) {
$arg[‘cat’] = get_query_var( ‘cat’ );
}
return $arg;
}
add_filter( ‘ipt_kb_popular_widget_query_args’, ‘my_popular_widget_ext’ );
[/php]

The widget class is located under /inc/class-ipt-kb-popular-widget.php.

Swashata has written 257 articles

Hi there, I am the Lead Developer at WPQuark.com. I love to create something beautiful for WordPress and here I write about how to use them. When I am not working, usually I am doing a number of other creative things ;).

2 thoughts on “Working with the Popular Articles Widget

  1. Tarunima says:

    Hi, First of all let me begin by thanking you for this theme. The UI is delightful.
    I wanted to get rid of the popular articles widget at the bottom of the home page. Is that possible?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.