2014-09-29 46 views
0

我有一個網站正在開發中,客戶想要一個新聞和F.A.Q頁面。不是問題!他希望能夠添加自己的帖子(包括新聞和常見問題解答),而不是問題!他要求的最後一件事是他能夠管理顯示的帖子數量和顯示的帖子類型。我已經建立了一個系統,客戶可以選擇一個類別來顯示(我使用的是AwesomeBuilder),現在我們有三種不同類型的帖子:Regular,Regular + Sticky和如果客戶選擇只顯示普通帖子的選項,我可以通過使用post__not_in來關閉粘貼帖子,但是如果客戶選擇普通+粘滯或粘滯功能,那麼金額功能不再起作用限制wordpress中的貼子數量

可以說客戶端最多可以選擇10個帖子,在常規類別中,最多可以達到10個,就是這樣,在粘性帖子中,這不會發生,它只顯示所有粘性帖子si被告知總是保持最佳狀態。定期+粘滯會顯示所有的粘性帖子,然後是10個常規帖子。我希望我的情況和問題清楚。

下面的代碼。

$sticky = get_option('sticky_posts'); 
$number = $atts['number']; 

if ($atts['sticky'] == 'nieuws') { 
    $args = array('post__not_in' => $sticky, 'posts_per_page' => $number); 

} elseif ($atts['sticky'] == 'nieuws-sticky') { 
    $sticky_count = count($sticky); 
    if ($sticky_count <= $number){ 
     $number_sticky = $number - $sticky_count; 
     $args = array('post_type' => post, 'posts_per_page' => $number_sticky); 
    } 
    else { 
//  $sticky = array_slice($sticky,0, 1); 
//  echo 'hello'. $sticky; 
     $args = array('post__in' => $sticky); 
    } 
} else { 
// $sticky = array_slice($sticky,1, 2); 
    $args = array('post__in' => $sticky, 'posts_per_page' => $number); 
} 

ps。我知道THIS是大約相同的問題,但它尚未得到答覆。

回答

0

請確保$ number變量已變爲10,並確保您在query_posts函數中使用$ args,如query_posts($ args);

+0

$數字正在由用戶定義的滑塊設置。它得到了正確的變量,這已經通過「常規」帖子正常工作進行檢查。 – 2014-09-29 14:56:26

+0

嘗試使用show_posts或numberofposts代替 – 2014-09-29 17:20:41

+0

$ args = array( 'showposts'=> $ number ); – 2014-09-29 17:45:13