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


PHP get_category_children函数代码示例

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


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

示例1: get_category_children

function get_category_children($parent_id)
{
    $cat_list = array($parent_id);
    $query = tep_db_query('select categories_id from ' . TABLE_CATEGORIES . ' where parent_id = ' . (int) $parent_id);
    while ($cat = tep_db_fetch_array($query)) {
        $children = get_category_children($cat['categories_id']);
        $cat_list = array_merge($cat_list, $children);
    }
    return $cat_list;
}
开发者ID:digideskio,项目名称:oscmax2,代码行数:10,代码来源:categories.php

示例2: getchild

function getchild($id)
{
    $result = explode('/', get_category_children($id));
    $childs = array();
    foreach ($result as $i) {
        if (!empty($i)) {
            $childs[] = get_category($i);
        }
    }
    return $childs;
}
开发者ID:Eason-Chen,项目名称:lucia-wordpress,代码行数:11,代码来源:functions.php

示例3: get_category_children

function get_category_children($id, $before = '/', $after = '')
{
    if (0 == $id) {
        return '';
    }
    $chain = '';
    $cat_ids = get_all_category_ids();
    foreach ($cat_ids as $cat_id) {
        if ($cat_id == $id) {
            continue;
        }
        $category = get_category($cat_id);
        if ($category->category_parent == $id) {
            $chain .= $before . $category->cat_ID . $after;
            $chain .= get_category_children($category->cat_ID, $before, $after);
        }
    }
    return $chain;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:19,代码来源:category-template.php

示例4: get_category_children

/**
 * Retrieve category children list separated before and after the term IDs.
 *
 * @since 1.2.0
 *
 * @param int $id Category ID to retrieve children.
 * @param string $before Optional. Prepend before category term ID.
 * @param string $after Optional, default is empty string. Append after category term ID.
 * @param array $visited Optional. Category Term IDs that have already been added.
 * @return string
 */
function get_category_children( $id, $before = '/', $after = '', $visited = array() ) {
	if ( 0 == $id )
		return '';

	$chain = '';
	/** TODO: consult hierarchy */
	$cat_ids = get_all_category_ids();
	foreach ( (array) $cat_ids as $cat_id ) {
		if ( $cat_id == $id )
			continue;

		$category = get_category( $cat_id );
		if ( is_wp_error( $category ) )
			return $category;
		if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) {
			$visited[] = $category->term_id;
			$chain .= $before.$category->term_id.$after;
			$chain .= get_category_children( $category->term_id, $before, $after );
		}
	}
	return $chain;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:33,代码来源:category-template.php

示例5: widget_sub

function widget_sub($args) {
	
	global
	$cat,
	$post;
	
	extract($args);
	
	$options = get_option('widget_sub');
	
	if (is_category()) {
		$category = get_category($cat);
		
		if (get_category_children($category->cat_ID) != '') { 
			echo
				$before_widget,
					$before_title . $options['title_category'] . $after_title,
					'<ul class="clearfix">',
						wp_list_categories('child_of='.$category->cat_ID.'&title_li=&depth=1&hide_empty=0'),
					'</ul>',
				$after_widget;
		}
	}
	
	if (is_page()) {
		$page = wp_list_pages('&child_of='.$post->ID.'&echo=0');
		
		if ($page) {
			echo
				$before_widget,
					$before_title . $options['title_page'] . $after_title,
					'<ul class="clearfix">',
						wp_list_pages('child_of='.$post->ID.'&title_li=&depth=1'),
					'</ul>',
				$after_widget;
		}
	}
}
开发者ID:nunomorgadinho,项目名称:RebelTheme,代码行数:38,代码来源:widget-sub.php

示例6: get_category_children

function get_category_children($id, $before = '/', $after = '')
{
    if (0 == $id) {
        return '';
    }
    $chain = '';
    // TODO: consult hierarchy
    $cat_ids = get_all_category_ids();
    foreach ($cat_ids as $cat_id) {
        if ($cat_id == $id) {
            continue;
        }
        $category = get_category($cat_id);
        if (is_wp_error($category)) {
            return $category;
        }
        if ($category->parent == $id) {
            $chain .= $before . $category->term_id . $after;
            $chain .= get_category_children($category->term_id, $before, $after);
        }
    }
    return $chain;
}
开发者ID:helmonaut,项目名称:owb-mirror,代码行数:23,代码来源:category-template.php

示例7: widget

    function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', $instance['title']);
        ?>

    <?php 
        echo $before_widget;
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        $args = array('depth' => '1');
        $categories = get_categories($args);
        foreach ($categories as $cat) {
            // check if category has child
            if (get_category_children($cat->term_id) != "") {
                echo '<span class="parent-category-title">' . $cat->name . '</span><br />';
                wp_dropdown_categories(array('id' => $cat->term_id, 'class' => 'child-cat-select', 'child_of' => $cat->term_id, 'show_option_none' => 'Select ' . $cat->name, 'hide_if_empty' => 1));
                echo '<br />';
            }
        }
        echo $after_widget;
        wp_enqueue_script('jquery');
        ?>
		<script type="text/javascript"><!--
			jQuery(".child-cat-select").change(function() { 
				if (jQuery(this).val() > 0) {
					location.href = "<?php 
        echo get_option('home');
        ?>
/?cat=" + jQuery(this).val();
				}
			});
		--></script>
     <?php 
    }
开发者ID:48Web,项目名称:Child-Category-Dropdown-Widget,代码行数:36,代码来源:category-dropdown.php

示例8: get_posts


//.........这里部分代码省略.........
					$search .= ' AND ((post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\'))';
				}
				$search .= ' OR (post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\')';
				$search .= ')';
			} else {
				$search = ' AND ((post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\'))';
			}
		}

		// Category stuff

		if ((empty($q['cat'])) || ($q['cat'] == '0') || 
				// Bypass cat checks if fetching specific posts
				( $this->is_single || $this->is_page )) {
			$whichcat='';
		} else {
			$q['cat'] = ''.urldecode($q['cat']).'';
			$q['cat'] = addslashes_gpc($q['cat']);
			if (stristr($q['cat'],'-')) {
				// Note: if we have a negative, we ignore all the positives. It must
				// always mean 'everything /except/ this one'. We should be able to do
				// multiple negatives but we don't :-(
				$eq = '!=';
				$andor = 'AND';
				$q['cat'] = explode('-',$q['cat']);
				$q['cat'] = intval($q['cat'][1]);
			} else {
				$eq = '=';
				$andor = 'OR';
			}
			$join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) ";
			$cat_array = preg_split('/[,\s]+/', $q['cat']);
			$whichcat .= ' AND (category_id '.$eq.' '.intval($cat_array[0]);
			$whichcat .= get_category_children($cat_array[0], ' '.$andor.' category_id '.$eq.' ');
			for ($i = 1; $i < (count($cat_array)); $i = $i + 1) {
				$whichcat .= ' '.$andor.' category_id '.$eq.' '.intval($cat_array[$i]);
				$whichcat .= get_category_children($cat_array[$i], ' '.$andor.' category_id '.$eq.' ');
			}
			$whichcat .= ')';
			if ($eq == '!=') {
				$q['cat'] = '-'.$q['cat']; // Put back the knowledge that we are excluding a category.
			}
		}

		// Category stuff for nice URIs

		if ('' != $q['category_name']) {
			if (stristr($q['category_name'],'/')) {
				$q['category_name'] = explode('/',$q['category_name']);
				if ($q['category_name'][count($q['category_name'])-1]) {
					$q['category_name'] = $q['category_name'][count($q['category_name'])-1]; // no trailing slash
				} else {
					$q['category_name'] = $q['category_name'][count($q['category_name'])-2]; // there was a trailling slash
				}
			}
			$q['category_name'] = sanitize_title($q['category_name']);
			$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_nicename = '" . $q['category_name'] . "'";
			$q['cat'] = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '" . $q['category_name'] . "'");
			$whichcat .= get_category_children($q['cat'], " OR category_id = ");
			$whichcat .= ")";
		}

		// Author/user stuff
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:66,代码来源:classes.php

示例9: intval

    if (isset($params['category'])) {
        $posts_parent_category = $params['category'];
    }
}
if ($posts_parent_category != false) {
    $add_post_q .= ' parent-category-id="' . intval($posts_parent_category) . '" ';
}
if (!isset($params['global']) and $posts_parent_page != false and $posts_parent_category != false and intval($posts_parent_category) > 0) {
    $str0 = 'table=categories&limit=1000&data_type=category&what=categories&' . 'parent_id=0&rel_id=' . $posts_parent_page;
    $page_categories = db_get($str0);
    $sub_cats = array();
    $page_categories = db_get($str0);
    if (is_array($page_categories)) {
        foreach ($page_categories as $item_cat) {
            $sub_cats[] = $item_cat['id'];
            $more = get_category_children($item_cat['id']);
            if ($more != false and is_array($more)) {
                foreach ($more as $item_more_subcat) {
                    $sub_cats[] = $item_more_subcat;
                }
            }
        }
    }
    if (is_array($sub_cats) and in_array($posts_parent_category, $sub_cats)) {
        $add_post_q .= ' selected-category-id=' . intval($posts_parent_category);
    }
}
if (isset($params['is_shop']) and $params['is_shop'] == 'y') {
    $add_post_q .= ' content_type="product"   ';
} else {
    $add_post_q .= '  ';
开发者ID:newaltcoin,项目名称:microweber,代码行数:31,代码来源:admin_live_edit.php

示例10: preg_replace

            $GLOBALS['category_name'] = $GLOBALS['category_name'][count($GLOBALS['category_name']) - 1];
            // no trailing slash
        } else {
            $GLOBALS['category_name'] = $GLOBALS['category_name'][count($GLOBALS['category_name']) - 2];
            // there was a trailling slash
        }
    }
    $GLOBALS['category_name'] = preg_replace('|[^a-z0-9-]|', '', $GLOBALS['category_name']);
    $_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id');
    $_joinCriteria->cascade(new XoopsJoinCriteria(wp_table('categories'), 'category_id', 'cat_ID'));
    $_wCriteria =& new CriteriaCompo(new Criteria('category_nicename', $GLOBALS['category_name']));
    $categoryHandler =& wp_handler('Category');
    $categoryObject =& $categoryHandler->getByNiceName($GLOBALS['category_name']);
    if ($categoryObject) {
        $GLOBALS['cat'] = $categoryObject->getVar('cat_ID');
        $_catc = trim(get_category_children($GLOBALS['cat'], '', ' '));
        $_catc_array = explode(' ', $_catc);
        for ($_i = 0; $_i < count($_catc_array); $_i++) {
            $_wCriteria->add(new Criteria('category_id', intval($_catc_array[$_i])), 'OR');
        }
        $_criteria->add($_wCriteria);
        unset($_wCriteria);
    }
}
// author stuff
if (test_param('author') && get_param('author') != 'all') {
    $GLOBALS['author'] = '' . urldecode(get_param('author')) . '';
    $GLOBALS['author'] = addslashes_gpc($GLOBALS['author']);
    if (stristr($GLOBALS['author'], '-')) {
        $_eq = '!=';
        $_andor = 'AND';
开发者ID:BackupTheBerlios,项目名称:nobunobuxoops-svn,代码行数:31,代码来源:wp-blog-header.php

示例11: get_category_children

				<a title="Post Another Confession" class="btn-secondary-cta post-another-confession" href="#">Post Another Confession</a>
			</div>
		</div>
		<div class="mod-filter-confessions-faq clearfix">
			<h2>Read the Latest Confessions</h2>
			<div class="filter-wrap">
				<span class="label">Filter by:</span>
				<div class="dropdown-custom">
					<select id='tagDropdown' class="tagDropdown" title="Tags" style="z-index: 10; opacity: 0;" >
						<option data-alias="<?php 
echo $url;
?>
" value="all">View All</option>
						<?php 
$childAJQCategroy = '';
$childAJQCategroy = get_category_children('231');
$arrChildAJQCategroy = explode('/', $childAJQCategroy);
sort($arrChildAJQCategroy);
foreach ($arrChildAJQCategroy as $intCatId) {
    if (empty($intCatId)) {
        continue;
    }
    $strCatName = '';
    $strCatName = get_the_category_by_ID($intCatId);
    echo "<option data-alias=\"/confessions/?tags=" . $strCatName . "\" value ='" . $strCatName . "' >#" . strtolower($strCatName) . "</option>";
}
?>
					</select>
					<span class="dropdown-custom-select"><?php 
if (isset($_REQUEST['tags'])) {
    echo $_REQUEST['tags'];
开发者ID:srinivas-qfor,项目名称:jkc-wp,代码行数:31,代码来源:archive-confessions.php

示例12: get_related_categories

 /**
  * gets all parents and child categories for the category passed
  * 
  * @returns array parent and children array merged to return a general array of related categories
  * 
  * @author Ryan R. Bayne
  * @package CSV 2 POST
  * @since 8.1.3
  * @version 1.1
  */
 public function get_related_categories($category_id)
 {
     // get the categories parents
     $parent_array = self::get_category_parents_id($category_id, false, '/', false);
     // remove empty values as is usually returned by get_category_parents()
     $parent_array = array_diff($parent_array, array('', ' '));
     // get the categories children
     $child_string = get_category_children($category_id, '/');
     // turn string to array for the merge
     $child_array = explode('/', $child_string);
     // remove possible empty values (not sure if the child function returns them as the parent one does
     $child_array = array_diff($child_array, array('', ' '));
     // return a merge
     return array_merge($parent_array, $child_array);
 }
开发者ID:WebTechGlobal,项目名称:csv-2-post-1,代码行数:25,代码来源:class-categories.php

示例13: list_cats

    function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 1, $children = FALSE, $child_of = 0, $categoryObjects = null, $recurse = 0, $feed = '', $feed_image = '', $exclude = '', $hierarchical = FALSE, $echo = true)
    {
        $list_cats = '';
        // Optiondates now works
        if ('' == $file) {
            $file = wp_siteurl() . '/index.php';
        }
        $excludeCriteria = null;
        if (!empty($exclude)) {
            $excats = preg_split('/[\\s,]+/', $exclude);
            if (count($excats)) {
                $excludeCriteria = new CriteriaCompo();
                foreach ($excats as $excat) {
                    $exclusions .= ' AND cat_ID <> ' . intval($excat) . ' ';
                    $excludeCriteria->add(new Criteria('cat_ID', $excat, '!='));
                    $catc = trim(get_category_children($excat, '', ' '));
                    $catc_array = explode(' ', $catc);
                    for ($i = 0; $i < count($catc_array); $i++) {
                        $excludeCriteria->add(new Criteria('category_id', intval($catc_array[$i]), '!='));
                    }
                }
            }
        }
        $categoryHandler =& wp_handler('Category');
        if (!$categoryObjects) {
            $criteria =& new CriteriaCompo(new Criteria('cat_ID', 0, '>'));
            if ($excludeCriteria) {
                $criteria->add($excludeCriteria);
            }
            $criteria->setSort('cat_' . $sort_column);
            $criteria->setOrder($sort_order);
            $categoryObjects =& $categoryHandler->getObjects($criteria, false, 'cat_ID, cat_name, category_nicename, category_description cat_description, category_parent');
        }
        if (empty($GLOBALS['category_posts']) || !count($GLOBALS['category_posts'])) {
            $criteria =& new CriteriaCompo('post_status', 'publish');
            if ($excludeCriteria) {
                $criteria->add($excludeCriteria);
            }
            $criteria->setGroupBy('category_id');
            $joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'cat_ID', 'category_id', 'INNER');
            $joinCriteria->cascade(new XoopsJoinCriteria(wp_table('posts'), 'post_id', 'ID', 'INNER'));
            $categoryPostsObjects =& $categoryHandler->getObjects($criteria, false, 'cat_ID, COUNT(' . wp_table('post2cat') . '.post_id) AS cat_count', false, $joinCriteria);
            if ($categoryPostsObjects) {
                foreach ($categoryPostsObjects as $categoryObject) {
                    if (intval($hide_empty) != 1 || $categoryObject->getExtraVar('cat_count') > 0) {
                        $GLOBALS['category_posts'][$categoryObject->getVar('cat_ID')] = $categoryObject->getExtraVar('cat_count');
                    }
                }
            }
        }
        if (intval($optiondates) == 1) {
            $criteria =& new CriteriaCompo('post_status', 'publish');
            if ($excludeCriteria) {
                $criteria->add($excludeCriteria);
            }
            $criteria->setGroupBy('category_id');
            $joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'cat_ID', 'category_id', 'INNER');
            $joinCriteria->cascade(new XoopsJoinCriteria(wp_table('posts'), 'post_id', 'ID', 'INNER'));
            $categoryDateObjects =& $categoryHandler->getObjects($criteria, false, 'cat_ID, DAYOFMONTH(MAX(post_date)) AS lastday,
		                                                     MONTH(MAX(post_date)) AS lastmonth', false, $joinCriteria);
            foreach ($categoryDateObjects as $categoryObject) {
                $category_lastday["" . $categoryObject->getVar('cat_ID')] = $categoryObject->getExtraVar('lastday');
                $category_lastmonth["" . $categoryObject->getVar('cat_ID')] = $categoryObject->getExtraVar('lastmonth');
            }
        }
        if (intval($optionall) == 1 && !$child_of && $categoryObjects) {
            $all = apply_filters('list_cats', $all);
            $link = "<a href=\"" . $file . '?cat=all">' . $all . "</a>";
            if ($list) {
                $list_cats .= "\n\t<li>{$link}</li>";
            } else {
                $list_cats .= "\t{$link}<br />\n";
            }
        }
        $num_found = 0;
        $thelist = "";
        foreach ($categoryObjects as $categoryObject) {
            $category = $categoryObject->exportWpObject();
            $child_list = '';
            if ((!$hierarchical || $category->category_parent == $child_of) && ($children || $category->category_parent == 0)) {
                if ($hierarchical && $children) {
                    $child_list = list_cats($optionall, $all, $sort_column, $sort_order, $file, $list, $optiondates, $optioncount, $hide_empty, $use_desc_for_title, $hierarchical, $category->cat_ID, $categoryObjects, 1, $feed, $feed_image, $exclude, $hierarchical);
                }
                if (intval($hide_empty) == 0 || isset($GLOBALS['category_posts']["{$category->cat_ID}"]) || $child_list) {
                    $num_found++;
                    $link = '<a href="' . get_category_link(0, $category->cat_ID, $category->category_nicename) . '" ';
                    if ($use_desc_for_title == 0 || empty($category->cat_description)) {
                        $link .= 'title="' . sprintf("View all posts filed under %s", htmlspecialchars($category->cat_name)) . '"';
                    } else {
                        $link .= 'title="' . htmlspecialchars(strip_tags($category->cat_description)) . '"';
                    }
                    $link .= '>';
                    $link .= apply_filters('list_cats', $category->cat_name) . '</a>';
                    if (!empty($feed_image) || !empty($feed)) {
                        $link .= ' ';
                        if (empty($feed_image)) {
                            $link .= '(';
                        }
                        $link .= '<a href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename) . '"';
                        if (!empty($feed)) {
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:nobunobuxoops-svn,代码行数:101,代码来源:template-functions-category.php

示例14: index


//.........这里部分代码省略.........
                $ids = array();
                foreach ($orders as $order) {
                    $ids[] = $order['rel_id'];
                }
                $post_params['ids'] = $ids;
            }
        }
        if (isset($post_params['recently_viewed'])) {
            if (defined("MAIN_PAGE_ID") and defined("CONTENT_ID")) {
                $str0 = 'table=stats_pageviews&limit=30&main_page_id=' . MAIN_PAGE_ID . '&page_id=[neq]' . CONTENT_ID . '&fields=page_id&order_by=id desc&no_cache=true';
                $orders = db_get($str0);
                if (!empty($orders)) {
                    $ids = array();
                    foreach ($orders as $order) {
                        $ids[] = $order['page_id'];
                    }
                    $post_params['ids'] = $ids;
                }
            }
        }
        if ($posts_parent_related == false) {
            if (intval($cfg_page_id_force) or !isset($params['global'])) {
                if ($cfg_page_id != false and intval($cfg_page_id) > 0) {
                    $sub_categories = array();
                    $page_categories = false;
                    if (intval($cfg_page_id) != 0 and $cat_from_url == false) {
                        $str0 = 'table=categories&limit=1000&data_type=category&what=categories&' . 'parent_id=0&rel_id=' . $cfg_page_id;
                        $page_categories = db_get($str0);
                        $str0 = 'table=categories&limit=1000&data_type=category&what=categories&' . 'parent_id=0&rel_id=' . $cfg_page_id;
                        $page_categories = db_get('table=categories&limit=1&data_type=category&' . 'parent_id=0&rel_id=' . $cfg_page_id);
                        if (is_array($page_categories)) {
                            foreach ($page_categories as $item_cat) {
                                $sub_categories[] = $item_cat['id'];
                                $more = get_category_children($item_cat['id']);
                                if ($more != false and is_array($more)) {
                                    foreach ($more as $item_more_subcat) {
                                        $sub_categories[] = $item_more_subcat;
                                    }
                                }
                            }
                        }
                    }
                    if ($posts_parent_category != false and intval($posts_parent_category) > 0 and $cat_from_url == false) {
                        if ($page_categories != false and is_array($page_categories) and !empty($page_categories)) {
                            // $sub_categories = array();
                            foreach ($page_categories as $item_cat) {
                                if (intval($item_cat['id']) == intval($posts_parent_category)) {
                                    $sub_categories[] = $item_cat['id'];
                                }
                            }
                        } elseif ($posts_parent_category_cfg != false) {
                            $post_params['category'] = $posts_parent_category_cfg;
                        }
                        if (is_array($sub_categories) and !empty($sub_categories) and isset($post_params['related']) and $post_params['related'] != false) {
                            $post_params['category'] = $sub_categories;
                        } elseif ($cfg_page_id != false) {
                            $post_params['parent'] = $cfg_page_id;
                        }
                    } else {
                        $post_params['parent'] = $cfg_page_id;
                        if (($cfg_page_id == PAGE_ID or $cfg_page_id == MAIN_PAGE_ID) and (!isset($post_params['category']) or $post_params['category'] == false) and $cat_from_url != false) {
                            $post_params['category'] = $cat_from_url;
                        }
                    }
                } elseif ($cat_from_url != false) {
                    $post_params['category'] = $cat_from_url;
开发者ID:hyrmedia,项目名称:microweber,代码行数:67,代码来源:Front.php

示例15: widget

    function widget($args, $instance)
    {
        // 输出显示在页面上
        extract($args);
        $id = $instance['id'];
        $before_content = $instance['before_content'];
        $after_content = $instance['after_content'];
        ?>
       
  <?php 
        if (is_category()) {
            ?>
 <?php 
            $cat2 = get_query_var('cat');
            $cat = get_category_root_id($cat2);
            $category = get_category($cat);
            ?>
          <?php 
            if (get_category_children($cat) != "") {
                ?>
      
<div class="widget_left widget_nav_menu">

<div class="widge_hd">
   <span>
  
       <b><?php 
                echo $category->name;
                ?>
</b>
   </span>
  
   </div>

    <ul> <?php 
                if (get_category_children($cat) != "") {
                    wp_list_categories("child_of=" . $cat . "&depth=0&hide_empty=0&title_li=");
                }
                ?>
</ul>
</div>

<?php 
            }
        }
        ?>


 <?php 
        if (is_single()) {
            ?>
 <?php 
            $cat2 = get_query_var('cat');
            $cat = get_category_root_id(the_category_ID(false));
            $category = get_category($cat);
            ?>
          <?php 
            if (get_category_children($cat) != "") {
                ?>
      
<div class="widget_left widget_nav_menu">

<div class="widge_hd">
   <span>
  
       <b><?php 
                echo $category->name;
                ?>
</b><p><?php 
                echo $category->slug;
                ?>
</p>
   </span>
  
   </div>

    <ul> <?php 
                if (get_category_children($cat) != "") {
                    wp_list_categories("child_of=" . $cat . "&depth=0&hide_empty=0&title_li=");
                }
                ?>
</ul>
</div>

<?php 
            }
        }
        ?>
  <?php 
        if (is_page()) {
            ?>
  
    <?php 
            global $wpdb;
            global $post;
            $post_data = get_post($post->ID, ARRAY_A);
            $slug = $post_data['post_name'];
            $name = $slug;
            //page别名
            $parent_id = get_post($post->post_parent, ARRAY_A);
//.........这里部分代码省略.........
开发者ID:yunfanLu,项目名称:wordpress,代码行数:101,代码来源:nav.php


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