【发布时间】:2013-01-17 21:37:28
【问题描述】:
我已经连续两天研究这个问题了,我这辈子都想不通。
我有一个自定义帖子类型 'teams',它分配了名为“男孩部门”的自定义类别,我正在尝试向我的模板添加代码,以显示分配给的所有帖子这个自定义类别。
例如,我想让它显示如下:
男孩 U10
黑豹
眼镜蛇
阿兹特克人
男孩 U12
星星
国王
鸭子
宇宙
任何帮助将不胜感激。我已经尝试了 100 次谷歌搜索,但似乎没有任何效果。这就是我所拥有的......
<?php
//for each category, show posts
$cat_args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'orderby' => 'title',
'order' => 'ASC',
'showposts' => -1,
'category__in' => array($category->term_id),
'caller_get_posts'=>1
);
$posts=get_posts($args);
if ($posts) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
foreach($posts as $post) {
setup_postdata($post); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
}
}
}
?>
【问题讨论】:
-
我没有仔细检查所有参数,但您的代码看起来是一个好的开始。它会产生任何有用的东西吗?有没有错误?
-
它显示来自标准类别的帖子和类别,但不显示我的自定义类别和自定义帖子
标签: wordpress