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

PHP get_the_terms函数代码示例

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

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



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

示例1: new_question

 /**
  * Add activity after inserting new question.
  * @param  integer $question_id Post ID.
  */
 public function new_question($question_id)
 {
     $question = get_post($question_id);
     $question_title = '<a class="ap-q-link" href="' . wp_get_shortlink($question_id) . '">' . get_the_title($question_id) . '</a>';
     $txo_type = '';
     if (taxonomy_exists('question_category')) {
         $txo_type = 'question_category';
     }
     if (taxonomy_exists('question_tag')) {
         $txo_type = 'question_tag';
     }
     $term_ids = array();
     if (!empty($txo_type)) {
         $terms = get_the_terms($question_id, $txo_type);
         if ($terms) {
             foreach ($terms as $t) {
                 $term_ids[] = $t->term_id;
             }
             $term_ids = implode(',', $term_ids);
         }
     }
     $activity_arr = array('user_id' => $question->post_author, 'type' => 'new_question', 'question_id' => $question_id, 'permalink' => wp_get_shortlink($question_id), 'content' => sprintf(__('%s asked question %s', 'anspress-question-answer'), ap_activity_user_name($question->post_author), $question_title), 'term_ids' => $term_ids);
     $activity_id = ap_new_activity($activity_arr);
     // Add question activity meta.
     update_post_meta($question_id, '__ap_activity', array('type' => 'new_question', 'user_id' => $question->post_author, 'date' => current_time('mysql')));
     $this->check_mentions($question_id, $question->post_content, $question_title, $question->post_author, __('question', 'anspress-question-answer'));
     // Notify users.
     // ap_new_notification($activity_id, $question->post_author);
 }
开发者ID:erashu212,项目名称:anspress,代码行数:33,代码来源:activity-hooks.php


示例2: manage_events_columns

function manage_events_columns($name)
{
    global $post, $wp_query, $default_date;
    switch ($name) {
        case 'events_cat':
            $terms = get_the_terms($post->ID, 'events_cat');
            //If the terms array contains items... (dupe of core)
            if (!empty($terms)) {
                //Loop through terms
                foreach ($terms as $term) {
                    //Add tax name & link to an array
                    $post_terms[] = esc_html(sanitize_term_field('name', $term->name, $term->term_id, '', 'edit'));
                }
                //Spit out the array as CSV
                echo implode(', ', $post_terms);
            } else {
                //Text to show if no terms attached for post & tax
                echo '<em>No terms</em>';
            }
            break;
        case 'eventdate':
            if (get_post_meta(get_the_ID(), 'event_date', true) != '') {
                echo date($default_date, get_post_meta(get_the_ID(), 'event_date', true));
            }
            //echo get_post_meta( get_the_ID(),'event_date',TRUE );
            break;
        case 'location':
            echo get_post_meta(get_the_ID(), 'event_location', TRUE);
            break;
        case 'venue':
            echo get_post_meta(get_the_ID(), 'event_venue', TRUE);
            break;
    }
}
开发者ID:pryspry,项目名称:MusicPlay,代码行数:34,代码来源:events.php


示例3: lazyLoadProperty

 protected function lazyLoadProperty($key)
 {
     switch ($key) {
         case 'page_template':
             return $this->page_template = get_post_meta($this->ID, '_wp_page_template', true);
         case 'post_category':
             if (is_object_in_taxonomy($this->post_type, 'category')) {
                 $terms = get_the_terms($this->ID, 'category');
                 if (empty($terms)) {
                     $this->post_category = array();
                 } else {
                     $this->post_category = wp_list_pluck($terms, 'term_id');
                 }
             }
             return $this->post_category;
         case 'tags_input':
             if (is_object_in_taxonomy($this->post_type, 'post_tag')) {
                 $terms = get_the_terms($this->ID, 'post_tag');
                 if (empty($terms)) {
                     $this->tags_input = array();
                 } else {
                     $this->tags_input = wp_list_pluck($terms, 'name');
                 }
             }
             return $this->tags_input;
         case 'ancestors':
             return $this->ancestors = get_post_ancestors($this);
         default:
             break;
     }
     throw new \InvalidArgumentException("Invalid lazy-loaded property '{$key}'");
 }
开发者ID:wells5609,项目名称:wp-app,代码行数:32,代码来源:Post.php


示例4: todays_movies

function todays_movies()
{
    $todays_movies = array();
    $args = array('post_type' => array('film'), 'posts_per_page' => -1);
    $query = new WP_Query($args);
    if ($query->have_posts()) {
        while ($query->have_posts()) {
            $query->the_post();
            $schedule = get_post_meta(get_the_ID(), 'film_horaire', true);
            $duration = get_post_meta(get_the_ID(), 'film_duration', true);
            //the_title();
            //piklist::pre($schedule);
            foreach ($schedule as $key) {
                //echo $key['film_date'] . '<br>';
                $movie_iso_date = DateTime::createFromFormat('d/m/Y', $key['film_date'])->format('Y-m-d');
                //echo $movie_iso_date . '<br>';
                if (date('Y-m-d') == $movie_iso_date) {
                    $director = get_the_terms($post->ID, 'director');
                    $countries = get_the_terms($post->ID, 'country');
                    $languages = get_the_terms($post->ID, 'language');
                    $year = get_the_terms($post->ID, 'film-year');
                    $format = get_the_terms($post->ID, 'format');
                    $featured_image = wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()));
                    $film_detail = array('id' => get_the_ID(), 'image' => $featured_image, 'title' => get_the_title(), 'duration' => $duration, 'excerpt' => get_the_excerpt(), 'link' => get_permalink(), 'date' => $movie_iso_date, 'hour' => $key['film_heure'], 'director' => $director, 'country' => $countries, 'language' => $languages, 'year' => $year, 'format' => $format);
                    array_push($todays_movies, $film_detail);
                }
            }
        }
        wp_reset_postdata();
    }
    return $todays_movies;
}
开发者ID:gabzon,项目名称:spoutnik,代码行数:32,代码来源:sorting.php


示例5: ap_question_categories_html

function ap_question_categories_html($post_id = false, $list = true)
{
    if (!ap_opt('enable_categories')) {
        return;
    }
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    $cats = get_the_terms($post_id, 'question_category');
    if ($cats) {
        if ($list) {
            $o = '<ul class="question-categories">';
            foreach ($cats as $c) {
                $o .= '<li><a href="' . esc_url(get_term_link($c)) . '" title="' . $c->description . '">' . $c->name . '</a></li>';
            }
            $o .= '</ul>';
            echo $o;
        } else {
            $o = 'Categories:';
            $o .= ' <span class="question-categories-list">';
            foreach ($cats as $c) {
                $o .= '<a href="' . esc_url(get_term_link($c)) . '" title="' . $c->description . '">' . $c->name . '</a>';
            }
            $o .= '</span>';
            echo $o;
        }
    }
}
开发者ID:coollog,项目名称:theboola,代码行数:28,代码来源:anspress-categories.php


示例6: filter_available_payment_gateways_per_category

 /**
  * filter_available_payment_gateways_per_category.
  */
 function filter_available_payment_gateways_per_category($available_gateways)
 {
     //if ( ! is_checkout() ) return $available_gateways;
     foreach ($available_gateways as $gateway_id => $gateway) {
         $categories_in = get_option('wcj_gateways_per_category_' . $gateway_id);
         if (!empty($categories_in)) {
             $do_skip = true;
             foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
                 $product_categories = get_the_terms($values['product_id'], 'product_cat');
                 if (empty($product_categories)) {
                     continue;
                 }
                 // ... to next product in the cart
                 foreach ($product_categories as $product_category) {
                     if (in_array($product_category->term_id, $categories_in)) {
                         // Current gateway is OK, breaking to check next gateway (no need to check other categories of the product)
                         $do_skip = false;
                         break;
                     }
                 }
                 if (!$do_skip) {
                     // Current gateway is OK, breaking to check next gateway (no need to check other products in the cart)
                     break;
                 }
             }
             if ($do_skip) {
                 // Skip (i.e. hide/unset) current gateway - no products of needed categories found in the cart
                 unset($available_gateways[$gateway_id]);
             }
         }
     }
     return $available_gateways;
 }
开发者ID:quasel,项目名称:woocommerce-jetpack,代码行数:36,代码来源:class-wcj-payment-gateways-per-category.php


示例7: ubik_places_ancestors

function ubik_places_ancestors($taxonomy = 'places', $depth = 2, $sep = ', ')
{
    // Initialize
    $output = '';
    $places = array();
    // Get term ID; we only need one
    global $post;
    $terms = get_the_terms($post->ID, $taxonomy);
    $term = $terms[0];
    // Only proceed if this term shows inheritance
    if (!empty($term->parent)) {
        // The grunt work
        $ancestors = ubik_terms_ancestors($term->term_id, $taxonomy);
        // Ready to roll
        if (!empty($ancestors) && count($ancestors) > 1) {
            // Remove basal term, limit depth, and reverse (as is the custom for displaying places)
            $ancestors = array_reverse(array_slice(array_slice($ancestors, 0, -1), 0, $depth));
            // Loop through all ancestors and create links
            if (!empty($ancestors)) {
                foreach ($ancestors as $ancestor) {
                    $place = get_term_by('id', $ancestor, $taxonomy);
                    $places[] = '<a href="' . get_term_link($place->term_id, $taxonomy) . '" rel="tag">' . $place->name . '</a>';
                }
                // Assemble output
                if (!empty($places)) {
                    $output = implode($sep, $places);
                }
            }
        }
    }
    return $output;
}
开发者ID:synapticism,项目名称:ubik-places,代码行数:32,代码来源:ubik-places-core.php


示例8: custom_columns_portfolio

function custom_columns_portfolio($column)
{
    global $post;
    switch ($column) {
        case "portfolio_image":
            if (has_post_thumbnail()) {
                $imageurl = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
                ?>
            <img src="<?php 
                echo $imageurl;
                ?>
" height="120"  />
			<?php 
            }
            break;
        case "pcategories":
            $pcategories = get_the_terms(0, "portfolios");
            $pcategories_html = array();
            if ($pcategories) {
                foreach ($pcategories as $pcategory) {
                    array_push($pcategories_html, $pcategory->name);
                }
                echo implode($pcategories_html, ", ");
            }
            break;
    }
}
开发者ID:Karpec,项目名称:geo-mac,代码行数:27,代码来源:portfolio.php


示例9: delete_cache_transition

 function delete_cache_transition($new_status, $old_status, $post)
 {
     global $wpdb;
     $cache_duration = vibe_get_option('cache_duration');
     if (!isset($cache_duration)) {
         $cache_duration = 0;
     }
     if ($cache_duration) {
         $key = 'kposts_' . $post->post_type;
         $instructor_content_privacy = vibe_get_option('instructor_content_privacy');
         if ($instructor_content_privacy) {
             $user_id = get_current_user_id();
             $key .= '_' . $user_id;
         }
         $linkage = vibe_get_option('linkage');
         if (isset($linkage) && $linkage) {
             $linkage_terms = get_the_terms($post_id, 'linkage');
             if (isset($linkage_terms) && is_array($linkage_terms)) {
                 foreach ($linkage_terms as $term) {
                     $key .= '_' . $term->name;
                 }
             }
         }
         delete_transient($key);
         if ($post->post_type == 'course') {
             global $wpdb;
             $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '%wplms_%_course%'");
         }
     }
 }
开发者ID:nikitansk,项目名称:devschool,代码行数:30,代码来源:caching.php


示例10: get_related_projects

function get_related_projects($post_id, $number_posts = 8) {
    $query = new WP_Query();

    $args = '';

	if($number_posts == 0) {
		return $query;
	}

    $item_cats = get_the_terms($post_id, 'portfolio_category');
    if($item_cats):
    foreach($item_cats as $item_cat) {
        $item_array[] = $item_cat->term_id;
    }
    endif;

    $args = wp_parse_args($args, array(
        'posts_per_page' => $number_posts,
        'post__not_in' => array($post_id),
        'ignore_sticky_posts' => 0,
        'meta_key' => '_thumbnail_id',
        'post_type' => 'avada_portfolio',
        'tax_query' => array(
            array(
                'taxonomy' => 'portfolio_category',
                'field' => 'id',
                'terms' => $item_array
            )
        )
    ));

    $query = new WP_Query($args);

    return $query;
}
开发者ID:verbazend,项目名称:AWFA,代码行数:35,代码来源:custom_functions.php


示例11: cause_columns

function cause_columns($name)
{
    global $post;
    switch ($name) {
        case 'category':
            $categories = get_the_terms($post->ID, 'cs_cause-category');
            if ($categories != "") {
                $couter_comma = 0;
                foreach ($categories as $category) {
                    echo $category->name;
                    $couter_comma++;
                    if ($couter_comma < count($categories)) {
                        echo ", ";
                    }
                }
            }
            break;
        case 'tag':
            $categories = get_the_terms($post->ID, 'cs_cause-tag');
            if ($categories != "") {
                $couter_comma = 0;
                foreach ($categories as $category) {
                    echo $category->name;
                    $couter_comma++;
                    if ($couter_comma < count($categories)) {
                        echo ", ";
                    }
                }
            }
            break;
        case 'author':
            echo get_the_author();
            break;
    }
}
开发者ID:rasyidmujahid,项目名称:scalar-web,代码行数:35,代码来源:cs_cause.php


示例12: custom_columns

 /**
  * Define our custom columns shown in admin.
  * @param  string $column
  */
 public function custom_columns($column, $post_id)
 {
     switch ($column) {
         case 'sp_league':
             echo get_the_terms($post_id, 'sp_league') ? the_terms($post_id, 'sp_league') : __('All', 'prosports');
             break;
         case 'sp_season':
             echo get_the_terms($post_id, 'sp_season') ? the_terms($post_id, 'sp_season') : __('All', 'prosports');
             break;
         case 'sp_team':
             $teams = (array) get_post_meta($post_id, 'sp_team', false);
             $teams = array_filter($teams);
             if (empty($teams)) {
                 _e('All', 'prosports');
             } else {
                 foreach ($teams as $team_id) {
                     if (!$team_id) {
                         continue;
                     }
                     $team = get_post($team_id);
                     if ($team) {
                         echo $team->post_title . '<br>';
                     }
                 }
             }
             break;
     }
 }
开发者ID:kleitz,项目名称:ProSports,代码行数:32,代码来源:class-sp-admin-cpt-directory.php


示例13: output

    /**
     * Output the metabox
     */
    public static function output($post)
    {
        $player = new SP_Player($post);
        $leagues = get_the_terms($post->ID, 'sp_league');
        $league_num = sizeof($leagues);
        // Loop through statistics for each league
        if ($leagues) {
            $i = 0;
            foreach ($leagues as $league) {
                ?>
				<p><strong><?php 
                echo $league->name;
                ?>
</strong></p>
				<?php 
                list($columns, $data, $placeholders, $merged, $seasons_teams) = $player->data($league->term_id, true);
                self::table($post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0);
                $i++;
            }
        }
        ?>
		<p><strong><?php 
        _e('Career Total', 'sportspress');
        ?>
</strong></p>
		<?php 
        list($columns, $data, $placeholders, $merged, $seasons_teams) = $player->data(0, true);
        self::table($post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams);
    }
开发者ID:ArnaudGuillou,项目名称:SiteESBVolley,代码行数:32,代码来源:class-sp-meta-box-player-statistics.php


示例14: orbit_manage_excpt2_columns

function orbit_manage_excpt2_columns($column, $post_id)
{
    global $post;
    switch ($column) {
        // If displaying the 'type' column
        case 'type':
            // Get the types for the post
            $terms = get_the_terms($post_id, 'excpt2-type');
            // If terms were found
            if (!empty($terms)) {
                $out = array();
                // Loop through each term, linking to the 'edit posts' page for the specific term
                foreach ($terms as $term) {
                    $out[] = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post_type' => $post->post_type, 'excpt2' => $term->slug), 'edit.php')), esc_html(sanitize_term_field('name', $term->name, $term->term_id, 'excpt2', 'display')));
                }
                // Join the terms, separating them with a comma
                echo join(', ', $out);
            } else {
                _e('No excpt2 type');
            }
            break;
            // Just break out of the switch statement for everything else
        // Just break out of the switch statement for everything else
        default:
            break;
    }
}
开发者ID:ryanurban,项目名称:Orbit,代码行数:27,代码来源:admin-columns.php


示例15: ceo_comic_archive_jump_to_chapter

function ceo_comic_archive_jump_to_chapter($hide = true, $exclude = '', $showcount = false, $jumptoarchive = false, $echo = true, $render_as_list = false)
{
    ceo_protect();
    $output = '';
    if ($render_as_list) {
        global $post;
        $the_terms = get_the_terms($post->ID, 'chapters');
        // echo "<pre>the terms ";print_r($the_terms); echo "</pre>";
        $args = array('walker' => new ceo_walker_taxonomy_list(), 'orderby' => 'menu_order', 'order' => 'ASC', 'show_count' => $showcount, 'hide_empty' => $hide, 'exclude' => $exclude, 'echo' => false, 'hierarchical' => 1, 'taxonomy' => 'chapters', 'current_category' => $the_terms, 'title_li' => null, 'jumptoarchive' => $jumptoarchive, 'render_as_list' => $render_as_list);
        $output .= '<ul class="chapter-select">';
        $output .= wp_list_categories($args);
        $output .= '</ul>';
    } else {
        $args = array('walker' => new ceo_walker_taxonomy_dropdown(), 'show_option_all' => __('Select', 'comiceasel') . ' ' . ucwords(ceo_pluginfo('chapter_type_slug_name')), 'option_none_value' => '-1', 'orderby' => 'menu_order', 'order' => 'ASC', 'name' => ceo_pluginfo('chapter_type_slug_name'), 'show_count' => $showcount, 'hide_empty' => $hide, 'exclude' => $exclude, 'echo' => false, 'hierarchical' => 1, 'taxonomy' => 'chapters', 'hide_if_empty' => $hide, 'value_field' => 'slug', 'jumptoarchive' => $jumptoarchive, 'render_as_list' => $render_as_list);
        $output .= '<form id="chapter-select" class="chapter-select" method="get">' . "\r\n";
        $select = wp_dropdown_categories($args);
        $replace = '<select$1 onchange="document.location.href=this.options[this.selectedIndex].value;">';
        $output .= preg_replace('#<select([^>]*)>#', $replace, $select);
        $output .= "\t<noscript>\r\n";
        $output .= "\t\t<input type=\"submit\" value=\"View\" />\r\n";
        $output .= "\t</noscript>\r\n";
        $output .= "</form>\r\n";
    }
    ceo_unprotect();
    if ($echo) {
        echo $output;
    } else {
        return $output;
    }
}
开发者ID:egypturnash,项目名称:comic-easel,代码行数:30,代码来源:archive-dropdown.php


示例16: manage_portfolio_columns

function manage_portfolio_columns($column)
{
    global $post;
    if ($post->post_type == "portfolio") {
        switch ($column) {
            case "description":
                the_excerpt();
                break;
            case "portfolio_categories":
                $terms = get_the_terms($post->ID, 'portfolio_category');
                if (!empty($terms)) {
                    foreach ($terms as $t) {
                        $output[] = "<a href='edit.php?post_type=portfolio&portfolio_tag={$t->slug}'> " . esc_html(sanitize_term_field('name', $t->name, $t->term_id, 'portfolio_tag', 'display')) . "</a>";
                    }
                    $output = implode(', ', $output);
                } else {
                    $t = get_taxonomy('portfolio_category');
                    $output = "No {$t->label}";
                }
                echo $output;
                break;
            case 'thumbnail':
                echo the_post_thumbnail('thumbnail');
                break;
        }
    }
}
开发者ID:kevalbaxi,项目名称:dosomething-blog,代码行数:27,代码来源:portfolio.php


示例17: end_el

 /**
  * Code that appends posts when a child node is reached
  */
 function end_el(&$output, $object, $depth = 0, $args = array())
 {
     $tax_name = $args['taxonomy'];
     // use cat_id for category and slug for all other taxonomy
     $term_id = $tax_name == 'category' ? $object->cat_ID : $object->slug;
     $query_args = array('post_type' => $args['post_type'], 'post_status' => 'publish', 'posts_per_page' => -1, "{$tax_name}" => $term_id, 'meta_query' => array('relation' => 'OR', array('key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', 'value' => '', 'compare' => 'NOT EXISTS'), array('key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', 'value' => '1', 'compare' => '!='), array('key' => WPSEO_Meta::$meta_prefix . 'sitemap-html-include', 'value' => 'always', 'compare' => '=')));
     $posts = get_posts($query_args);
     if (is_array($posts) && $posts !== array()) {
         $output .= '<ul>';
         foreach ($posts as $post) {
             $category = get_the_terms($post->ID, $tax_name);
             if ($category) {
                 // reset array to get the first element
                 $category = reset($category);
                 // Only display a post link once, even if it's in multiple taxonomies
                 if ($category->term_id == $object->term_id && !in_array($post->ID, $this->processed_post_ids)) {
                     $this->processed_post_ids[] = $post->ID;
                     $output .= '<li><a href="' . esc_url(get_permalink($post->ID)) . '">' . get_the_title($post->ID) . '</a></li>';
                 }
             }
         }
         $output .= '</ul>';
     }
     parent::end_el($output, $object, $depth, $args);
 }
开发者ID:kyme-online,项目名称:Ramesh-Photography,代码行数:28,代码来源:class-sitemap-walker.php


示例18: frl_get_related_ids

function frl_get_related_ids($cpost, $tax = 'post_tag', $limit = 5)
{
    global $wpdb, $related_pt_rules;
    $related_ids = array();
    //params
    $related_pt_rules = frl_related_posts_rules();
    $post_type = isset($related_pt_rules[$cpost->post_type]) ? $related_pt_rules[$cpost->post_type] : '';
    $post_type = apply_filters('tst_related_post_types', $post_type, $cpost, $tax);
    //sometimes we need to alter it outside
    if (empty($post_type)) {
        return $related_ids;
    }
    $post_type = implode("','", $post_type);
    $limit = absint($limit);
    $post_id = absint($cpost->ID);
    //tags
    $relation_tags = get_the_terms($cpost, $tax);
    if (empty($relation_tags)) {
        return $related_ids;
    }
    $tag_ids = array();
    foreach ($relation_tags as $pt) {
        $tag_ids[] = (int) $pt->term_taxonomy_id;
    }
    $tag_ids = implode(',', $tag_ids);
    $sql = "SELECT p.ID, COUNT(t_r.object_id) AS cnt \nFROM {$wpdb->term_relationships} AS t_r, {$wpdb->posts} AS p\nWHERE t_r.object_id = p.id \nAND t_r.term_taxonomy_id IN({$tag_ids}) \nAND p.post_type IN('{$post_type}') \t\nAND p.id != {$post_id} \nAND p.post_status='publish' \nGROUP BY t_r.object_id \nORDER BY cnt DESC, p.post_date_gmt DESC \nLIMIT {$limit} ";
    $r_posts = $wpdb->get_results($sql);
    if (empty($r_posts)) {
        return $related_ids;
    }
    foreach ($r_posts as $p) {
        $related_ids[] = (int) $p->ID;
    }
    return $related_ids;
}
开发者ID:Teplitsa,项目名称:giger,代码行数:35,代码来源:related.php


示例19: widget

 function widget($args, $instance)
 {
     global $wp_query;
     extract($args);
     $current_taxonomy = $this->_get_current_taxonomy($instance);
     if (!empty($instance['title'])) {
         $title = $instance['title'];
     } else {
         if ('post_tag' == $current_taxonomy) {
             $title = __('Tags');
         } else {
             $tax = get_taxonomy($current_taxonomy);
             $title = $tax->labels->name;
         }
     }
     $use_desc_for_title = isset($instance['use_desc_for_title']) ? $instance['use_desc_for_title'] : true;
     $count = isset($instance['count']) ? $instance['count'] : false;
     $title = apply_filters('widget_title', $title, $instance, $this->id_base);
     $current_term = false;
     $current_term_id = $current_post_id = 0;
     if (suwp::is_tax($current_taxonomy)) {
         $current_term = $wp_query->get_queried_object();
         $current_term_id = $wp_query->get_queried_object_id();
         $title = $current_term->name;
     } elseif (is_singular()) {
         $current_post_id = $wp_query->get_queried_object_id();
         $post_terms = get_the_terms($current_post_id, $current_taxonomy);
         if (is_array($post_terms) && count($post_terms)) {
             $current_term = reset($post_terms);
             $current_term_id = $current_term->term_id;
             $title = $current_term->name;
         }
     }
     $term_args = array('taxonomy' => $current_taxonomy, 'orderby' => 'name', 'show_count' => $count ? '1' : '0', 'hierarchical' => '0', 'title_li' => '', 'parent' => $current_term_id, 'show_option_none' => false, 'use_desc_for_title' => $use_desc_for_title ? '1' : '0', 'echo' => false);
     $category_output = $post_output = '';
     if (!$current_term || is_taxonomy_hierarchical($current_taxonomy)) {
         $category_output = wp_list_categories($term_args);
     }
     if ($current_term) {
         $child_posts = get_posts(array('taxonomy' => $current_taxonomy, 'term' => $current_term->slug, 'numberposts' => 5));
         foreach ($child_posts as $child_post) {
             $css_class = '';
             if ($child_post->ID == $current_post_id) {
                 $css_class = 'current_post_item';
             }
             $post_output .= "\n\t\t\t<li class=\"" . $css_class . '"><a href="' . get_permalink($child_post->ID) . '" title="' . esc_attr(wp_strip_all_tags(apply_filters('the_title', $child_post->post_title, $child_post->ID))) . '">' . apply_filters('the_title', $child_post->post_title, $child_post->ID) . "</a></li>\n";
         }
     }
     if ($category_output || $post_output) {
         echo $before_widget;
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         echo "\n\t\t<ul>\n";
         echo $category_output;
         echo $post_output;
         echo "\n\t\t</ul>\n";
         echo $after_widget;
     }
 }
开发者ID:grantschulte,项目名称:suna-wordpress,代码行数:60,代码来源:widgets.php


示例20: EM_Categories

 /**
  * Creates an EM_Categories instance, currently accepts an EM_Event object (gets all Categories for that event) or array of any EM_Category objects, which can be manipulated in bulk with helper functions.
  * @param mixed $data
  * @return null
  */
 function EM_Categories($data = false)
 {
     global $wpdb;
     self::ms_global_switch();
     if (is_object($data) && get_class($data) == "EM_Event" && !empty($data->post_id)) {
         //Creates a blank categories object if needed
         $this->event_id = $data->event_id;
         $this->post_id = $data->post_id;
         if (EM_MS_GLOBAL && !is_main_site($data->blog_id)) {
             $cat_ids = $wpdb->get_col('SELECT meta_value FROM ' . EM_META_TABLE . " WHERE object_id='{$this->event_id}' AND meta_key='event-category'");
             foreach ($cat_ids as $cat_id) {
                 $this->categories[$cat_id] = new EM_Category($cat_id);
             }
         } else {
             $results = get_the_terms($data->post_id, EM_TAXONOMY_CATEGORY);
             if (is_array($results)) {
                 foreach ($results as $result) {
                     $this->categories[$result->term_id] = new EM_Category($result);
                 }
             }
         }
     } elseif (is_array($data) && self::array_is_numeric($data)) {
         foreach ($data as $category_id) {
             $this->categories[$category_id] = new EM_Category($category_id);
         }
     } elseif (is_array($data)) {
         foreach ($data as $EM_Category) {
             if (get_class($EM_Category) == 'EM_Category') {
                 $this->categories[] = $EM_Category;
             }
         }
     }
     self::ms_global_switch_back();
     do_action('em_categories', $this);
 }
开发者ID:mpaskew,项目名称:isc-dev,代码行数:40,代码来源:em-categories.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP get_the_time函数代码示例发布时间:2022-05-15
下一篇:
PHP get_the_term_list函数代码示例发布时间: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