2015-12-23 98 views
0

我正在爲wordpress設置一個自定義帖子類型,現在我試圖在主頁上顯示帖子。我想隱藏帖子,直到他們通過has_tag被調用,我使用下面的代碼,但它顯示所有帖子。顯示wp_query上沒有帖子

$args = array('post_type' => 'homepage', 'posts_per_page' => -1); 
$loop = new WP_Query($args); 

while ($loop->have_posts()) : 
    $loop->the_post(); 
    echo '<div class="entry-content">'; 
    the_content(); 
    echo '</div>'; 
endwhile; 
+0

http://stackoverflow.com/q/33838424/1687983可能的重複? –

+0

*「我想隱藏帖子,直到它們通過has_tag被調用」* - 這是什麼意思? – rnevius

+0

這不是重複的帖子。這與我提出的其他問題完全不同。這是與一個自定義帖子類型,我遇到了所有帖子顯示的麻煩。我試圖將每頁的帖子設置爲-1,但似乎不起作用。 –

回答

0

所以我能夠通過使用下面的代碼來實現這一點。

<?php 

$args = array(
'post_type' => 'homepage', 
); 
$the_query = new WP_Query($args); ?> 

<?php 
// The Loop 
if ($the_query->have_posts()) { 
echo '<ul>'; 
while ($the_query->have_posts()) { 
$the_query->the_post(); 
if (has_tag('footer')) { 
echo '<li>' . get_the_title() . '</li>'; 
} 
} 
echo '</ul>'; 
} rewind_posts(); 




// The Loop 
if ($the_query->have_posts()) { 

while ($the_query->have_posts()) { 
$the_query->the_post(); 
if (has_tag('cta')) { 
echo '<div class="cta-style">' . get_the_title() . '</div>'; 
} 
} 

} ?> 
相關問題