php 插件WP热门帖子

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 插件WP热门帖子相关的知识,希望对你有一定的参考价值。


----- polular posts function wpp_get_mostpopular

<?php if (function_exists('wpp_get_mostpopular')) : ?>
	<?php wpp_get_mostpopular(array(
					'header' => '',
					'limit' => 2,
					'range' => 'daily',
					'order_by' => 'views',
					'post_type' => 'post',
					'cat' => '',
					'author' => '',
					'title_length' => 0,
					'excerpt_length' => 200,
					'excerpt_format' => true,				
					'thumbnail_width' => 74,
					'thumbnail_height' => 45,
					'thumbnail_selection' => 'wppgenerated',
					'rating' => false,
					'stats_comments' => false,
					'stats_views' => false,
					'stats_author' => true,
					'stats_date' => false,
					'stats_date_format' => 'F j, Y',
					'custom_html' => true,
					'wpp_start' => '&lt;ul class=&quot;articles-list&quot; &gt;',
					'wpp_end' => '&lt;/ul&gt;',
					'post_start' => '<li>',
					'post_end' => '</li>',
					'header_start' => '<h2>',
					'header_end' => '</h2>',
					'do_pattern' => true,
					'pattern_form' => '<div class=&quot;headline&quot;><div class=&quot;img-holder&quot;>{image}</div><div class=&quot;holder&quot;><h2>{title}</h2>{stats}</div></div><p>{summary}</p>'									
	)); ?>
<?php endif; ?>

-----

if (function_exists('wpp_get_mostpopular') ){
	function get_popular_post_ids($args) {

		global $wpdb;
		$prefix = $wpdb->prefix . "popularposts";
		$where = "";
		$now = current_time('mysql');

		/* Build the Query */
		$fields = "p.ID AS 'id', p.post_title AS 'title', p.post_date AS 'date', p.post_author AS 'uid', v.pageviews AS 'pageviews'";

		$from = "{$prefix}data v LEFT JOIN {$wpdb->posts} p ON v.postid = p.ID";

		switch( $args['range'] ){
			case "yesterday":
				$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 DAY) ";
				break;

			case "daily":
				$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 DAY) ";
				break;

			case "weekly":
				$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 WEEK) ";
				break;

			case "monthly":
				$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 MONTH) ";
				break;

			default:
				$where .= "";
				break;
		}

		$where .= " AND p.post_type = 'post'";
		$where .= " AND p.post_password = '' AND p.post_status = 'publish'";	

		$orderby = "ORDER BY pageviews DESC";

		$query = "SELECT {$fields} FROM {$from} {$where} {$orderby};";

		$result = $wpdb->get_results($query);

		$counter = 0;
		$myIDs = array();

		foreach ($result as $aPost) {
			$theID = $aPost->id;

			if ( !$theID == "" ) {
				$myIDs[$counter] = $theID;
				$counter++;
			}
		}

		return($myIDs);
	}
}

Разлогинься, вьюшки админе не считаются.

function get_popular_posts_custom($content, $posts_data) {
	$post_ids = array();
	foreach($posts_data as $post){ $post_ids[] = $post->id; }
	return $post_ids;
}

в темплейте

<?php
				if(function_exists('wpp_get_mostpopular')){
					add_filter('wpp_html', 'get_popular_posts_custom', 10, 2);
					$wpp = new WordpressPopularPosts;
					$post_ids = $wpp->get_popular_posts(array('post_type' => 'video', 'range' => 'daily', 'order_by' => 'views', 'limit' => '100'));
					print_r($post_ids);
				}
				query_posts(array('post_type' => 'video', 'post__in' => $post_ids, 'orderby' => 'post__in'));
			?>
			<?php if(have_posts()) : ?>
				<div class="movie-list-wrap">
					<div class="movie-list-holder">
						<ul class="movie-list">
							<?php while(have_posts()) : the_post(); ?>
								<?php if (has_post_thumbnail()) : ?>
									<li>
										<a href="<?php the_permalink(); ?>">
											<?php the_post_thumbnail('today-films'); ?>
											<?php get_template_part('blocks/tooltip'); ?>
										</a>
									</li>
								<?php endif; ?>
							<?php endwhile;  ?>
						</ul>
					</div>
					<a class="btn-prev" href="#">Previous</a>
					<a class="btn-next" href="#">Next</a>
				</div>
			<?php endif; wp_reset_query(); remove_filter('wpp_html', 

以上是关于php 插件WP热门帖子的主要内容,如果未能解决你的问题,请参考以下文章

WP REST API 帖子提要不显示特色图片

WP-Pagenavi 无法在最新帖子的静态主页中工作

WP Plugin 中的异步 php 代码

php PHP为每位作者的WP总帖子提供支持

php 从WP查询中排除当前帖子

php 批量更新WP帖子