get tags in category get terms of related taxonomies
feilong.org 修订于2011-02-17 04:08:26 565 次浏览
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
<?php /** 1. functions.php feilong.org,function to get terms of related taxnomy **/ function feilong_get_termids($args,$taxonomy='post_tag'){ $flposts = new WP_Query();$flposts->query($args); while ($flposts->have_posts()) : $flposts->the_post(); $postterms = get_the_terms($post->ID,$taxonomy); if ($postterms) { foreach($postterms as $term) { $all_termids[] = $term->term_id; } } endwhile; if($all_termids){ $termids = array_unique($all_termids); //REMOVES DUPLICATES of an array of one dimension return $termids; } } /** 2. get posts by certion termslug of certain taxonomy or post type **/ $taxonomy='singer'; $termslug='zhangye'; $args=array( 'post_type'=>'post', 'orderby'=>'count', 'posts_per_page'=>-1, $taxonomy=> $termslug //certain termslug of this taxonomy 'singer' ); $relatedtaxonomy='post_tag'; $termids=feilong_get_termids($args,$relatedtaxonomy); /** 3. functions.php feilong.org, if you know termids, then function to list these terms in thumbnails links or dls format **/ function feilong_list_terms_by_ids($termids,$taxonomy,$thumbornot='0',$linkbefore='',$linkafter='',$gap=''){ foreach ($termids as $termid) { $term=get_term( $termid, $taxonomy ); $termlink = get_term_link( $term, $taxonomy ); $termname=$term->name; $termimg='<img src="'.get_bloginfo('template_directory').'/pic/term/term-'.$termid.'.jpg" alt="'.$termname.'"/>'; $termposts=$term->count; if ( !is_wp_error( $termlink ) ) echo $linkbefore; if ($thumbornot=='1') { echo '<a href="'.$termlink.'" rel="tag" title="'.$termname.$termid.'">'.$termimg.'</a>'.$gap; } elseif($thumbornot=='0') { echo '<a href="'.$termlink.'" rel="tag" title="'.$termname.$termid.'">'.$termname.'</a>'.$gap; }else{ echo '<dt><a href="'.$termlink.'">'.$termimg.'</a></dt>'; echo '<dd class="albumname"><a href="'.$termlink.'">'.$termname.'</a></dd>'; echo '<dd class="albumposts">'.$termposts.' 个视频</dd>'; } echo $linkafter; } } /** 4. if termids,then list them in links **/ if($termids){ feilong_list_terms_by_ids($termids,$relatedtaxonomy,$thumbornot='0',$linkbefore='',$linkafter='',$gap=', '); } //feilong.org tags in category,or terms of related taxonomy ?> |
更新网址:https://feilong.org/tags-in-category-terms-of-related-taxonomy
最初发布:20110217 04:08:26 feilong.org 于广州
加入收藏夹,查看更方便。
所在分类: wordpress