本文整理汇总了PHP中td_global::current_category_obj方法的典型用法代码示例。如果您正苦于以下问题:PHP td_global::current_category_obj方法的具体用法?PHP td_global::current_category_obj怎么用?PHP td_global::current_category_obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类td_global
的用法示例。
在下文中一共展示了td_global::current_category_obj方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: td_modify_main_query_for_category_page
function td_modify_main_query_for_category_page($query)
{
//checking for category page and main query
if (!is_admin() and is_category() and $query->is_main_query()) {
// get the category object - with or without permalinks
if (empty($query->query_vars['cat'])) {
td_global::$current_category_obj = get_category_by_path(get_query_var('category_name'), false);
// when we have permalinks, we have to get the category object like this.
} else {
td_global::$current_category_obj = get_category($query->query_vars['cat']);
}
// we are on a category page with an ID that doesn't exists - wp will show a 404 and we do nothing
if (is_null(td_global::$current_category_obj)) {
return;
}
//get the number of page where on
$paged = get_query_var('paged');
//get the `filter_by` URL($_GET) variable
$filter_by = get_query_var('filter_by');
//get the limit of posts on the category page
$limit = get_option('posts_per_page');
//echo $filter_by;
switch ($filter_by) {
case 'featured':
//get the category object
$query->set('category_name', td_global::$current_category_obj->slug);
$query->set('cat', get_cat_ID(TD_FEATURED_CAT));
//add the fetured cat
break;
case 'popular':
$query->set('meta_key', td_page_views::$post_view_counter_key);
$query->set('orderby', 'meta_value_num');
$query->set('order', 'DESC');
break;
case 'popular7':
$query->set('meta_key', td_page_views::$post_view_counter_7_day_total);
$query->set('orderby', 'meta_value_num');
$query->set('order', 'DESC');
break;
case 'review_high':
$query->set('meta_key', td_review::$td_review_key);
$query->set('orderby', 'meta_value_num');
$query->set('order', 'DESC');
break;
case 'random_posts':
$query->set('orderby', 'rand');
break;
}
//end switch
// how many posts are we showing in the big grid for this category
$offset = td_api_category_top_posts_style::_helper_get_posts_shown_in_the_loop();
// offset + custom pagination - if we have offset, WordPress overwrites the pagination and works with offset + limit
if (empty($query->is_feed)) {
if (!empty($offset) and $paged > 1) {
$query->set('offset', $offset + ($paged - 1) * $limit);
} else {
$query->set('offset', $offset);
}
}
//print_r($query);
}
//end if main query
}