• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP get_category_by_path函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中get_category_by_path函数的典型用法代码示例。如果您正苦于以下问题:PHP get_category_by_path函数的具体用法?PHP get_category_by_path怎么用?PHP get_category_by_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_category_by_path函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: get_people

 protected function get_people($instance)
 {
     $args = ['numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC'];
     if (isset($instance['people_category'])) {
         $people_cat = get_category_by_path($instance['people_category']);
         $args['category'] = $people_cat->cat_ID;
     }
     $people = get_posts($args);
     return array_map(function ($p) {
         return new WidgetPerson($p);
     }, $people);
 }
开发者ID:hjbolide,项目名称:wordpress_roster,代码行数:12,代码来源:roster_widget.php


示例2: 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


示例3: do_action_ref_array


//.........这里部分代码省略.........
             } else {
                 $q['category__not_in'][] = $cat;
                 $q['category__not_in'] = array_merge($q['category__not_in'], get_term_children($cat, 'category'));
             }
         }
         $q['cat'] = implode(',', $req_cats);
     }
     if (!empty($q['category__in'])) {
         $groupby = "{$wpdb->posts}.ID";
     }
     if (!empty($q['category__in'])) {
         $join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) INNER JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id) ";
         $whichcat .= " AND {$wpdb->term_taxonomy}.taxonomy = 'category' ";
         $include_cats = "'" . implode("', '", $q['category__in']) . "'";
         $whichcat .= " AND {$wpdb->term_taxonomy}.term_id IN ({$include_cats}) ";
     }
     if (!empty($q['category__not_in'])) {
         if ($wpdb->has_cap('subqueries')) {
             $cat_string = "'" . implode("', '", $q['category__not_in']) . "'";
             $whichcat .= " AND {$wpdb->posts}.ID NOT IN ( SELECT tr.object_id FROM {$wpdb->term_relationships} AS tr INNER JOIN {$wpdb->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN ({$cat_string}) )";
         } else {
             $ids = get_objects_in_term($q['category__not_in'], 'category');
             if (is_wp_error($ids)) {
                 $ids = array();
             }
             if (is_array($ids) && count($ids > 0)) {
                 $out_posts = "'" . implode("', '", $ids) . "'";
                 $whichcat .= " AND {$wpdb->posts}.ID NOT IN ({$out_posts})";
             }
         }
     }
     // Category stuff for nice URLs
     if ('' != $q['category_name'] && !$this->is_singular) {
         $reqcat = get_category_by_path($q['category_name']);
         $q['category_name'] = str_replace('%2F', '/', urlencode(urldecode($q['category_name'])));
         $cat_paths = '/' . trim($q['category_name'], '/');
         $q['category_name'] = sanitize_title(basename($cat_paths));
         $cat_paths = '/' . trim(urldecode($q['category_name']), '/');
         $q['category_name'] = sanitize_title(basename($cat_paths));
         $cat_paths = explode('/', $cat_paths);
         $cat_path = '';
         foreach ((array) $cat_paths as $pathdir) {
             $cat_path .= ($pathdir != '' ? '/' : '') . sanitize_title($pathdir);
         }
         //if we don't match the entire hierarchy fallback on just matching the nicename
         if (empty($reqcat)) {
             $reqcat = get_category_by_path($q['category_name'], false);
         }
         if (!empty($reqcat)) {
             $reqcat = $reqcat->term_id;
         } else {
             $reqcat = 0;
         }
         $q['cat'] = $reqcat;
         $join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) INNER JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id) ";
         $whichcat = " AND {$wpdb->term_taxonomy}.taxonomy = 'category' ";
         $in_cats = array($q['cat']);
         $in_cats = array_merge($in_cats, get_term_children($q['cat'], 'category'));
         $in_cats = "'" . implode("', '", $in_cats) . "'";
         $whichcat .= "AND {$wpdb->term_taxonomy}.term_id IN ({$in_cats})";
         $groupby = "{$wpdb->posts}.ID";
     }
     // Tags
     if ('' != $q['tag']) {
         if (strpos($q['tag'], ',') !== false) {
             $tags = preg_split('/[,\\s]+/', $q['tag']);
开发者ID:SymbiSoft,项目名称:litprojects,代码行数:67,代码来源:query.php


示例4: test_get_category_by_path

	/**
	 * Validate get_category_by_path function
	 */
	function test_get_category_by_path() {

		// create Test Categories
		$root_id = $this->factory->category->create(
			array(
				'slug' => 'root',
			)
		);
		$root_cat_id = $this->factory->category->create(
			array(
				'slug' => 'cat',
				'parent' => $root_id
			)
		);
		$root_cat_cat_id = $this->factory->category->create(
			array(
				'slug' => 'cat', //note this is modified on create
				'parent' => $root_cat_id
			)
		);
		$root_path_id = $this->factory->category->create(
			array(
				'slug' => 'path',
				'parent' => $root_id
			)
		);
		$root_path_cat_id = $this->factory->category->create(
			array(
				'slug' => 'cat', //note this is modified on create
				'parent' => $root_path_id
			)
		);
		$root_level_id = $this->factory->category->create(
			array(
				'slug' => 'level-1',
				'parent' => $root_id
			)
		);
		$root_level_cat_id = $this->factory->category->create(
			array(
				'slug' => 'cat', //note this is modified on create
				'parent' => $root_level_id
			)
		);

		// Validate Full Match
		$ret_cat = get_category_by_path( '/root/level-1', true );
		$this->assertEquals( $root_level_id, $ret_cat->term_id );
		$this->assertNull( get_category_by_path( 'level-1', true ) );
		$this->assertNull( get_category_by_path( 'nocat/nocat/', true) );

		// Validate Partial Match
		$ret_cat = get_category_by_path( 'level-1', false );
		$this->assertEquals( $root_level_id, $ret_cat->term_id );
		$ret_cat = get_category_by_path( 'root/cat/level-1', false );
		$this->assertEquals( $root_level_id, $ret_cat->term_id );
		$ret_cat = get_category_by_path( 'root$2Fcat%20%2Flevel-1', false );
		$this->assertEquals( $root_level_id, $ret_cat->term_id );
		$this->assertNull( get_category_by_path( 'nocat/nocat/', false) );
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:63,代码来源:category.php


示例5: get_header

<?php

get_header();
?>
<section style="border-bottom:none;">
    <?php 
$url = sf_get_current_url('base');
$category = get_category_by_path($url, false);
?>
    <h2><?php 
echo $category->name;
?>
</h2>
    <?php 
$query = new WP_query('post_type=partenariat');
//Looking for children articles
while ($query->have_posts()) {
    ?>
        <?php 
    $query->the_post();
    ?>
        <div class="partenariat">
            <p class="partenariat__title">
                <?php 
    the_title();
    ?>
            </p>
            <div class="partenariat__content">
                <div class="partenariat__description">
                    <?php 
    if (!!get_field('img')) {
开发者ID:ArnaudDassy,项目名称:alfa,代码行数:31,代码来源:category-partenariat.php


示例6: do_action_ref_array


//.........这里部分代码省略.........
             $cat = intval($cat);
             $in = strstr($cat, '-') ? false : true;
             $cat = trim($cat, '-');
             if ($in) {
                 $in_cats .= "{$cat}, " . get_category_children($cat, '', ', ');
             } else {
                 $out_cats .= "{$cat}, " . get_category_children($cat, '', ', ');
             }
         }
         $in_cats = substr($in_cats, 0, -2);
         $out_cats = substr($out_cats, 0, -2);
         if (strlen($in_cats) > 0) {
             $in_cats = " AND {$wpdb->post2cat}.category_id IN ({$in_cats})";
         }
         if (strlen($out_cats) > 0) {
             $ids = $wpdb->get_col("SELECT post_id FROM {$wpdb->post2cat} WHERE {$wpdb->post2cat}.category_id IN ({$out_cats})");
             if (is_array($ids) && count($ids > 0)) {
                 foreach ($ids as $id) {
                     $out_posts .= "{$id}, ";
                 }
                 $out_posts = substr($out_posts, 0, -2);
             }
             if (strlen($out_posts) > 0) {
                 $out_cats = " AND {$wpdb->posts}.ID NOT IN ({$out_posts})";
             } else {
                 $out_cats = '';
             }
         }
         $whichcat = $in_cats . $out_cats;
         $groupby = "{$wpdb->posts}.ID";
     }
     // Category stuff for nice URLs
     if ('' != $q['category_name']) {
         $reqcat = get_category_by_path($q['category_name']);
         $q['category_name'] = str_replace('%2F', '/', urlencode(urldecode($q['category_name'])));
         $cat_paths = '/' . trim($q['category_name'], '/');
         $q['category_name'] = sanitize_title(basename($cat_paths));
         $cat_paths = '/' . trim(urldecode($q['category_name']), '/');
         $q['category_name'] = sanitize_title(basename($cat_paths));
         $cat_paths = explode('/', $cat_paths);
         $cat_path = '';
         foreach ((array) $cat_paths as $pathdir) {
             $cat_path .= ($pathdir != '' ? '/' : '') . sanitize_title($pathdir);
         }
         //if we don't match the entire hierarchy fallback on just matching the nicename
         if (empty($reqcat)) {
             $reqcat = get_category_by_path($q['category_name'], false);
         }
         if (!empty($reqcat)) {
             $reqcat = $reqcat->cat_ID;
         } else {
             $reqcat = 0;
         }
         $q['cat'] = $reqcat;
         $tables = ", {$wpdb->post2cat}, {$wpdb->categories}";
         $join = " LEFT JOIN {$wpdb->post2cat} ON ({$wpdb->posts}.ID = {$wpdb->post2cat}.post_id) LEFT JOIN {$wpdb->categories} ON ({$wpdb->post2cat}.category_id = {$wpdb->categories}.cat_ID) ";
         $whichcat = " AND category_id IN ({$q['cat']}, ";
         $whichcat .= get_category_children($q['cat'], '', ', ');
         $whichcat = substr($whichcat, 0, -2);
         $whichcat .= ")";
         $groupby = "{$wpdb->posts}.ID";
     }
     // Author/user stuff
     if (empty($q['author']) || $q['author'] == '0') {
         $whichauthor = '';
     } else {
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:67,代码来源:query.php


示例7: 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 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');
        // get the category object - with or without permalinks
        if (empty($query->query_vars['cat'])) {
            $td_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_current_category_obj = get_category($query->query_vars['cat']);
        }
        //if this is `yes` then do not show the big grid
        $category_big_grid_hide_option = td_util::get_category_option($td_current_category_obj->cat_ID, 'tdc_slider');
        //offset is hardcoded because of big grid
        $offset = 0;
        if ($category_big_grid_hide_option != 'yes') {
            $offset = 5;
        }
        //echo $filter_by;
        switch ($filter_by) {
            case 'featured':
                //get the category object
                $query->set('category_name', $td_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
        // offset + custom pagination - if we have offset, wordpress overwrites the pagination and works with offset + limit
        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:vikasjain1595,项目名称:wordpresstheme,代码行数:62,代码来源:functions.php


示例8: redirect_canonical


//.........这里部分代码省略.........
                    } else {
                        // Custom taxonomies will have a custom query var, remove those too:
                        $tax_obj = get_taxonomy($obj->taxonomy);
                        if (false !== $tax_obj->query_var) {
                            $qv_remove[] = $tax_obj->query_var;
                        }
                    }
                    $rewrite_vars = array_diff(array_keys($wp_query->query), array_keys($_GET));
                    if (!array_diff($rewrite_vars, array_keys($_GET))) {
                        // Check to see if all the Query vars are coming from the rewrite, none are set via $_GET
                        $redirect['query'] = remove_query_arg($qv_remove, $redirect['query']);
                        //Remove all of the per-tax qv's
                        // Create the destination url for this taxonomy
                        $tax_url = parse_url($tax_url);
                        if (!empty($tax_url['query'])) {
                            // Taxonomy accessible via ?taxonomy=..&term=.. or any custom qv..
                            parse_str($tax_url['query'], $query_vars);
                            $redirect['query'] = add_query_arg($query_vars, $redirect['query']);
                        } else {
                            // Taxonomy is accessible via a "pretty-URL"
                            $redirect['path'] = $tax_url['path'];
                        }
                    } else {
                        // Some query vars are set via $_GET. Unset those from $_GET that exist via the rewrite
                        foreach ($qv_remove as $_qv) {
                            if (isset($rewrite_vars[$_qv])) {
                                $redirect['query'] = remove_query_arg($_qv, $redirect['query']);
                            }
                        }
                    }
                }
            }
        } elseif (is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false && ($cat = get_query_var('category_name'))) {
            $category = get_category_by_path($cat);
            $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids'));
            if (!$category || is_wp_error($category) || !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms)) {
                $redirect_url = get_permalink($wp_query->get_queried_object_id());
            }
        }
        // Post Paging
        if (is_singular() && !is_front_page() && get_query_var('page')) {
            if (!$redirect_url) {
                $redirect_url = get_permalink(get_queried_object_id());
            }
            $redirect_url = trailingslashit($redirect_url) . user_trailingslashit(get_query_var('page'), 'single_paged');
            $redirect['query'] = remove_query_arg('page', $redirect['query']);
        }
        // paging and feeds
        if (get_query_var('paged') || is_feed() || get_query_var('cpage')) {
            while (preg_match("#/{$wp_rewrite->pagination_base}/?[0-9]+?(/+)?\$#", $redirect['path']) || preg_match('#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path']) || preg_match("#/{$wp_rewrite->comments_pagination_base}-[0-9]+(/+)?\$#", $redirect['path'])) {
                // Strip off paging and feed
                $redirect['path'] = preg_replace("#/{$wp_rewrite->pagination_base}/?[0-9]+?(/+)?\$#", '/', $redirect['path']);
                // strip off any existing paging
                $redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path']);
                // strip off feed endings
                $redirect['path'] = preg_replace("#/{$wp_rewrite->comments_pagination_base}-[0-9]+?(/+)?\$#", '/', $redirect['path']);
                // strip off any existing comment paging
            }
            $addl_path = '';
            if (is_feed() && in_array(get_query_var('feed'), $wp_rewrite->feeds)) {
                $addl_path = !empty($addl_path) ? trailingslashit($addl_path) : '';
                if (!is_singular() && get_query_var('withcomments')) {
                    $addl_path .= 'comments/';
                }
                if ('rss' == get_default_feed() && 'feed' == get_query_var('feed') || 'rss' == get_query_var('feed')) {
                    $addl_path .= user_trailingslashit('feed/' . (get_default_feed() == 'rss2' ? '' : 'rss2'), 'feed');
开发者ID:hadywisam,项目名称:WordPress,代码行数:67,代码来源:canonical.php


示例9: mgm_hide_protected


//.........这里部分代码省略.........
                $query->set('category__not_in', array_unique($hide_cats));
                // set negation
                // issue#: 510
                if (substr(get_bloginfo('version'), 0, 3) > 3.0 && !is_page()) {
                    //Note: selectively attach the filter to not apply in other scenarios
                    //issue #1600
                    $post_name = $query->query_vars['name'];
                    if (empty($post_name)) {
                        $current_uri = trim($_SERVER['REQUEST_URI']);
                        $uri = explode('?', $current_uri);
                        $uriArr = explode('/', $uri[0]);
                        if (!empty($uriArr)) {
                            $post_name = $uriArr[1];
                        }
                    }
                    $member = mgm_get_member($user->ID);
                    $membership_type = $member->membership_type;
                    $membership_type = empty($membership_type) ? 'guest' : $membership_type;
                    $arr_memberships = mgm_get_subscribed_membershiptypes($user->ID, $member);
                    if (!in_array($membership_type, $arr_memberships)) {
                        $arr_memberships[] = $membership_type;
                    }
                    $accessible = false;
                    $post_data = mgm_get_post_data_by_name($post_name);
                    // check found
                    if (isset($post_data->ID)) {
                        $post_obj = mgm_get_post($post_data->ID);
                        if (count(array_intersect($post_obj->access_membership_types, $arr_memberships)) > 0) {
                            $accessible = true;
                        }
                    }
                    //not accessible add filter
                    if (!$accessible) {
                        //to filter posts as per category__not_in values
                        add_filter('posts_search', 'mgm_attach_category_not_in');
                    }
                }
            }
            // if on category archive listing page: check cateory is accessible, if not redirect to category_access_redirect_url setting url
            if (!is_super_admin() && !is_home() && is_category()) {
                // url
                $the_url = mgm_current_url();
                //get archived category details
                $loaded_cat = get_category_by_path($the_url, false);
                //getting subcategory by path - issue #1578
                if (empty($loaded_cat)) {
                    $flag = false;
                    $url_segments = preg_split('#/#', $the_url);
                    foreach ($url_segments as $key => $url_segment) {
                        if (strtolower($url_segment) == 'category') {
                            $flag = $key;
                        }
                    }
                    if ($flag) {
                        if (!empty($url_segments[$flag + 2])) {
                            $slug = $url_segments[$flag + 2];
                            $loaded_cat = get_category_by_slug($slug);
                        }
                    }
                }
                // url
                if (!isset($category_access_redirect_url)) {
                    $category_access_redirect_url = $system_obj->get_setting('category_access_redirect_url');
                }
                // issue #: 657
                // if the loaded category cannot be accessed by the user, and if category_access_redirect_url is set, redirect
                if (isset($loaded_cat->cat_ID) && in_array($loaded_cat->cat_ID, $hide_cats) && !empty($category_access_redirect_url) && trailingslashit($the_url) != trailingslashit($category_access_redirect_url)) {
                    // redirect:
                    mgm_redirect($category_access_redirect_url);
                    exit;
                }
            }
        }
    }
    // endif
    // hide terms
    $hide_terms = mgm_content_exclude_by_user($user->ID, 'taxonomy');
    //hide terms
    // set filter
    if (is_array($hide_terms) && !empty($hide_terms)) {
        // flag
        $run_term_notin = true;
        // set filter
        $query->set('tag__not_in', array_unique($hide_terms));
        // set negation
        // set in search
        if (substr(get_bloginfo('version'), 0, 3) > 3.0 && !is_page()) {
            //note: selectively attach the filter to not apply in other scenarios
            add_filter('posts_search', 'mgm_attach_tag_not_in');
            //to filter posts as per tag__not_in values
        }
    }
    // term check
    if ($run_cat_notin || $run_term_notin) {
        add_filter('list_terms_exclusions', 'mgm_exclude_terms');
        // terms
    }
    // return
    return $query;
}
开发者ID:jervy-ez,项目名称:magic-members-test,代码行数:101,代码来源:mgm_content_hooks.php


示例10: customizer_wrapper_preview_type

function customizer_wrapper_preview_type($previewed_url = null)
{
    //make this usable on front-end templating and backend-admin
    //by also handling the easy cases: regular templating
    if (true === is_single()) {
        return array('id' => get_query_var('p'), 'type' => 'single');
    } else {
        if (true === is_home()) {
            return array('id' => null, 'type' => 'home');
        } else {
            if (true === is_category()) {
                return array('id' => get_query_var('cat'), 'type' => 'category');
            } else {
                if (true === is_author()) {
                    return array('id' => get_query_var('author'), 'type' => 'author');
                }
            }
        }
    }
    if (null === $previewed_url) {
        //the harder stuff: ?url= parameter
        //first step, figure out the url
        $previewed_url = $_GET['url'];
        if (empty($previewed_url)) {
            $full = $_SERVER['HTTP_REFERER'];
            $parsed = parse_url($full);
            $query = $parsed['query'];
            $args = array();
            parse_str($query, $args);
            $previewed_url = $args['url'];
        }
    }
    $previewed_url = apply_filters('customizer_demo_preview_url', $previewed_url);
    if (empty($previewed_url)) {
        return apply_filters('customizer_wrapper_preview_type', array('url' => null, 'id' => null, 'type' => null));
    }
    //next step: figure out what kind of page the
    //$previewed_url represents
    $object_id = null;
    $post_id = null;
    //check if it's a post
    $post_id = url_to_postid($previewed_url);
    if (0 === $post_id) {
        //last attempt to parse (recipes fail url_to_postid)
        $parsed = parse_url($previewed_url);
        $matches = array();
        //catch ?p=123 (guid-like) permalinks
        preg_match_all('/^\\/(\\d{1,})\\//', $parsed['path'], $matches);
        if (isset($matches[1]) && isset($matches[1][0])) {
            $post_id = $matches[1][0];
        }
    }
    if (null !== $post_id && 0 !== $post_id) {
        $type = 'single';
        $object_id = $post_id;
    } else {
        //check if it's a category
        $home_url = get_home_url();
        $cat = get_category_by_path(str_replace($home_url, "", $previewed_url), $full_match = true, constant('OBJECT'));
        if (null !== $cat) {
            $type = 'category';
            $object_id = $cat->ID;
        }
        //check if it's a homepage
        if (null === $type) {
            if ($previewed_url === $home_url) {
                $type = 'homepage';
            }
        }
    }
    return apply_filters('customizer_wrapper_preview_type', array('url' => $previewed_url, 'id' => $object_id, 'type' => $type));
}
开发者ID:resarahman,项目名称:customizer-demo,代码行数:72,代码来源:core.php


示例11: wk_navigation_display

function wk_navigation_display($language, $posts_num, $mode = 1, $page_type = '')
{
    include 'languages/' . $language . '.php';
    global $url;
    global $addon;
    global $paged;
    //find from page_type
    if ($page_type == 'cat') {
        $cat = get_category_by_path($_SERVER['REQUEST_URI'], false);
        $posts_num = $cat->count;
    }
    if ($mode == 0) {
        ?>
		<div id="wp-pagenavi">
			<span class="pages"><?php 
        echo $page_txt;
        ?>
 <?php 
        echo $paged;
        ?>
 <?php 
        echo $from_txt;
        ?>
 <?php 
        $last_page = intval($posts_num / 10);
        $last_page++;
        echo $last_page;
        ?>
</span>
			<span class="navi-choices">
				<a href="<?php 
        echo $url . $addon;
        ?>
" title="« Πρώτη Σελίδα">« <?php 
        echo $first_txt;
        ?>
</a>
				<a href="<?php 
        if ($paged <= 2) {
            echo $url . $addon;
        } else {
            $new_paged = $paged - 1;
            echo $url . 'page/' . $new_paged . '/' . $addon;
        }
        ?>
">«</a>
				<?php 
        if ($paged < 4) {
            $start = 1;
        } else {
            $start = $paged - 1;
        }
        if ($last_page - $paged > 3) {
            $end = $paged + 3;
        } else {
            $end = $last_page + 1;
        }
        for ($i = $start; $i < $end; $i++) {
            if ($i == $paged) {
                ?>
						<span class="current"><?php 
                echo $paged;
                ?>
</span>
				<?php 
            } else {
                ?>
						<a href="<?php 
                if ($i != 1) {
                    echo $url . 'page/' . $i . '/' . $addon;
                } else {
                    echo $url . $addon;
                }
                ?>
" title="<?php 
                echo $i;
                ?>
"><?php 
                echo $i;
                ?>
</a>
				<?php 
            }
        }
        ?>
				<a href="<?php 
        if ($paged != $last_page) {
            $new_paged = $paged + 1;
            echo $url . 'page/' . $new_paged . '/' . $addon;
        } else {
            echo $_SERVER['REQUEST_URI'];
        }
        ?>
">»</a>
				<a href="<?php 
        if ($last_page != 1) {
            echo $url . 'page/' . $last_page . '/' . $addon;
        } else {
            echo $url . $addon;
        }
//.........这里部分代码省略.........
开发者ID:Knorcedger,项目名称:main,代码行数:101,代码来源:index.php


示例12: get_weekdays

 protected function get_weekdays()
 {
     global $week_mapping;
     $weekdays_cat = get_category_by_path($this->options['weekday_category']);
     $weekdays = array_map(function ($t) {
         return get_category($t);
     }, get_term_children($weekdays_cat->term_id, $weekdays_cat->taxonomy));
     $result = [];
     foreach ($weekdays as $weekday) {
         $index = $week_mapping[strtoupper($weekday->cat_name)];
         $result[$index] = $weekday;
     }
     ksort($result);
     return $result;
 }
开发者ID:hjbolide,项目名称:wordpress_roster,代码行数:15,代码来源:roster_admin.php


示例13: set_taxonomy_by_permalink

function set_taxonomy_by_permalink($user_category_permalink, $user_category_id)
{
    $permalinkIsTaxonomy = false;
    $taxonomy = false;
    $c = get_category_by_path($user_category_permalink, false);
    //If getting category fails, trying to get custom taxonomy
    if ($c == NULL) {
        $c = get_taxonomy_by_path($user_category_permalink);
    }
    // So is it a category/taxonomy? Let's also tell the permalink parser we already figured it out
    if ($c) {
        $user_category_id = $c->term_id;
        $permalinkIsTaxonomy = true;
        $taxonomy = $c->taxonomy;
    }
    return array($user_category_id, $permalinkIsTaxonomy, $taxonomy);
}
开发者ID:a-i-ko93,项目名称:ipl-foodblog,代码行数:17,代码来源:posts.php


示例14: do_action_ref_array


//.........这里部分代码省略.........
             $cat = intval($cat);
             $in = $cat > 0;
             $cat = abs($cat);
             if ($in) {
                 $q['category__in'][] = $cat;
                 $q['category__in'] = array_merge($q['category__in'], get_term_children($cat, 'category'));
             } else {
                 $q['category__not_in'][] = $cat;
                 $q['category__not_in'] = array_merge($q['category__not_in'], get_term_children($cat, 'category'));
             }
         }
     }
     if (!empty($q['category__in']) || !empty($q['category__not_in']) || !empty($q['category__and'])) {
         $groupby = "{$wpdb->posts}.ID";
     }
     if (!empty($q['category__in'])) {
         $join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) INNER JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id) ";
         $whichcat .= " AND {$wpdb->term_taxonomy}.taxonomy = 'category' ";
         $include_cats = "'" . implode("', '", $q['category__in']) . "'";
         $whichcat .= " AND {$wpdb->term_taxonomy}.term_id IN ({$include_cats}) ";
     }
     if (!empty($q['category__not_in'])) {
         $ids = get_objects_in_term($q['category__not_in'], 'category');
         if (is_wp_error($ids)) {
             return $ids;
         }
         if (is_array($ids) && count($ids > 0)) {
             $out_posts = "'" . implode("', '", $ids) . "'";
             $whichcat .= " AND {$wpdb->posts}.ID NOT IN ({$out_posts})";
         }
     }
     // Category stuff for nice URLs
     if ('' != $q['category_name']) {
         $reqcat = get_category_by_path($q['category_name']);
         $q['category_name'] = str_replace('%2F', '/', urlencode(urldecode($q['category_name'])));
         $cat_paths = '/' . trim($q['category_name'], '/');
         $q['category_name'] = sanitize_title(basename($cat_paths));
         $cat_paths = '/' . trim(urldecode($q['category_name']), '/');
         $q['category_name'] = sanitize_title(basename($cat_paths));
         $cat_paths = explode('/', $cat_paths);
         $cat_path = '';
         foreach ((array) $cat_paths as $pathdir) {
             $cat_path .= ($pathdir != '' ? '/' : '') . sanitize_title($pathdir);
         }
         //if we don't match the entire hierarchy fallback on just matching the nicename
         if (empty($reqcat)) {
             $reqcat = get_category_by_path($q['category_name'], false);
         }
         if (!empty($reqcat)) {
             $reqcat = $reqcat->term_id;
         } else {
             $reqcat = 0;
         }
         $q['cat'] = $reqcat;
         $join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) INNER JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id) ";
         $whichcat = " AND {$wpdb->term_taxonomy}.taxonomy = 'category' ";
         $in_cats = array($q['cat']);
         $in_cats = array_merge($in_cats, get_term_children($q['cat'], 'category'));
         $in_cats = "'" . implode("', '", $in_cats) . "'";
         $whichcat .= "AND {$wpdb->term_taxonomy}.term_id IN ({$in_cats})";
         $groupby = "{$wpdb->posts}.ID";
     }
     // Tags
     if ('' != $q['tag']) {
         if (strpos($q['tag'], ',') !== false) {
             $tags = preg_split('/[,\\s]+/', $q['tag']);
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:67,代码来源:query.php


示例15: do_action_ref_array


//.........这里部分代码省略.........
         $q['cat'] = '' . urldecode($q['cat']) . '';
         $q['cat'] = addslashes_gpc($q['cat']);
         $cat_array = preg_split('/[,\\s]+/', $q['cat']);
         $q['cat'] = '';
         $req_cats = array();
         foreach ((array) $cat_array as $cat) {
             $cat = intval($cat);
             $req_cats[] = $cat;
             $in = $cat > 0;
             $cat = abs($cat);
             if ($in) {
                 $q['category__in'][] = $cat;
                 $q['category__in'] = array_merge($q['category__in'], get_term_children($cat, 'category'));
             } else {
                 $q['category__not_in'][] = $cat;
                 $q['category__not_in'] = array_merge($q['category__not_in'], get_term_children($cat, 'category'));
             }
         }
         $q['cat'] = implode(',', $req_cats);
     }
     if (!empty($q['category__in'])) {
         $join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) INNER JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id) ";
         $whichcat .= " AND {$wpdb->term_taxonomy}.taxonomy = 'category' ";
         $include_cats = "'" . implode("', '", $q['category__in']) . "'";
         $whichcat .= " AND {$wpdb->term_taxonomy}.term_id IN ({$include_cats}) ";
     }
     if (!empty($q['category__not_in'])) {
         $cat_string = "'" . implode("', '", $q['category__not_in']) . "'";
         $whichcat .= " AND {$wpdb->posts}.ID NOT IN ( SELECT tr.object_id FROM {$wpdb->term_relationships} AS tr INNER JOIN {$wpdb->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN ({$cat_string}) )";
     }
     // Category stuff for nice URLs
     if ('' != $q['category_name'] && !$this->is_singular) {
         $q['category_name'] = implode('/', array_map('sanitize_title', explode('/', $q['category_name'])));
         $reqcat = get_category_by_path($q['category_name']);
         $q['category_name'] = str_replace('%2F', '/', urlencode(urldecode($q['category_name'])));
         $cat_paths = '/' . trim($q['category_name'], '/');
         $q['category_name'] = sanitize_title(basename($cat_paths));
         $cat_paths = '/' . trim(urldecode($q['category_name']), '/');
         $q['category_name'] = sanitize_title(basename($cat_paths));
         $cat_paths = explode('/', $cat_paths);
         $cat_path = '';
         foreach ((array) $cat_paths as $pathdir) {
             $cat_path .= ($pathdir != '' ? '/' : '') . sanitize_title($pathdir);
         }
         //if we don't match the entire hierarchy fallback on just matching the nicename
         if (empty($reqcat)) {
             $reqcat = get_category_by_path($q['category_name'], false);
         }
         if (!empty($reqcat)) {
             $reqcat = $reqcat->term_id;
         } else {
             $reqcat = 0;
         }
         $q['cat'] = $reqcat;
         $join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) INNER JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id) ";
         $whichcat = " AND {$wpdb->term_taxonomy}.taxonomy = 'category' ";
         $in_cats = array($q['cat']);
         $in_cats = array_merge($in_cats, get_term_children($q['cat'], 'category'));
         $in_cats = "'" . implode("', '", $in_cats) . "'";
         $whichcat .= "AND {$wpdb->term_taxonomy}.term_id IN ({$in_cats})";
         $groupby = "{$wpdb->posts}.ID";
     }
     // Tags
     if ('' != $q['tag']) {
         if (strpos($q['tag'], ',') !== false) {
             $tags = preg_split('/[,\\s]+/', $q['tag']);
开发者ID:owaismeo,项目名称:wordpress-10,代码行数:67,代码来源:query.php


示例16: get_pagination

 static function get_pagination()
 {
     global $wp_query;
     if (td_global::$current_template == '404') {
         return;
     }
     $pagenavi_options = self::pagenavi_init();
     $request = $wp_query->request;
     $posts_per_page = intval(get_query_var('posts_per_page'));
     $paged = intval(get_query_var('paged'));
     $numposts = $wp_query->found_posts;
     $max_page = $wp_query->max_num_pages;
     //hack for category pages - pagination
     if (!is_admin() and is_category()) {
         // get the category object - with or without permalinks
         if (empty($wp_query->query_vars['cat'])) {
             $td_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_current_category_obj = get_category($wp_query->query_vars['cat']);
         }
         if (isset($td_current_category_obj->cat_ID)) {
             $disable_category_big_grid_hide_option = td_util::get_category_option($td_current_category_obj->cat_ID, 'tdc_slider');
         } else {
             $disable_category_big_grid_hide_option = '';
         }
         //check if the slider for this category is enabled or disabled
         if ($disable_category_big_grid_hide_option != 'yes') {
             $numposts = $wp_query->found_posts - 5;
             //5 from big grid
             $max_page = ceil($numposts / $posts_per_page);
         }
         //echo '<br>num posts: '.$numposts;
         //echo '<br>max pages: '.$max_page;
     }
     if (empty($paged) || $paged == 0) {
         $paged = 1;
     }
     $pages_to_show = intval($pagenavi_options['num_ 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_category_by_slug函数代码示例发布时间:2022-05-15
下一篇:
PHP get_category函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap