doufang2228 2014-03-23 14:52
浏览 21

在Wordpress中显示具有特定元值的帖子

I have a function which display posts of a custom post type in wordpress:

Code:

<?php
 $args = array(
              'post_type' => 'todo_listing',
              'posts_per_page' => 4,
              'order' => 'asc',
              'meta_value' => '0'
              );
 $loop = new WP_Query( $args );
 ?>     

 <ul class="leftlist">

<?php
while ( $loop->have_posts() ) : $loop->the_post();
?>

        <li class="todo" id="<?php echo get_the_ID();?>" itemage="<?php echo get_post_meta(get_the_ID(),'_todotime',true)?>"><a href="javascript:;"<?php if($all_meta_for_user[get_the_ID()][0]){               
        ?>
        class="strike"

    <?php
}
?>
       >           
  <?php if($all_meta_for_user[get_the_ID()][0]){?>
            <span class="check_box cb"></span>
            <?php }else{?>
        <span class="uncheck_box cb"></span>
        <?php }?>   
        <p><?php the_title(); ?></p></a>           
        <?php
        endwhile;
        ?>            
        </ul>

Which results in the HTML rendered as follows:

<li class="todo" id="1013" itemage=""><a href="javascript:;" class="">
    <span class="cb uncheck_box"></span>
    <p>Some Text here</p></a>
</li> 

or

<li class="todo" id="1013" itemage=""><a href="javascript:;" class="">
    <span class="check_box"></span>
    <p>Some Text here</p></a>
</li>

If the class has span class="cb uncheck_box" the meta value is 0 and if the span class="check_box", meta value is 1.

I only want to show those items with Meta Value 1. How can I modify the above wordpress function to achieve this?

  • 写回答

2条回答 默认 最新

  • dougu2240 2014-03-23 15:11
    关注

    Here is the code you can use:

    <?php
    $args = array(
              'post_type' => 'todo_listing',
              'posts_per_page' => 4,
              'order' => 'asc',
              'meta_value' => '0'
              );
     $loop = new WP_Query( $args );
    ?>     
    
    <?php
    while ( $loop->have_posts() ) : $loop->the_post();
    ?>
    <?php if(get_post_meta(get_the_ID(), 'checkbox_meta', true) == 0) { ?>
    <?php echo get_the_ID();?> <?php the_title(); ?>
    <?php } ?>
    
    <?php
    endwhile;
    ?>  
    

    I think there is some detail that you have missed to give out but assuming the code <?php echo get_the_ID();?> <?php the_title(); ?> prints out the given html then I suppose this could work. Get back to me if it couldn't be solved.

    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗