V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
joynic
V2EX  ›  问与答

请问wordpress怎样实现在首页按分类输出对应的TAGS标签云?

  •  
  •   joynic · 2012-01-13 17:05:53 +08:00 · 3589 次点击
    这是一个创建于 4495 天前的主题,其中的信息可能已经有所发展或是发生改变。
    <?php
    query_posts('cat=226&posts_per_page=-1');
    if(have_posts()): while (have_posts()) : the_post();
    $all_tag_objects = get_the_tags();
    if($all_tag_objects){
    foreach($all_tag_objects as $tag) {
    if($tag->count > 0) {$all_tag_ids[] = $tag -> term_id;}
    }
    }
    endwhile;endif;
    $tag_ids_unique = array_unique($all_tag_ids);
    foreach($tag_ids_unique as $tag_id) {$post_tag = get_term( $tag_id, 'post_tag' ); echo '<a href="'.get_tag_link($tag_id).'">'.$post_tag->name.'</a>&nbsp; &nbsp;';}?>

    我用这个可以做到输出某个分类的,但如果同时多个分类的话,就全部集中到一个标签云里面了。
    2 条回复    1970-01-01 08:00:00 +08:00
    joynic
        1
    joynic  
    OP
       2012-01-13 17:07:48 +08:00
    @Sivan 必须得请教你了^_^
    Sivan
        2
    Sivan  
       2012-01-13 19:10:25 +08:00
    最后加一行 wp_reset_query() 试试
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2424 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 12:08 · PVG 20:08 · LAX 05:08 · JFK 08:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.