wordpress 获取分类目录的ID,分类标题,分类描述,分类链接url函数

      发布在:all      评论:1 条评论

get_cat_ID()    根据分类名称获取分类ID   ///// get_cat_name()    根据分类ID获取分类名称

用法:<?phpget_cat_ID( $cat_name ) ?>

参数:$cat_name  分类名称默认值为"General"。类型为字符型,可选

返回的值:出错时返回0,成功则返回分类ID号,类型为整数

示例:

<?php      
    $category_id= get_cat_id('CategoryName');      
   query_posts('cat='.$category_id);      
    if(have_posts()) : while (have_posts()) : the_post();
   the_content();   
    endwhile;endif;  
?>  

get_category_link()   根据分类ID获取分类的链接URL

用法:<?phpget_category_link( $category_id ) ?>

参数:$categroy_id 分类ID号  默认值:None,类型为整数,必需

返回的值:分类URL  字符串型

示例:

<?php
    $category_id= get_cat_ID( 'Category Name' );
   $category_link = get_category_link( $category_id );
?>
<a href="<?php echo $category_link;?>" title="Category Name">CategoryName</a>

the_category() 显示文章所属分类目录的链接。此标签必须在主循环中。

用法:<?phpthe_category( $separator, $parents ); ?>

参数:$separator显示在分类目录链接之间的文字或字符。默认以无序列表方式排列分类目录链接。字符串型

         $parents怎样显示子分类目录链接,字符串型,值包括:

        'multiple'——显示父分类与其子分类的链接以展示"父子"关系

        'single'——只显示子分类的链接,用链接文本标出"父子"关系

          默认值为显示子分类链接,无标识文字。

示例:

用逗号隔开分类目录

列出分类目录,(在分类目录数量多于一个的情况下)以逗号作为分隔符。

<p>This post is in:<?php the_category(', ');?></p> 

用箭头隔开分类目录

列出分类目录,以箭头(>)作为分隔符。(使用时请注意,有些访问者可能会将分类>分类这种格式解读为一对具有“父子”关系的分类。)

<p>Categories: <?phpthe_category(' &gt; ');?></p> 

single_cat_title()   显示或返回当前页面的分类目录标题。

对那些显示WordPress标签而非分类目录标题的页面(如"/tag/carceer"),该标签显示或返回标签名称。该标签只能用在WordPress主循环(loop)之外。

用法:<?phpsingle_cat_title( $prefix, $display ); ?>

默认用法: <?phpsingle_cat_title('prefix'=>,'display'=>true ); ?>

参数:

$prefix  输出时在标题前的文本信息。默认值:None,类型是字符串,可选

$display 显示标题(TRUE)或返回标题以便用在PHP中(FALSE)。默认值:TRUE,类型是布尔型 可选

示例:

下面这个例子在分类目录标题后显示“当前分类:”字样:

<p><?phpsingle_cat_title('当前分类是');?></p> 

输出:当前分类是wordpress

下面这个例子将当前分类目录标题赋值给变量$current_category以用在PHP中。

<?php $current_category = single_cat_title("",false); ?>

category_description()  返回用户在当前分类目录所填写的说明信息

用法:<?phpecho category_description( $category ); ?>

参数:$category被返回说明信息的分类目录的数值型ID。若用户未指定分类目录,默认为当前分类目录。类型为整型

示例:

<div><?php echocategory_description(3);?></div>

返回结果:WordPress is a favorite blogging tool of mine and I share tipsand tricks for using WordPress here.

 <div><strong><?phpsingle_cat_title('当前分类'); ?>
</strong>: <?php echocategory_description();?></div>

返回结果:当前分类WordPress: WordPress is a favorite blogging tool of mineand I share tips and tricks for using WordPress here.

Responses
    加载中...
  1. Hello to every body, it's my first pay a quick visit of this web site;
    this weblog carries remarkable and genuinely excellent stuff
    in support of visitors.

    回复

滇ICP备14007443号-4