开发者

Wordpress using Post titles as navigation

开发者 https://www.devze.com 2023-04-09 13:00 出处:网络
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.

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_post开发者_StackOverflow中文版s()) { 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


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 );
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号