Top 10 API examples
<?php
/**
* Add categories to the list items.
*
* @since 2.2.0
*
* @param string $output Formatted list item with link and and thumbnail
* @param object $result Object of the current post result
* @param array $args Array of arguments
*
* @return string Output variable with categories added
*/
function tptn_list_cats( $output, $result, $args ) {
$categories = get_the_category_list( ", ", "", $result->ID );
$output .= " " . $categories;
return $output;
}
add_filter( 'tptn_list', 'tptn_list_cats' , 10, 3 );
<?php
/*
* This example fetches the popular posts tracked by Top 10.
*
*/
if ( function_exists( 'get_tptn_pop_posts' ) ) {
$settings = array(
'daily' => TRUE,
'daily_range' => 30,
'limit' => 20,
'strict_limit' => FALSE,
);
$topposts = get_tptn_pop_posts( $settings ); // Array of posts
$topposts = wp_list_pluck( (array) $topposts, 'postnumber' );
$args = array(
'post__in' => $topposts,
'orderby' => 'post__in',
'posts_per_page' => 7,
'ignore_sticky_posts' => 1
);
$my_query = new WP_Query( $args );
if ( $my_query->have_posts() ) {
while ( $my_query->have_posts() ) {
$my_query->the_post();
echo '<a href="' . get_permalink( get_the_ID() ) . '">';
the_title();
echo '</a>';
wp_reset_postdata();
}
} else {
}
wp_reset_query();
}