php 类别过滤器分类多过滤器多过滤器多过滤器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 类别过滤器分类多过滤器多过滤器多过滤器相关的知识,希望对你有一定的参考价值。

query_posts('meta_key=featured&meta_value=featured&showposts=1' );
  if (have_posts()) : 
   while (have_posts()) : the_post();
 	$feature_post='<div class="post-holder"><div class="main-post">';
	if(has_post_thumbnail()) $feature_post .= get_the_post_thumbnail(get_the_ID(),'post_thumbnail_large'); 
	$feature_post .='<div class="post-bott"><h3><a href="'.get_permalink().'">'.get_the_title().'</a></h3>';
	$feature_post .= get_the_tag_list('<ul class="tags-bar"><li>', '</li><li> ', '</li></ul>'); 
	$featured_id = get_the_ID();
	$feature_post .='</div></div></div>'; 
  endwhile; endif; 
wp_reset_query();

global $wp_query;

$featured = '';
$orderby ='';
$args_array1 = array();
$args_array2 = array();
$most_viewed = array();
$viewed_time = 'all_time';

if (function_exists('wmp_get_popular'))
{
	if(!empty($_GET['time']))
	{
		switch($_GET['time'])
		{
			case 'today':
				$viewed_time = 'daily';
				break;
			case 'thisweek':
				$viewed_time = 'weekly';
				break;
			case 'thismonth':
				$viewed_time = 'monthly';
				break;
			case 'thisyear':
				$viewed_time = 'yearly';	
				break;

			default:
				$viewed_time = 'all_time';
				break;
		}
	}

 	$posts	= wmp_get_popular(array( 'post_type' => 'post', 'range' => $viewed_time ));

	foreach ( $posts as $post )
	{
		setup_postdata( $post );
		if(in_category( get_query_var('cat'), get_the_ID() )){
			$most_viewed[] =	get_the_ID();
		}
	}
	
	
}

if(!empty($_GET['browse']))
{
	switch($_GET['browse'])
	{
		case 'random':
			$args_array1['orderby'] = 'rand';
			$args_array1['post__not_in'] = array($featured_id);
		break;
		case 'featured':
			$args_array1['meta_key'] = 'featured';
			$args_array1['meta_value'] = 'featured';
		break;
		case 'mostviewed':
			if(!empty($most_viewed)){
				$args_array1['post__in'] = $most_viewed;
			}
			if($viewed_time == 'yearly')
			{
				$args_array1['year'] = date('Y');	
			}
		break;
		default:
			$args_array1 = array();
			break;
	}
}
else{
	$args_array1['post__not_in'] = array($featured_id);
}
if(!empty($_GET['time']))
{
	switch($_GET['time'])
	{
		case 'today':
			$args_array2['day'] = date('d');
			break;
		case 'thisweek':
			$args_array2['w'] = date('W');
			break;
		case 'thismonth':
			$args_array2['monthnum'] = date('n');
			break;
		case 'thisyear':
			$args_array2['year'] = date('Y');	
			break;
		default:
			$args_array2 = array();
			break;
	}
}

$args_2 = array_merge( $wp_query->query, $args_array1, $args_array2);

query_posts( $args_2 );

以上是关于php 类别过滤器分类多过滤器多过滤器多过滤器的主要内容,如果未能解决你的问题,请参考以下文章

多对多关系过滤器

Django模板过滤2个多对多字段

使用JS进行多类别过滤?

如何过滤 EF Core 中的多对多联接

Laravel 5 / Eloquent - 对属于多的关系进行查询过滤

在 Django Admin 中过滤多对多框