2010-11-18 55 views
0

我試圖列出共享頁面名稱的類別中的帖子。即如果你在「服務」頁面上,它應該顯示類別「服務」中的帖子。我知道這是很容易的用條件,如要做到:按類別列出與頁面標題匹配的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); ?> 

希望在最後一行有我做了正確的串聯,這似乎可行,但如果不是它是如何應該是正確完成,請讓我知道!

回答

0

嘗試更改: $ test = the_title();

去:

$ test = get_the_title();

您可能還必須使用array_merge();刪除行。

相關問題