Hey there,
If you want to display different lists of popular posts by category on a page, you can use the [wpp] shortcode in conjuction with the cat parameter (see Settings > WordPress Popular Posts > Parameters for more).
Similarly, if you want to display a list of popular posts by category when archive.php is loaded by WordPress, you can use the wpp_get_mostpopular() template tag in conjunction with the cat parameter. For example:
<?php
// Somewhere inside your archive.php template ...
if ( function_exists('wpp_get_mostpopular') ) {
// WPP parameters
$args = array(
'range' => 'weekly'
);
// Get the category ID so we can use it with the wpp_get_mostpopular() template tag
if ( is_category() ) {
$args['cat'] = get_queried_object_id();
}
wpp_get_mostpopular( $args );
}
?>
-
This reply was modified 7 years, 2 months ago by
Hector Cabrera. Reason: Wrapped code in backticks
-
This reply was modified 7 years, 2 months ago by
Hector Cabrera. Reason: Added link to wpp_get_mostpopular() function documentation