我是Wordpress的新手,我不知道如何为Wordpress中的所有类别创建一个通用的自定义主题页面。我已经看过很多关于如何为每个类别创建自定义主题页面的教程,但没有关于如何为所有类别链接创建一个通用主题页面的教程。
这是如何实现的?谢谢
发布于 2019-09-12 16:12:56
为了简单起见,我假设你指的是post_type "post“的所有类别。“帖子”在管理菜单上。
您可以创建自定义函数或在页面中使用此代码来列出所有类别get_categories
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC'
) );
foreach( $categories as $category ) {
$category_link = sprintf(
'<a href="%1$s" alt="%2$s">%3$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
esc_html( $category->name )
);
echo '<p>' . sprintf( esc_html__( 'Category: %s', 'textdomain' ), $category_link ) . '</p> ';
echo '<p>' . sprintf( esc_html__( 'Description: %s', 'textdomain' ), $category->description ) . '</p>';
echo '<p>' . sprintf( esc_html__( 'Post Count: %s', 'textdomain' ), $category->count ) . '</p>';
}显然,您可以根据自己认为合适的方式调整输出。
https://stackoverflow.com/questions/57890392
复制相似问题