2014-10-31 87 views
0

我已經繼承了WordPress的網站,我很難理解如何顯示帖子。我想從視圖中隱藏一對夫婦(但仍能夠發佈一個URL來查看它們)。我不熟悉特定模板的編碼方式。該模板爲某個類別中的每個事件輸出一個圖像和blurb。這是吐出來​​的代碼肉是這樣的:隱藏帖子從wordpress中顯示

<?php 
$args['post_type']='seasonalevents'; 
$args['posts_per_page']=-1; 
$args['orderby'] = 'menu_order'; 

$activities = new WP_Query($args); 


while ($activities->have_posts()) : $activities->the_post(); 
$image_id = get_post_thumbnail_id(); 
    $image_url = wp_get_attachment_image_src($image_id,'thumb_345_154', true); 
?> 

有沒有什麼辦法可以在上面的代碼中排除帖子ID?任何提示或提示?感到完全被這個困惑。這些代碼片段上面定義了變量。如果需要,我可以發佈。

的感謝!

+0

是否已經查閱了該方法的函數引用? http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src – Rasclatt 2014-10-31 17:11:48

回答

2

工作WordPress的-Y的方式做這將是一個元素三下加個$ args數組你已經有了:

$args['post__not_in'] = array(123,456,789); 

其中123,456和789是您想要排除在此頁面上顯示的帖子的ID。

所以,你的整個代碼看起來像:

<?php 
$args['post_type']='seasonalevents'; 
$args['posts_per_page']=-1; 
$args['orderby'] = 'menu_order'; 
$args['post__not_in'] = array(123,456,789); 

$activities = new WP_Query($args); 


while ($activities->have_posts()) : $activities->the_post(); 
$image_id = get_post_thumbnail_id(); 
    $image_url = wp_get_attachment_image_src($image_id,'thumb_345_154', true); 
?> 
+0

謝謝!這是有道理的。這很奇怪,它起初工作,但如果你點擊季節性事件導航項目,它會顯示所有隱藏的帖子。在錨標籤中有幾件事情:你認爲這是重寫後置排除?data-type =「all-posts」data-taxnomy =「seasonalevents_category」data-post =「seasonalevents」 – Peachy 2014-10-31 18:32:40

+0

@佩奇,你可能有多個模板。上面正在編輯的php文件首先被使用,但是當你點擊季節性事件導航項時,它可能使用不同的php文件來顯示帖子。有一個非常好的wordpress插件叫做「What the file」,它會告訴你什麼(當你登錄時),什麼模板文件被用來顯示當前頁面。 – JakeParis 2014-10-31 19:42:30

+0

這似乎並不那麼 - 但你可能是對的。邊欄,其具有的資產淨值在裏面,有follwing代碼: 的$ args =陣列( \t '父'=> 28, \t '的OrderBy'=> 'menu_order', \t '分類'=> 'seasonalevents_category'); $ categories2 = get_categories($ args); 這可能是造成問題嗎? – Peachy 2014-11-05 20:37:15

-1

最簡單的解決方案是從管理面板取消發佈該帖子。

或者

<?php 
// The Loop 
while($query->have_posts()): 
    $query->the_post(); 
    if(get_the_ID()!=YOUR_POST_ID): 
    ?> 
    <!-- Show Post --> 

    <?php 
    endif; 
endwhile; 
?> 
1

是的,有! 您可以使用http://codex.wordpress.org/Function_Reference/get_the_ID 獲取當前帖子的ID我建議您查看'循環'以及它是什麼。

這段代碼應該做:-)

... 
$not_these = array(1, 2, 7 /* array with post id's you got somewhere */); 
while ($activities->have_posts()) : $activities->the_post(); 
    if(in_array(get_the_ID(), $not_these)) continue; 
    ...