柯南 Become Professional


2011-02-15

在WordPress分类目录下显示文章标题

958 views, 技术, by 许石南.
1
顶一下

下面的代码可在category.php中发挥作用。这段代码能够给出某分类的分类名称并以列表形式动态生成该分类下属文章。

示例:

分类目录A

子分类下的第四篇文章

子分类下的第三篇文章

子分类下的第二篇文章

子分类下的第一篇文章

<?php
//Identify current Post-Category-ID ermitteln
foreach((get_the_category()) as $category)
    {
    $postcat= $category->cat_ID;
    $catname =$category->cat_name;
    }
?>
<h2><?php echo $catname; ?></h2>
<?php $categories = get_categories("child_of=$postcat");
    foreach ($categories as $cat)
    { ?>
    <?php query_posts("cat=$cat->cat_ID&posts_per_page=-1"); ?>
    <h3><?php single_cat_title(); ?></h3>
    <?php while (have_posts()) : the_post(); ?>
    <ul>
        <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
            <?php the_title(); ?></a>
        </li>
    </ul>
    <?php endwhile; ?>
    <?php } ?>
<?php } ?>

来源

分享家:Addthis中国

相关文章:

Back Top

评论 (3) 引用 (1) 发表评论 引用地址
  1. 我想问一下,这个category.php是在当前使用主题目录下吗?怎么我的主题目录下没有这个文件呢?

  2. 在wp-include下面的呀

  3. 要放在里面的那个位置呢?

  1. 美容!美容!美容!美容!美容!美容!美容!美容!美容!美容!美容!美容! | BB霜 (,2011-07-22)

    [...] 在WordPress分类目录下显示文章标题 | 柯南 Become Professional [...]

发表评论

电子邮件地址不会被公开。 必填项已被标记为 *

*