隐藏在wordpress中显示的帖子

时间:2014-10-31 16:53:58

标签: php wordpress post hide

我继承了一个wordpress网站,我很难理解帖子的显示方式。我想从视图中隐藏一对(但仍然能够提供一个URL来查看它们)。我不熟悉特定模板的编码方式。模板为特定类别中的每个事件输出图像和模糊。吐出这个代码的代码看起来像这样:

<?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?任何提示或提示?感到非常困惑。变量在此代码段上方定义。如果需要,我可以发帖。

谢谢!

3 个答案:

答案 0 :(得分: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);
?>

答案 1 :(得分: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;
    ...

答案 2 :(得分:-1)

最简单的解决方案是从管理面板取消发布该帖子。

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

    <?php
    endif;
endwhile;   
?>