我正在尝试通过 Wordpress Stats(现在称为 Jetpack)获取基于页面浏览量的前 10 个帖子。在论坛上挖了几个小时后,我设法让这段代码工作(大约..)(因为变量和代码不时改变):
<?php
if ( function_exists('stats_get_csv') && $top_posts = stats_get_csv('postviews', 'days=-1&limit=10')) {
echo '<ol class="most-viewed">';
foreach ( $top_posts as $post ) {
if($post['post_id'] && get_post($post['post_id']))
echo '<li><a href="' . get_permalink( $post['post_id'] ) . '">' .
get_the_title( $post['post_id'] ) . '</a> (' . number_format_i18n( $post['views']) .' visits)</li>';
}
echo '</ol>';
}
?>
现在我想从这个列表中排除页面并且只有帖子。问题是 WordPress.com Stats API 不提供 post_type 过滤器。我应该把这个放在某个地方
if ( !isset($post->post_type) || $post->post_type != 'post' )
你能帮我指出我应该在哪里添加它吗?
提前致谢!:D