获取标签说明并在WordPress中显示

时间:2015-10-19 16:30:37

标签: php wordpress get tags

我试图获取标签描述并在WordPress中显示但没有成功。我在下面评论了我添加的内容,以尝试获取标记说明。

        <?php

        $q_categories = $_GET['categories'];
        $q_tags = $_GET['tags'];


            $term_id = 26;
            $taxonomy_name = 'tags';
            $termchildren = get_term_children( $term_id, $taxonomy_name);
            $description = tag_description(); //NOT WORKING
            foreach ( $termchildren as $child ) { 
            $term = get_term_by( 'id', $child, $taxonomy_name, $description );
            $tag_image = get_field('tag_image', $term);
            $show_on_landing_page = get_field('show_on_landing_page', $term);


 if ( $show_on_landing_page) { ?>

                    <div class="box three columns">
                        <div class="box-content slidedown">
                            <? if( !empty($tag_image) ): ?><img src="<? echo the_field('tag_image', $term); ?>" class="cover cat-img" /><?php endif; ?>
                            <div class="details">
                                <div class="details-container">
                                    <h4><? echo $term->name; //NOT WORKING ?></h4>
                                    <p><? echo $term->description; ?></p>
                                    <a href="?tags=<? echo $term->slug; ?>" class="btn hvr-bounce-to-right">View Work</a>
                                </div>
                            </div>
                        </div>
                    </div>

                <? } ?>

            <? } ?>

2 个答案:

答案 0 :(得分:0)

请尝试使用&#34;标记说明&#34;。

 <?php

  $tags = get_tags();

  foreach ( $tags as $tag ) 
 {
    echo '<pre>';
   //print_r($tag);
    echo $tag_name=$tag->name.'<br>';
    echo $tag_desc=$tag->description.'<br>';   

 }

 ?>

答案 1 :(得分:0)

我只需要这种结构,就可以像这样解决它。

$posttags = get_the_tags();
if ($posttags) {
    foreach($posttags as $tag) {
        echo $tag->name;
        echo $tag->description;
    }
}