本文整理汇总了PHP中get_cat_name函数的典型用法代码示例。如果您正苦于以下问题:PHP get_cat_name函数的具体用法?PHP get_cat_name怎么用?PHP get_cat_name使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_cat_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: category_subnav
/**
* Subnav of current category's topmost parent's children, outputted as widget
* todo - make it an actual widget
*/
function category_subnav()
{
global $post;
if (is_category() || is_single()) {
$categories = get_the_category();
$category = array_shift($categories);
$top_parent = $category->category_parent ? $category->category_parent : $category->cat_ID;
$top_parent_name = get_cat_name($top_parent);
$top_parent_children = wp_list_categories(array('child_of' => $top_parent, 'title_li' => '', 'echo' => 0));
if ($top_parent_children != '<li>No categories</li>') {
?>
<nav class="widget widget-subnav">
<h1 class="widget-title nav-title">'<?php
echo $top_parent_name;
?>
</h1>
<div class="widget-content">
<ul class="menu menu-secondary">
<?php
echo $top_parent_children;
?>
</ul>
</div>
</nav>
<?php
}
}
}
示例2: widget
/** @see WP_Widget::widget */
function widget($args, $instance)
{
extract($args);
$category_id = $instance['category_id'];
echo $before_widget;
?>
<?php
echo "<h2>" . get_cat_name($category_id) . "</h2>";
?>
<ul>
<?php
global $post;
$args = array('category' => $category_id, "numberposts" => -1, "orderby" => "title", "order" => "ASC");
$myposts = get_posts($args);
foreach ($myposts as $post) {
setup_postdata($post);
?>
<li><a href="<?php
the_permalink();
?>
"><?php
the_title();
?>
</a></li>
<?php
}
?>
</ul>
<?php
wp_reset_query();
echo $after_widget;
}
示例3: wolf_breadcrumbs_get_category_links
function wolf_breadcrumbs_get_category_links($page_id = '')
{
if (strlen(trim($page_id)) > 0) {
$cat_name = '';
$cat_url = '';
$cats = get_the_category($page_id);
if (count($cats) > 0) {
$cat = $cats[0];
$cat_id = $cat->cat_ID;
$cat_name = $cat->cat_name;
$cat_url = get_category_link($cat_id);
}
} else {
if (single_tag_title('', false == '')) {
$cat_id = get_query_var('cat');
$cat_name = get_cat_name($cat_id);
$cat_url = get_category_link($cat_id);
} else {
$cat_url = get_tag_link(get_query_var('tag_id'));
$cat_name = single_tag_title('', false);
}
}
$cat_link = '<li>';
$cat_link .= '<a href="' . $cat_url . '" itemprop="url"><span itemprop="title">' . $cat_name . '</span></a>';
if (strlen(trim($page_id)) > 0 && strlen(trim($cat_name)) > 0) {
$cat_link .= '<span class="divider">/</span>';
}
$cat_link .= '</li>';
return $cat_link;
}
示例4: widget
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
$category_id = empty($instance['category_id']) ? 1 : $instance['category_id'];
$use_cat_title = empty($instance['use_cat_title']) ? 0 : $instance['use_cat_title'];
$hide_empty_cats = empty($instance['hide_empty_cats']) ? 0 : $instance['hide_empty_cats'];
$show_post_count = empty($instance['show_post_count']) ? 0 : $instance['show_post_count'];
$title_link = empty($instance['title_link']) ? 0 : $instance['title_link'];
$excluded = empty($instance['excluded']) ? '' : $instance['excluded'];
$sub_subs = empty($instance['sub_subs']) ? 0 : $instance['sub_subs'];
$dropdown = empty($instance['dropdown']) ? 0 : $instance['dropdown'];
$post_is_parent = empty($instance['post_is_parent']) ? 0 : $instance['post_is_parent'];
$dropdown_text = empty($instance['dropdown_text']) ? __('Select Sub-category', 'sub-categories-widget') : $instance['dropdown_text'];
$list_order = empty($instance['list_order']) ? 0 : $instance['list_order'];
if ($post_is_parent) {
$category = get_the_category();
$category_id = $category ? $category[0]->cat_ID : 1;
}
if ($use_cat_title) {
$title = apply_filters('widget_title', get_cat_name($category_id), $instance, $this->id_base);
} else {
$title = apply_filters('widget_title', empty($instance['title']) ? __('Sub Categories', 'sub-categories-widget') : $instance['title'], $instance, $this->id_base);
}
$parent = $sub_subs == 1 ? 'child_of' : 'parent';
$order = $list_order == 1 ? 'DESC' : 'ASC';
$no_sub_text = '<p>' . __('No sub-categories', 'sub-categories-widget') . '</p>';
$subs = wp_list_categories(array($parent => $category_id, 'hide_empty' => $hide_empty_cats, 'show_count' => $show_post_count, 'exclude' => $excluded, 'title_li' => null, 'show_option_none' => '', 'echo' => 0, 'orderby' => 'ID', 'order' => $order));
if ($post_is_parent == 0 || $post_is_parent == 1 && !empty($subs)) {
echo $before_widget;
if ($title_link) {
echo $before_title . '<a href="' . get_category_link($category_id) . '">' . $title . '</a>' . $after_title;
} else {
echo $before_title . $title . $after_title;
}
if ($dropdown == 0) {
if (!empty($subs)) {
echo '<ul>' . $subs . '</ul>';
} else {
echo $no_sub_text;
}
} else {
$subs = wp_dropdown_categories(array('id' => 'sub-cat-' . $this->number, 'show_option_none' => $dropdown_text, $parent => $category_id, 'hide_empty' => $hide_empty_cats, 'show_count' => $show_post_count, 'exclude' => $excluded, 'hide_if_empty' => true, 'echo' => false, 'orderby' => 'ID', 'order' => $order));
if (!empty($subs)) {
echo $subs;
echo '<script type="text/javascript">
/* <![CDATA[ */
var dropdown' . $this->number . ' = document.getElementById("sub-cat-' . $this->number . '");
function onSubCatChange() {
if (dropdown' . $this->number . '.options[dropdown' . $this->number . '.selectedIndex].value > 0) { location.href = "' . get_option('home') . '?cat="+dropdown' . $this->number . '.options[dropdown' . $this->number . '.selectedIndex].value; }
}
dropdown' . $this->number . '.onchange = onSubCatChange;
/* ]]> */
</script>';
} else {
echo $no_sub_text;
}
}
echo $after_widget;
}
}
示例5: my_rest_prepare_post
function my_rest_prepare_post($data, $post, $request)
{
$_data = $data->data;
$thumbnail_id = get_post_thumbnail_id($post->ID);
$thumbnail = wp_get_attachment_image_src($thumbnail_id);
$_data['featured_image_thumbnail_url'] = $thumbnail[0];
$categories = get_categories();
$_data['all_categories'] = $categories;
unset($_data['author']);
unset($_data['comment_status']);
unset($_data['ping_status']);
unset($_data['modified']);
unset($_data['modified_gmt']);
unset($_data['date_gmt']);
unset($_data['guid']);
unset($_data['slug']);
unset($_data['sticky']);
$tags_arr = array();
foreach ($_data['tags'] as $tagID) {
$tag = get_tag($tagID);
// add name field to the array
$tags_arr[] = array('ID' => $tagID, 'name' => $tag->name);
}
$_data['tags'] = $tags_arr;
// assign the new tags array to the JSON field
$categories_arr = array();
foreach ($_data['categories'] as $catID) {
// add name field to the array
$categories_arr[] = array('ID' => $catID, 'name' => get_cat_name($catID));
}
$_data['categories'] = $categories_arr;
// assign the new tags array to the JSON field
$data->data = $_data;
return $data;
}
示例6: Grafik_Functions_Shortcode_TypeCategories
function Grafik_Functions_Shortcode_TypeCategories($atts, $content = '')
{
global $wp_query;
global $GRAFIK_MODE;
$callback_output = '';
$a = shortcode_atts(array('type' => 'post', 'class' => '', 'id' => ''), $atts, 'TypeCategories');
// Construct the query...
$callback_query = new WP_Query(array('post_type' => $a['type'], 'posts_per_page' => -1));
// Loop the query...
$callback_categories = array();
if ($callback_query->have_posts()) {
while ($callback_query->have_posts()) {
$callback_query->the_post();
$callback_post = get_post();
$callback_postcats = wp_get_post_categories($callback_post->ID);
foreach ($callback_postcats as $key => $val) {
$callback_categories[$val]++;
}
}
wp_reset_postdata();
} else {
$callback_output .= '<span class="empty-message">' . $a['empty_msg'] . '</span>';
}
// Loop the results...
foreach ($callback_categories as $key => $val) {
$callback_output .= '<li class="ge-typecategories-item">' . '<a href="' . esc_url(get_category_link($key)) . '" class="ge-typecategories-link">' . '<span class="ge-typecategories-name">' . get_cat_name($key) . '</span>' . '<span class="ge-typecategories-count">' . $val . '</span>' . '</a>' . '</li>';
}
if (empty($callback_output)) {
return '';
}
return '<div class="ge-typecategories-container' . (empty($a['class']) ? null : ' ' . $a['class']) . '"' . (empty($a['id']) ? null : ' id="' . $a['id'] . '"') . '>' . '<div class="ge-typecategories-content">' . $content . '</div>' . '<ul class="ge-typecategories-list">' . $callback_output . '</ul>' . '</div>';
}
示例7: form
function form($instance)
{
$default = array('title' => 'Widget Demo', 'number_post' => '5', 'current_category' => '');
// Gộp các giá trị của $default vào $instance để nó trở thành giá trị mặc định
$instance = wp_parse_args((array) $instance, $default);
// Gán giá trị ($instance['title'] cho $title (khởi tạo biến $title))
$title = esc_attr($instance['title']);
$number_post = esc_attr($instance['number_post']);
// Get title
echo "<p>Title:</p>";
echo "<p><input type=\"text\" name=\"" . $this->get_field_name('title') . "\" value=\"" . $title . "\" /></p>";
// Select category
$all_categories = get_all_category_ids();
echo "<p>Category:</p>";
echo "<p><select id=\"" . $this->get_field_id('current_category') . "\" name=\"" . $this->get_field_name('current_category') . "\" >";
foreach ($all_categories as $category) {
if ($category == $instance['current_category']) {
echo "<option value=\"" . $category . "\" selected=\"selected\">" . get_cat_name($category) . "</option>";
} else {
echo "<option value=\"" . $category . "\">" . get_cat_name($category) . "</option>";
}
}
echo "</select></p>";
// Get count
echo "<p>Show number posts:</p>";
echo "<p><input type=\"text\" name=\"" . $this->get_field_name('number_post') . "\" value=\"" . $number_post . "\" /></p>";
}
示例8: widget
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
* @since 1.0.0
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
function widget($args, $instance)
{
// Extract args
extract($args, EXTR_SKIP);
$category_id = empty($instance['category_id']) ? 1 : $instance['category_id'];
$post_num = empty($instance['post_num']) ? 5 : $instance['post_num'];
$use_cat_title = empty($instance['use_cat_title']) ? 0 : $instance['use_cat_title'];
$title_link = empty($instance['title_link']) ? 0 : $instance['title_link'];
if ($use_cat_title) {
$title = apply_filters('widget_title', get_cat_name($category_id), $instance, $this->id_base);
} else {
$title = apply_filters('widget_title', empty($instance['title']) ? __('Listen to Broadcast', 'wpsp') : $instance['title'], $instance, $this->id_base);
}
echo $before_widget;
if ($title_link) {
echo $before_title . '<a href="' . get_category_link($category_id) . '">' . $title . '</a>' . $after_title;
} else {
echo $before_title . $title . $after_title;
}
global $post;
$args = array();
$defaults = array('post_type' => 'post', 'posts_per_page' => (int) $post_num, 'post__not_in' => array($post->ID), 'tax_query' => array('relation' => 'AND', array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-audio')), array('taxonomy' => 'category', 'field' => 'term_id', 'terms' => array($category_id))));
$args = wp_parse_args($args, $defaults);
extract($args);
$custom_query = new WP_Query($args);
if ($custom_query->have_posts()) {
while ($custom_query->have_posts()) {
$custom_query->the_post();
get_template_part('partials/content', 'radio');
}
wp_reset_postdata();
}
echo $after_widget;
return $instance;
}
示例9: get_tab_posts
/**
* Generates the tabs for posts
*
* @param array $content
* @return array
*/
public static function get_tab_posts($content)
{
// Set up date filter
self::date_range($content['from_date'], $content['to_date']);
// Set up results array
$results = array('title' => '{Needs to be changed}', 'tabs' => array());
// Get posts
foreach ($content['categories'] as $cat_id) {
// If parent skip
if (self::is_parent($cat_id)) {
continue;
}
// Get posts
$query_results = query_posts(array('cat' => $cat_id, 'orderby' => 'date', 'order' => 'desc', 'posts_per_page' => $content['posts_number'] === 'All' ? self::$result_limit[$content['layout']] : 1));
// Remove filter
wp_reset_query();
remove_filter('posts_where', array('Posts_Widget', 'date_filter'));
// Get custom fields
$cat_name = get_cat_name($cat_id);
$results['tabs'][$cat_name] = array();
foreach ($query_results as $result) {
$result->fields = (object) get_fields($result->ID);
$results['tabs'][$cat_name][] = $result;
}
}
return $results;
}
示例10: widget
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
* @since 1.0.0
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
function widget($args, $instance)
{
// Extract args
extract($args, EXTR_SKIP);
$category_id = empty($instance['category_id']) ? 1 : $instance['category_id'];
$use_cat_title = empty($instance['use_cat_title']) ? 0 : $instance['use_cat_title'];
$hide_empty_cats = empty($instance['hide_empty_cats']) ? 0 : $instance['hide_empty_cats'];
$show_post_count = empty($instance['show_post_count']) ? 0 : $instance['show_post_count'];
$title_link = empty($instance['title_link']) ? 0 : $instance['title_link'];
if ($use_cat_title) {
$title = apply_filters('widget_title', get_cat_name($category_id), $instance, $this->id_base);
} else {
$title = apply_filters('widget_title', empty($instance['title']) ? __('Sub Categories', 'wpsp') : $instance['title'], $instance, $this->id_base);
}
$no_sub_text = '<p>' . __('No sub-categories', 'wpsp') . '</p>';
$subs = wp_list_categories(array('child_of' => $category_id, 'hide_empty' => $hide_empty_cats, 'show_count' => $show_post_count, 'title_li' => null, 'show_option_none' => '', 'echo' => 0));
echo $before_widget;
if ($title_link) {
echo $before_title . '<a href="' . get_category_link($category_id) . '">' . $title . '</a>' . $after_title;
} else {
echo $before_title . $title . $after_title;
}
if (!empty($subs)) {
echo '<ul>' . $subs . '</ul>';
} else {
echo $no_sub_text;
}
echo $after_widget;
return $instance;
}
示例11: widget
function widget($args, $advcat_instance)
{
extract($args);
$title = apply_filters('widget_title', empty($advcat_instance['title']) ? 'Categories' : $advcat_instance['title'], $advcat_instance, $this->id_base);
$numCols = isset($advcat_instance['numCols']) ? $advcat_instance['numCols'] : false;
if (!($cats = $advcat_instance["cats"])) {
$cats = '';
}
$advcat_widget = null;
$advcat_widget = new WP_Query($advcat_args);
echo $before_widget;
echo '<div id="adv-recent-cats" class="widget-inner">';
// Widget title
if ($advcat_instance["title"] != '') {
echo $before_title;
echo $advcat_instance["title"];
echo $after_title;
}
// Post list in widget
if ($cats != '') {
echo "<ul class='row'>\n";
foreach ($cats as $cat) {
if ($numCols) {
echo '<li class="advwidget-item col-xs-6">';
} else {
echo '<li class="advwidget-item col-xs-12">';
}
// Get the ID of a given category
$category_id = $cat;
// Get the URL of this category
$category_link = get_category_link($category_id);
// Get te Name of this category
$category_name = get_cat_name($category_id);
?>
<!-- Print a link to this category -->
<a href="<?php
echo esc_url($category_link);
?>
"><?php
echo $category_name;
?>
</a>
</li>
<?php
}
//end for each
?>
<?php
//endif;
?>
<?php
wp_reset_query();
echo "</ul>\n";
}
//end if array not empty
echo '</div>';
echo $after_widget;
}
示例12: widget
function widget($args, $instance)
{
// outputs the content of the widget
extract($args);
$this->category_JS();
$title = apply_filters('widget_title', $instance['title']);
if ($args['id'] == 'sidebar-footerwidgetarea') {
$footer_width = 'span' . circleflip_calculate_widget_width();
} else {
$footer_width = '';
}
?>
<li class="categoryCount widget customWidget <?php
echo esc_attr($footer_width);
?>
">
<?php
if ($title != null) {
?>
<div class="widgetDot"></div>
<h3 class="widgetTitle grid2"><?php
echo esc_html($title);
?>
</h3>
<?php
}
$category_ids = get_terms('category', array('fields' => 'ids', 'get' => 'all'));
foreach ($category_ids as $cat_id) {
$cat_name = get_cat_name($cat_id);
if ($cat_name != 'Uncategorized') {
?>
<p class="widgetcategory_with_count textwidget">
<span class="left"><a href="<?php
echo esc_url(get_category_link($cat_id));
?>
"><?php
echo esc_html($cat_name);
?>
</a></span>
<?php
$postsInCat = get_term_by('name', $cat_name, 'category');
$postsInCat = $postsInCat->count;
?>
<span class="right"><?php
echo '(' . $postsInCat . ')';
?>
</span>
</p>
<?php
}
}
?>
</li>
<?php
}
示例13: get_video_category_link
public static function get_video_category_link()
{
$category_ids = get_all_category_ids();
foreach ($category_ids as $cat_id) {
if (!strcmp(get_cat_name($cat_id), "video")) {
echo get_category_link($cat_id);
}
}
}
示例14: list_type
function list_type($category, $type)
{
echo "<h1>" . get_cat_name(get_category_by_slug($category)->cat_ID) . ":</h1>\n";
$files = new WP_Query(array('category_name' => $category, 'post_type' => $type, 'order' => 'ASC', 'orderby' => 'title'));
while ($files->have_posts()) {
$files->the_post();
echo "<p>" . the_post_thumbnail() . "<strong>" . get_the_title() . "</strong>: " . get_the_content() . "</p>\n";
}
}
示例15: constantTest
protected function constantTest()
{
$post_id_1 = 0;
$time = microtime(true);
for ($i = 0; $i < $this->runNumber; $i++) {
get_cat_name(1);
}
$time = microtime(true) - $time;
$this->enterResult($time);
}