按类别列出与页面标题匹配的wordpress帖子

问题描述:

我试图列出共享页面名称的类别中的帖子。即如果你在“服务”页面上,它应该显示类别“服务”中的帖子。我知道这是很容易的用条件,如要做到:按类别列出与页面标题匹配的wordpress帖子

<?php if ((is_page('Groups'))) { query_posts('category_name=groups'); 
while (have_posts()) { the_post();?> 
<h2 class="title" id="sub">Upcoming Group Programs</h2> 
<a href="<?php the_permalink() ?>"> 
<div class="post" id="post-<?php the_ID(); ?>"> 
<h2><?php the_title(); ?></h2></a> 
<div class="entry"><?php the_content(); ?></div> 
</div> 
<?php } wp_reset_query(); //Restores Global Post Data }?> 

但我想这样做,而不必设置多个特定条件语句,是这样的:

<?php //global $wp_query; // Uncomment if necessary, shouldn't be 
$test = the_title(); 
$args = array('cat_name' => $test // ARGS HERE); 
$args = array_merge($args , $wp_query->query); 
query_posts($args); while (have_posts()) { the_post(); ?> 
<div class="post" id="post-<?php the_ID(); ?>"> 
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2> 
<div class="entry"><?php the_content(); ?></div></div> 
<?php } ?> 

有什么想法!很明显,我可以将页面&类别“名称”与“slu”“或任何最适合的内容交换。谢谢!

谢谢!我改变了一些东西,并得到它与您的建议。

<?php 
$catmatch = get_the_title(); 
//The Query 
query_posts('category_name=' . $catmatch); ?> 

希望在最后一行有我做了正确的串联,这似乎可行,但如果不是它是如何应该是正确完成,请让我知道!

尝试更改: $ test = the_title();

去:

$ test = get_the_title();

您可能还必须使用array_merge();删除行。