分类: 建站知识

  • wordpress已知该分类id 获取分类名字和分类链接代码

    <?php
    echo get_cat_name( 1 ); // 根据id获取分类名
    echo get_category_link( 1 ); // 根据分类id获取链接
    ?>

    在制作wordpress模板时,有时会用到根据分类ID来调用分类名称或链接的时候,用以上这段代码即可解决。

  • 按分类调用标签 调用指定分类下的TAG

    <?php
    query_posts('category_name=news');
    if (have_posts()) : while (have_posts()) : the_post();
    if( get_the_tag_list() ){
    echo $posttags = get_the_tag_list('<li class="jquery">','</li><li>','</li>');
    }
    endwhile; endif;
    wp_reset_query();
    ?>

    在制作wordpress主题时,有时候会用到按分类调用标签的时候,用上面的这一段代码就可以解决。

  • WordPress子页面page调用父页面标题

    在需要调用的页面,添加以下代码就可以现实子页面调用父页面的标题。
    <?php
    if($post->post_parent) {
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
    } else {
    wp_title('');
    }
    ?>