当前位置: 首页>>代码示例>>PHP>>正文


PHP td_global::current_category_obj方法代码示例

本文整理汇总了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
}
开发者ID:weerapat,项目名称:wp-daily,代码行数:63,代码来源:td_wp_booster_functions.php


注:本文中的td_global::current_category_obj方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。