2012-07-15 54 views
1

雖然我有PHP的經驗,但WordPress對我來說很新,我在這裏掙扎。顯示帖子由DYNAMIC標籤

我想幫助朋友完成一個主題。他與幾位藝術家合作,每位藝術家都有一個以該藝術家的名字命名的WP頁面(即Tom Jones),他只想顯示該藝術家的帖子。我們定義了一個標籤爲每個藝術家(湯姆·瓊斯)與像(湯姆·瓊斯)

繼食品鼻涕蟲,我躍躍欲試河套模板如下:

$tags = get_tags(); 
//query_posts(array('tag' => $tag->slug)); 
query_posts(array('tag' => 'tom-jones')); 

if(have_posts()) : while(have_posts()) : the_post(); 
    echo '<li id="feed<?php theID(); ?>" style="border-bottom:1px solid #404040;">'; 
    echo '<table><tr><td width="40">'; 
    echo '<img src="<?php echo get_post_meta($post->ID, 'image_path', true); ?>" />'; 
    echo '</td><td><a href="'; 
    the_permalink(); 
    echo '">'; 
    the_title();        
    echo '</a><br><span class="smTxt">Posted by '; 
    the_author(); 
    echo ' on <em>'; 
    the_time('F jS, Y'); 
    echo '</em></span><br>'; 
    the_excerpt(); 
    echo '</td></tr></table></li>'; 
    endwhile; 
else: 
    echo '<h3>There are no posts.</h3>'; 
endif; 

我還以爲被註釋掉的query_post會抓住藝術家的特定slu but,但它返回「No Posts」。當我像現在這樣硬編碼時,它按預期工作。

任何幫助,非常感謝。

+0

你能解釋一下其中的文件你正在使用此代碼? – 2012-07-15 19:14:27

+0

page-artist.php(模板頁面) – jgravois 2012-07-15 19:18:01

回答

0

試試這個

query_posts(array('tag' => get_query_var('tag'))); 

This post may help you

更新:

正如你所說artist是一個自定義texonomy所以嘗試當您使用query_posts

You may read this post

$the_tax = get_taxonomy(get_query_var('taxonomy')); 
query_posts(array('artist' => $the_tax->labels->name)); 

必須循環使用後wp_reset_query()

更新:(使用WP_Query)

$the_tax = get_taxonomy(get_query_var('taxonomy')); 
$args = array(
'tax_query' => array(
    array(
     'taxonomy' => 'artist', 
     'field' => 'slug', 
     'terms' => $the_tax->labels->name 
    ) 
) 
); 
$query = new WP_Query($args); 
+0

返回所有帖子...無限制 – jgravois 2012-07-15 19:50:36

+0

不清楚你是什麼意思? – 2012-07-15 19:58:04

+0

該網站上的所有帖子都與該查詢一起列出,而不是由特定藝術家標籤限制的一組帖子 – jgravois 2012-07-15 20:03:37

相關問題