我有一个wordpress网站,我想在类别中显示帖子 Headers 列表 . 喜欢
Category 1
post 1
post 2
category 2
post 1
post 2
post 3
category 3
post 1
post 2
$show_count = 0;
$pad_counts = 0;
$hierarchical = 1;
$taxonomy = 'filter';
$title = true;
$description = true;
$args = array(
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'taxonomy' => $taxonomy,
'use_desc_for_title' => $description,
'title_li' => $title
);
$categories=get_categories($args);
foreach($categories as $category) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
//display posts
$cat_new = $category->term_id;
$post_args = array( 'numberposts' => -1, 'category' => $cat_new, 'caller_get_posts' => 0 );
$myposts = get_posts( $post_args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
echo '<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?>';
endforeach; }
上面的代码只显示了一个类别列表,而不是它下面的帖子 Headers .
我很困惑,我已经阅读了很多博客并发布了这个但仍然没有完成 . 任何帮助将不胜感激 . 提前致谢 .
3 回答
首先,您的代码被破坏,可能会破坏您的主题,因此帖子不会显示 . endforeach之前的最后一行缺少关闭标记
您在此代码中使用了一个非常古老且已弃用的参数
caller_get_posts
:你应该用
ignore_sticky_posts
替换