Php 取决于日期的条件CSS类

Php 取决于日期的条件CSS类,php,css,Php,Css,我试图创建一个无序列表(使用Wordpress插件高级自定义字段创建),其中所有日期早于30天的列表项都有一个不同的css类(因此我可以使用不同的样式)。考虑到这一点,有谁能告诉我如何编辑下面的代码,以便当每个li上第二个div中的子字段(日期)超过30天时,它会将更改为 见下面的代码: // check for rows <?php if( have_rows('item_list_details') ): ?> <ul

我试图创建一个无序列表(使用Wordpress插件高级自定义字段创建),其中所有日期早于30天的列表项都有一个不同的css类(因此我可以使用不同的样式)。考虑到这一点,有谁能告诉我如何编辑下面的代码,以便当每个
li
上第二个
div
中的
子字段(日期)
超过30天时,它会将
  • 更改为
  • 见下面的代码:

            // check for rows
            <?php if( have_rows('item_list_details') ): ?>
                <ul class="admin">
                <?php
                // loop through rows
                while( have_rows('item_list_details') ): the_row() 
                    // display each item as a list
                    ?>
                       <li class='new'>
                    <div class='itemTitle'>
                        <?php the_sub_field('link_name'); ?>
                    </div>
                    <div class="memberListDate">
                              <?php the_sub_field('date'); ?>
                         </div>
                       </li>   
                <?php endwhile; ?>
                </ul>
            <?php endif; ?>
    
    //检查行
    
    如有任何帮助,将不胜感激

    <li class='new'>
    
  • 
    
  • $diff的内容

    object(DateInterval)#3 (15) {
      ["y"]=>
      int(0)
      ["m"]=>
      int(0)
      ["d"]=>
      int(18)                        <-------d is relative to a single month
      ["h"]=>
      int(0)
      ["i"]=>
      int(0)
      ["s"]=>
      int(0)
      ["weekday"]=>
      int(0)
      ["weekday_behavior"]=>
      int(0)
      ["first_last_day_of"]=>
      int(0)
      ["invert"]=>
      int(1)
      ["days"]=>
      int(18)                        <--------days is the total days between
      ["special_type"]=>
      int(0)
      ["special_amount"]=>
      int(0)
      ["have_weekday_relative"]=>
      int(0)
      ["have_special_relative"]=>
      int(0)
    }
    
    对象(日期间隔)#3(15){
    [“y”]=>
    int(0)
    [“m”]=>
    int(0)
    [“d”]=>
    国际(18)
    int(0)
    [“i”]=>
    int(0)
    [“s”]=>
    int(0)
    [“工作日”]=>
    int(0)
    [“工作日行为”]=>
    int(0)
    [“第一天最后一天”]=>
    int(0)
    [“反转”]=>
    int(1)
    [“天”]=>
    国际(18)
    int(0)
    [“特别金额”]=>
    int(0)
    [“有工作日的亲戚”]=>
    int(0)
    [“有特殊关系”]=>
    int(0)
    }
    
    带有变量转储的原始代码

    ` “var_dump(get_sub_字段('age'));echo”“;?> 差异(日期)

    如果($diff->days>30):
    ?>
    
  • `
  • 子字段(..)的代码是什么样子的?这是一个日期格式的
    Ymd
    这就是你说的李斯特先生吗?谢谢你…非常有用。我能问一下:如果我要做“30天”吗“一个高级自定义字段实际上可以是不同的时间,如30天、60天或90天,并将该字段命名为‘年龄’。例如,您的代码中的if语句部分是否可以这样编写:
    if($diff->d>(the_sub_字段('age')):
    实际上,dynamic更像您建议的那样,因为它通常有两个原因,1)例如,减少重复文字值“30”的数量,以及2)消除任何没有充分自我解释的幻数。啊,有趣。我现在不在办公室,但会在周三调查,希望一切都会好起来。非常感谢你的帮助。试过了,但都
    好,整理好了!第一行应为“$date=new DateTime(get_sub_字段('date'));”通过将“the_sub_field”更改为“get_sub_field”,您可以将其包括在if语句中,而不只是打印它。谢谢,瓦赫
    
    object(DateInterval)#3 (15) {
      ["y"]=>
      int(0)
      ["m"]=>
      int(0)
      ["d"]=>
      int(18)                        <-------d is relative to a single month
      ["h"]=>
      int(0)
      ["i"]=>
      int(0)
      ["s"]=>
      int(0)
      ["weekday"]=>
      int(0)
      ["weekday_behavior"]=>
      int(0)
      ["first_last_day_of"]=>
      int(0)
      ["invert"]=>
      int(1)
      ["days"]=>
      int(18)                        <--------days is the total days between
      ["special_type"]=>
      int(0)
      ["special_amount"]=>
      int(0)
      ["have_weekday_relative"]=>
      int(0)
      ["have_special_relative"]=>
      int(0)
    }
    
                                    if ($diff->days > 30):
                                ?>
                                    <li class='research'>
                                <?php else: ?>
                                    <li class='researchLatest'>
                                <?php endif;?>`