WordPress 使用帖子标题作为导航

发布于 2024-12-07 08:33:27 字数 871 浏览 3 评论 0原文

我正在尝试创建一个基于帖子标题的导航。顶部的主要导航是类别,侧边栏中将是该相关类别的帖子标题。

我正在使用的代码一直有效到一定程度(我从 按类别列出与页面标题匹配的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

装迷糊 2024-12-14 08:33:27

对于第二个问题,您可以添加一个参数 'post_type' => '邮政'
它只会显示帖子。

$test = get_the_title();
$args = array( 'cat_name' => $test,'post_type' => 'post' );
$args = array_merge( $args , $wp_query->query );

for you second issue you can add one argument 'post_type' => 'post'
it will only display posts.

$test = get_the_title();
$args = array( 'cat_name' => $test,'post_type' => 'post' );
$args = array_merge( $args , $wp_query->query );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文