本文整理汇总了PHP中wp_count_terms函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_count_terms函数的具体用法?PHP wp_count_terms怎么用?PHP wp_count_terms使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_count_terms函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: custom_dashboard_display_stats
function custom_dashboard_display_stats($widget)
{
?>
<p>Les principales valeurs statistiques de l'intégration BF QUOTES</p>
<div class="inside">
<?php
// global $wpdb;
/*
=== JUST AS REMINDER
post_type => product_for_sale
taxonomy => product_for_sale_genre
taxonomy => product_for_sale_author
taxonomy => product_for_sale_kw
*/
$num_posts_bf_quotes_manager = wp_count_posts('bf_quotes_manager');
// Main figures for product_for_sale
$num_product_for_sale = $num_posts_product_for_sale->publish;
// nb for Author(s)
$num_cats_bf_quotes_manager_author = wp_count_terms('bf_quotes_manager_author');
// nb for Flavor(s)
$num_tags_bf_quotes_manager_flavor = wp_count_terms('bf_quotes_manager_flavor');
?>
<h4><strong>Les chiffres-clés</strong></h4>
<ul>
<li>Nombre d' Auteur(s) : <b><?php
echo '' . $num_cats_bf_quotes_manager_author . '';
?>
</b></li>
<li>Nombre de Saveur(s) : <b><?php
echo '' . $num_tags_bf_quotes_manager_flavor . '';
?>
</b></li>
</ul>
<h4><strong>Les dernières citations enregistrées</strong></h4>
<?php
/* LAST POSTS */
$args = array('offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'numberposts' => '3', 'post_status' => 'publish', 'post_type' => 'bf_quotes_manager');
$recent_posts = wp_get_recent_posts($args);
/* debug only */
// print_r($recent_posts);
foreach ($recent_posts as $recent) {
setup_postdata(get_post($recent['ID']));
// Output
echo '<ul><li><a class="rsswidget" href="' . get_permalink($recent['ID']) . '" title="' . esc_attr(get_the_title($recent['ID'])) . '">' . get_the_title($recent['ID']) . '</a> <span class="rss-date">' . get_the_time('j F Y', $recent['ID']) . '</span><div class="rssSummary">' . $recent['post_excerpt'] . '</div></li>';
}
// EOL
wp_reset_postdata();
?>
</div>
<?php
}
示例2: ajax_local_tags
/**
* Display a javascript collection for autocompletion script !
*
* @return void
* @author Amaury Balmer
*/
public static function ajax_local_tags()
{
status_header(200);
// Send good header HTTP
header("Content-Type: application/json; charset=" . get_bloginfo('charset'));
$taxonomy = 'post_tag';
if (isset($_REQUEST['taxonomy']) && taxonomy_exists($_REQUEST['taxonomy'])) {
$taxonomy = $_REQUEST['taxonomy'];
}
if ((int) wp_count_terms($taxonomy, 'ignore_empty=false') == 0) {
// No tags to suggest
json_encode(array());
exit;
}
// Prepare search
$search = isset($_GET['term']) ? trim(stripslashes($_GET['term'])) : '';
// Get all terms, or filter with search
$terms = SimpleTags_Admin::getTermsForAjax($taxonomy, $search);
if (empty($terms) || $terms == false) {
json_encode(array());
exit;
}
// Format terms
$results = array();
foreach ((array) $terms as $term) {
$term->name = stripslashes($term->name);
$term->name = str_replace(array("\r\n", "\r", "\n"), '', $term->name);
$results[] = array('id' => $term->term_id, 'label' => $term->name, 'value' => $term->name);
}
echo json_encode($results);
exit;
}
示例3: show_tag_filter
/**
* Show the tag cloud
*/
public function show_tag_filter($shortcode_atts)
{
if (isset($shortcode_atts['show_tags']) && ($shortcode_atts['show_tags'] === false || (string) $shortcode_atts['show_tags'] == 'false')) {
return;
}
if (wp_count_terms('job_listing_tag') == 0) {
return;
}
wp_register_script('wp-job-manager-ajax-tag-filters', JOB_MANAGER_TAGS_PLUGIN_URL . '/assets/js/tag-filter.js', array('jquery'), '1.0', true);
$args_data = array('orderby' => 'count', 'order' => 'DESC');
$jobs_tags_data = get_terms('job_listing_tag', $args_data);
$queried_object = get_queried_object();
foreach ($jobs_tags_data as $key => $jobs_tag_data) {
if ($jobs_tag_data->count > 1) {
$jobs_txt = 'jobs';
$font_size = 2;
} else {
$jobs_txt = 'job';
$font_size = 1;
}
//if($queried_object->term_id == $jobs_tag_data->term_id){ $active_class = 'activee'; }
$anchor_data[] = '<a href="#" id="test_' . $key . '" "class="tag-link-' . $jobs_tag_data->term_id . ' ' . $active_class . ' show_bg_tag" title="' . $jobs_tag_data->count . ' ' . $jobs_txt . '" style="font-size: ' . $font_size . 'em;">' . $jobs_tag_data->name . '</a>';
}
$anchor_tag_data = array('anchor_tag_data' => $anchor_data);
//anchor_tag_data
wp_localize_script('wp-job-manager-ajax-tag-filters', 'anchor_tag_data_object', $anchor_tag_data);
wp_enqueue_script('wp-job-manager-ajax-tag-filters', JOB_MANAGER_TAGS_PLUGIN_URL . '/assets/js/tag-filter.js', array('jquery'), '1.0', true);
echo '<div class="filter_wide filter_by_tag">' . __('Filter by tag:', 'wp-job-manager-tags') . ' <span class="filter_by_tag_cloud"></span></div>';
}
示例4: widget_content
/**
* Generate the content of the widget.
*
* @param array args The array of form elements
* @param array instance The current instance of the widget
*/
public function widget_content($args, $instance)
{
extract($args, EXTR_SKIP);
extract($instance);
$count = (array) wp_count_posts('movie');
$count = array('movies' => $count['publish'], 'imported' => $count['import-draft'], 'queued' => $count['import-queued'], 'draft' => $count['draft'], 'total' => 0);
$count['total'] = array_sum($count);
$count['collections'] = wp_count_terms('collection');
$count['genres'] = wp_count_terms('genre');
$count['actors'] = wp_count_terms('actor');
$count = array_map('intval', $count);
extract($count);
$links = array();
$links['%total%'] = sprintf('<a href="%s">%s</a>', get_post_type_archive_link('movie'), sprintf(_n('<strong>1</strong> movie', '<strong>%d</strong> movies', $movies, 'wpmovielibrary'), $movies));
$links['%collections%'] = WPMOLY_Utils::get_taxonomy_permalink('collection', sprintf(_n('<strong>1</strong> collection', '<strong>%d</strong> collections', $collections, 'wpmovielibrary'), $collections));
$links['%genres%'] = WPMOLY_Utils::get_taxonomy_permalink('genre', sprintf(_n('<strong>1</strong> genre', '<strong>%d</strong> genres', $genres, 'wpmovielibrary'), $genres));
$links['%actors%'] = WPMOLY_Utils::get_taxonomy_permalink('actor', sprintf(_n('<strong>1</strong> actor', '<strong>%d</strong> actors', $actors, 'wpmovielibrary'), $actors));
$title = $before_title . apply_filters('widget_title', $title) . $after_title;
$description = esc_attr($description);
$format = wpautop(wp_kses($format, array('ul', 'ol', 'li', 'p', 'span', 'em', 'i', 'p', 'strong', 'b', 'br')));
$content = str_replace(array_keys($links), array_values($links), $format);
$style = 'wpmoly-widget wpmoly-statistics';
$attributes = array('content' => $content, 'description' => $description, 'style' => $style);
$html = WPMovieLibrary::render_template('statistics-widget/statistics.php', $attributes, $require = 'always');
return $before_widget . $title . $html . $after_widget;
}
示例5: prepare_items
function prepare_items() {
global $taxonomy;
$tags_per_page = $this->get_items_per_page( 'edit_' . $taxonomy . '_per_page' );
if ( 'post_tag' == $taxonomy ) {
$tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
$tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
} elseif ( 'category' == $taxonomy ) {
$tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter
}
$search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : '';
$args = array(
'search' => $search,
'page' => $this->get_pagenum(),
'number' => $tags_per_page,
);
if ( !empty( $_REQUEST['orderby'] ) )
$args['orderby'] = trim( stripslashes( $_REQUEST['orderby'] ) );
if ( !empty( $_REQUEST['order'] ) )
$args['order'] = trim( stripslashes( $_REQUEST['order'] ) );
$this->callback_args = $args;
$this->set_pagination_args( array(
'total_items' => wp_count_terms( $taxonomy, compact( 'search' ) ),
'per_page' => $tags_per_page,
) );
}
示例6: ajaxLocalTags
/**
* Display a javascript collection for autocompletion script !
*
* @return void
* @author Amaury Balmer
*/
function ajaxLocalTags()
{
status_header(200);
// Send good header HTTP
header("Content-Type: text/plain; charset=" . get_bloginfo('charset'));
$taxonomy = 'post_tag';
if (isset($_REQUEST['taxonomy']) && taxonomy_exists($_REQUEST['taxonomy'])) {
$taxonomy = $_REQUEST['taxonomy'];
}
if ((int) wp_count_terms($taxonomy, 'ignore_empty=false') == 0) {
// No tags to suggest
exit;
}
// Prepare search
$search = isset($_GET['q']) ? trim(stripslashes($_GET['q'])) : '';
// Get all terms, or filter with search
$terms = $this->getTermsForAjax($taxonomy, $search);
if (empty($terms) || $terms == false) {
exit;
}
// Format terms
foreach ((array) $terms as $term) {
$term->name = stripslashes($term->name);
$term->name = str_replace(array("\r\n", "\r", "\n"), '', $term->name);
echo "{$term->term_id}|{$term->name}\n";
}
exit;
}
示例7: wpmp_msma_overview
function wpmp_msma_overview($menu)
{
$base = get_option('home');
$post_count = wp_count_posts('post');
$page_count = wp_count_posts('page');
print "<p>";
printf(__ngettext("You have one post", "You have %d posts", $c = 0 + $post_count->publish, 'wpmp'), $c);
print ' ';
printf(__ngettext("and one page", "and %d pages", $c = 0 + $page_count->publish, 'wpmp'), $c);
print ' ' . __("contained within", 'wpmp') . ' ';
printf(__ngettext("one category", "%d categories", $c = 0 + wp_count_terms('category'), 'wpmp'), $c);
print ' ' . __("and", 'wpmp') . ' ';
printf(__ngettext("one tag", "%d tags", $c = 0 + wp_count_terms('post_tag'), 'wpmp'), $c);
print ".</p>";
global $wpdb;
$comments = $wpdb->get_results("SELECT count(*) as cnt FROM {$wpdb->comments} WHERE comment_approved='0'");
$comment_count = $comments[0];
printf("<p>" . __ngettext("You have one comment to moderate", "You have %d comments to moderate", $c = 0 + $comment_count->cnt, 'wpmp') . ".</p>", $c);
print "<h3>" . __("Select an admin page:", 'wpmp') . "</h3>";
print "<p><ul>";
$not_first = false;
foreach ($menu as $name => $link) {
if ($name[0] != '_' && $not_first) {
if (substr($link, 0, 7) != "http://" && substr($link, 0, 8) != "https://") {
$link = $base . $link;
}
print "<li><a href='{$link}'>" . __("{$name}", 'wpmp') . "</a>";
}
$not_first = true;
}
print "</ul></p>";
print "<p>" . sprintf(__("...or <a%s>return to the site</a>", 'wpmp'), " href='{$base}/'") . "</p>";
print "<p>" . __("A subset of the full WordPress administration is available through this mobile interface.", 'wpmp') . "</p>";
}
示例8: test_wp_insert_delete_term
public function test_wp_insert_delete_term()
{
$taxonomy = 'wptests_tax';
register_taxonomy($taxonomy, 'post');
// a new unused term
$term = rand_str();
$this->assertNull(term_exists($term));
$initial_count = wp_count_terms($taxonomy);
$t = wp_insert_term($term, $taxonomy);
$this->assertInternalType('array', $t);
$this->assertNotWPError($t);
$this->assertTrue($t['term_id'] > 0);
$this->assertTrue($t['term_taxonomy_id'] > 0);
$this->assertEquals($initial_count + 1, wp_count_terms($taxonomy));
// make sure the term exists
$this->assertTrue(term_exists($term) > 0);
$this->assertTrue(term_exists($t['term_id']) > 0);
// now delete it
add_filter('delete_term', array($this, 'deleted_term_cb'), 10, 5);
$this->assertTrue(wp_delete_term($t['term_id'], $taxonomy));
remove_filter('delete_term', array($this, 'deleted_term_cb'), 10, 5);
$this->assertNull(term_exists($term));
$this->assertNull(term_exists($t['term_id']));
$this->assertEquals($initial_count, wp_count_terms($taxonomy));
}
示例9: seventeen_right_now_content_table_end
/**
* Add Custom Post Types and Taxonomies to "At a Glance" Dashboard Widget
*
* Ref Link: http://wpsnipp.com/index.php/functions-php/include-custom-post-types-in-right-now-admin-dashboard-widget/
* http://wordpress.org/support/topic/dashboard-at-a-glance-custom-post-types
* http://halfelf.org/2012/my-custom-posttypes-live-in-mu/
*/
function seventeen_right_now_content_table_end()
{
$args = array('public' => true, '_builtin' => false);
$output = 'object';
$operator = 'and';
$post_types = get_post_types($args, $output, $operator);
foreach ($post_types as $post_type) {
$num_posts = wp_count_posts($post_type->name);
$num = number_format_i18n($num_posts->publish);
$text = _n($post_type->labels->name, $post_type->labels->name, intval($num_posts->publish));
if (current_user_can('edit_posts')) {
$cpt_name = $post_type->name;
}
echo '<li class="post-count ' . $post_type->name . '-count"><tr><a href="edit.php?post_type=' . $cpt_name . '"><td class="first b b-' . $post_type->name . '"></td>' . $num . ' <td class="t ' . $post_type->name . '">' . $text . '</td></a></tr></li>';
}
$taxonomies = get_taxonomies($args, $output, $operator);
foreach ($taxonomies as $taxonomy) {
$num_terms = wp_count_terms($taxonomy->name);
$num = number_format_i18n($num_terms);
$text = _n($taxonomy->labels->name, $taxonomy->labels->name, intval($num_terms));
if (current_user_can('manage_categories')) {
$cpt_tax = $taxonomy->name;
}
echo '<li class="taxonomy-count ' . $taxonomy->name . '-count"><tr><a href="edit-tags.php?taxonomy=' . $cpt_tax . '"><td class="first b b-' . $taxonomy->name . '"></td>' . $num . ' <td class="t ' . $taxonomy->name . '">' . $text . '</td></a></tr></li>';
}
}
示例10: wph_right_now_content_table_end
function wph_right_now_content_table_end()
{
$args = array('public' => true, '_builtin' => false);
$output = 'object';
$operator = 'and';
$post_types = get_post_types($args, $output, $operator);
foreach ($post_types as $post_type) {
$num_posts = wp_count_posts($post_type->name);
$num = number_format_i18n($num_posts->publish);
$text = _n($post_type->labels->singular_name, $post_type->labels->name, intval($num_posts->publish));
if (current_user_can('edit_posts')) {
$num = "<a href='edit.php?post_type={$post_type->name}'>{$num}</a>";
$text = "<a href='edit.php?post_type={$post_type->name}'>{$text}</a>";
}
echo '<tr><td class="first num b b-' . $post_type->name . '">' . $num . '</td>';
echo '<td class="text t ' . $post_type->name . '">' . $text . '</td></tr>';
}
$taxonomies = get_taxonomies($args, $output, $operator);
foreach ($taxonomies as $taxonomy) {
$num_terms = wp_count_terms($taxonomy->name);
$num = number_format_i18n($num_terms);
$text = _n($taxonomy->labels->singular_name, $taxonomy->labels->name, intval($num_terms));
if (current_user_can('manage_categories')) {
$num = "<a href='edit-tags.php?taxonomy={$taxonomy->name}'>{$num}</a>";
$text = "<a href='edit-tags.php?taxonomy={$taxonomy->name}'>{$text}</a>";
}
echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>';
echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>';
}
}
示例11: ajax_click_tags
/**
* Display a span list for click tags
*
* @return void
* @author Amaury Balmer
*/
public static function ajax_click_tags()
{
status_header(200);
// Send good header HTTP
header("Content-Type: text/html; charset=" . get_bloginfo('charset'));
if ((int) wp_count_terms('post_tag', 'ignore_empty=false') == 0) {
// No tags to suggest
echo '<p>' . __('No terms in your WordPress database.', 'simpletags') . '</p>';
exit;
}
// Prepare search
$search = isset($_GET['q']) ? trim(stripslashes($_GET['q'])) : '';
$post_id = isset($_GET['post_id']) ? intval($_GET['post_id']) : 0;
// Order tags before selection (count-asc/count-desc/name-asc/name-desc/random)
$order_click_tags = strtolower(SimpleTags_Plugin::get_option_value('order_click_tags'));
$order_by = $order = '';
switch ($order_click_tags) {
case 'count-asc':
$order_by = 'tt.count';
$order = 'ASC';
break;
case 'random':
$order_by = 'RAND()';
$order = '';
break;
case 'count-desc':
$order_by = 'tt.count';
$order = 'DESC';
break;
case 'name-desc':
$order_by = 't.name';
$order = 'DESC';
break;
default:
// name-asc
$order_by = 't.name';
$order = 'ASC';
break;
}
// Get all terms, or filter with search
$terms = SimpleTags_Admin::getTermsForAjax('post_tag', $search, $order_by, $order);
if (empty($terms) || $terms == false) {
echo '<p>' . __('No results from your WordPress database.', 'simpletags') . '</p>';
exit;
}
// Get terms for current post
$post_terms = array();
if ($post_id > 0) {
$post_terms = wp_get_post_terms($post_id, 'post_tag', array('fields' => 'ids'));
}
foreach ((array) $terms as $term) {
$class_current = in_array($term->term_id, $post_terms) ? 'used_term' : '';
echo '<span class="local ' . $class_current . '">' . esc_html(stripslashes($term->name)) . '</span>' . "\n";
}
echo '<div class="clear"></div>';
exit;
}
示例12: getTotalPages
public function getTotalPages()
{
if (isset($this->options["id"])) {
return 1;
}
$total = wp_count_terms($this->taxonomy);
$per_page = $this->options["per_page"];
return round($total / $per_page, 0, PHP_ROUND_HALF_UP);
}
示例13: _load_default_entries
function _load_default_entries()
{
if (wp_count_terms($this->_var) > 0) {
return;
}
foreach ((array) $this->_default_terms as $term => $args) {
wp_insert_term($term, $this->_var, $args);
}
}
示例14: widget
function widget($args, $instance)
{
extract($args);
$title = apply_filters('widget_title', $instance['title']);
if (!empty($instance['title'])) {
$title = $instance['title'];
} else {
$title = 'بىكەت ئۇچۇرى';
}
$title = apply_filters('widget_title', $title, $instance, $this->id_base);
$date = $instance['date'];
echo $before_widget;
echo $before_title . $title . $after_title;
echo '<ul class="blog_info">';
if ($title) {
}
?>
<li>يازما سانى:<?php
$count_posts = wp_count_posts();
echo $published_posts = $count_posts->publish;
?>
</li>
<li> بەت سانى:<?php
$count_pages = wp_count_posts('page');
echo $page_posts = $count_pages->publish;
?>
</li>
<li>ئومۇمىي باھا:<?php
$count_comments = get_comment_count();
echo $count_comments['approved'];
?>
</li>
<li>ئومۇمىي خەتكۈش:<?php
echo $count_tags = wp_count_terms('post_tag');
?>
</li>
<?php
if (!empty($instance['date'])) {
?>
<li>قۇرۇلغان ۋاقىت:<?php
echo $date;
?>
</li>
<li>بىكەت يېشى:<?php
echo floor((time() - strtotime("{$date}")) / 86400);
?>
كۈن</li>
<?php
}
?>
</ul>
<?php
echo $after_widget;
}
示例15: init_fields
/**
* init_fields function.
*
* @access public
* @return void
*/
public static function init_fields()
{
if (self::$fields) {
return;
}
self::$fields = apply_filters('submit_job_form_fields', array('job' => array('job_title' => array('label' => __('Job title', 'wp-job-manager'), 'type' => 'text', 'required' => true, 'placeholder' => '', 'priority' => 1), 'job_location' => array('label' => __('Job location', 'wp-job-manager'), 'description' => __('Leave this blank if the job can be done from anywhere (i.e. telecommuting)', 'wp-job-manager'), 'type' => 'text', 'required' => false, 'placeholder' => __('e.g. "London, UK", "New York", "Houston, TX"', 'wp-job-manager'), 'priority' => 2), 'job_type' => array('label' => __('Job type', 'wp-job-manager'), 'type' => 'select', 'required' => true, 'options' => self::job_types(), 'placeholder' => '', 'priority' => 3), 'job_category' => array('label' => __('Job category', 'wp-job-manager'), 'type' => 'select', 'required' => true, 'options' => self::job_categories(), 'placeholder' => '', 'priority' => 4), 'job_description' => array('label' => __('Description', 'wp-job-manager'), 'type' => 'wp-editor', 'required' => true, 'placeholder' => '', 'priority' => 5), 'application' => array('label' => __('Application email/URL', 'wp-job-manager'), 'type' => 'text', 'required' => true, 'placeholder' => __('Enter an email address or website URL', 'wp-job-manager'), 'priority' => 6)), 'company' => array('company_name' => array('label' => __('Company name', 'wp-job-manager'), 'type' => 'text', 'required' => true, 'placeholder' => __('Enter the name of the company', 'wp-job-manager'), 'priority' => 1), 'company_website' => array('label' => __('Website', 'wp-job-manager'), 'type' => 'text', 'required' => false, 'placeholder' => __('http://', 'wp-job-manager'), 'priority' => 2), 'company_tagline' => array('label' => __('Tagline', 'wp-job-manager'), 'type' => 'text', 'required' => false, 'placeholder' => __('Briefly describe your company', 'wp-job-manager'), 'maxlength' => 64, 'priority' => 3), 'company_twitter' => array('label' => __('Twitter username', 'wp-job-manager'), 'type' => 'text', 'required' => false, 'placeholder' => __('@yourcompany', 'wp-job-manager'), 'priority' => 4), 'company_logo' => array('label' => __('Logo', 'wp-job-manager'), 'type' => 'file', 'required' => false, 'placeholder' => '', 'priority' => 5))));
if (!get_option('job_manager_enable_categories') || wp_count_terms('job_listing_category') == 0) {
unset(self::$fields['job']['job_category']);
}
}