WordPress 使用帖子标题作为导航
我正在尝试创建一个基于帖子标题的导航。顶部的主要导航是类别,侧边栏中将是该相关类别的帖子标题。
我正在使用的代码一直有效到一定程度(我从 按类别列出与页面标题匹配的 WordPress 帖子)。
但我有两个问题。
主要问题是,当您访问单个帖子时,它仅在侧边栏中列出该帖子,而没有同一类别的其他帖子。
第二个小问题是,当我不需要它时,它会列出页面。
<p>below lists the right posts for the right
cats but fails at the single post stage</p>
<?php
$test = get_the_title();
$args = array( 'cat_name' => $test );
$args = array_merge( $args , $wp_query->query );
get_posts( $args ); while (have_posts()) { the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<ul>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
</ul>
<?php } ?>
任何帮助将不胜感激。谢谢
I'm trying to create a navigation based around post titles. The main navigation at the top is the Categories, in a sidebar will be the Post Titles from that relevant Category.
The code I'm using works up until a point (i got it from List wordpress posts by category which match page title).
But I have 2 problems.
The main issue is when you get to the single post it just lists that post in the sidebar and no others from the same category.
The second minor issue, is it is listing pages when I don't need it to.
<p>below lists the right posts for the right
cats but fails at the single post stage</p>
<?php
$test = get_the_title();
$args = array( 'cat_name' => $test );
$args = array_merge( $args , $wp_query->query );
get_posts( $args ); while (have_posts()) { the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<ul>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
</ul>
<?php } ?>
Any help would be appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于第二个问题,您可以添加一个参数 'post_type' => '邮政'
它只会显示帖子。
for you second issue you can add one argument 'post_type' => 'post'
it will only display posts.