站点,忽略属性.有人能解释一下这个动作吗


Site, ignoring attribute. Could someone please explain this action

我被赋予了修复别人创建的网站的可怕任务。我几乎完成了它,但我遇到了一个绊脚石。

从本质上讲,我有一个主页,应该在2行、2列的布局中显示6个事件。只有在创建帖子时添加了homepage属性时,事件才应显示在主页上。然而,现在每个帖子都添加到主页中,无论是否添加了主页属性。

这是目前主页上的动作。我的PHP知识有限,所以有人能解释一下它被要求做什么吗?为什么它突然忽略了HOMEPAGE属性?

<?php if(is_front_page()): ?>
        <div id="eventBoxes">
            <ul>
            <?php $vReturn = eme_get_events_list('limit=6'); ?> 
            <?php 
                $vReturn = explode("</li>",$vReturn);
                foreach($vReturn as $item) {
                    if(strpos($item,'<div id="homepage">yes</div>') !== false) {
                        echo $item;
                    }
                }
            ?>
            </ul>
            <br class="clear" />

    <?php else: ?>
        <div id="content">
        <?php echo the_content(); ?>
        </div>          
    <?php endif; ?>

提前感谢!

编辑:这里有一个链接到这个动作输出的HTML;http://pastebin.com/Benmr0pd

首先,根据请求,我将分解此代码对您的作用:

<?php if (is_front_page()): ?>
  <!-- everything between the line above and <?ph p else: ?> is exectuted if it is the home page -->
    <div id="eventBoxes">
        <ul>
        <!-- this line populates the variable $vReturn with the result of the function eme_get_events_list() -->
        <?php $vReturn = eme_get_events_list('limit=6'); ?> 
        <?php 

            // split the string into an array, based on the <li> tags
            $vReturn = explode("</li>",$vReturn);
            foreach($vReturn as $item) {
                // loop the items
                if(strpos($item,'<div id="homepage">yes</div>') !== false) {
                    // display the item if it contains the string <div id="homepage">yes</div>
                    echo $item;
                }
            }
        ?>
        </ul>
        <br class="clear" />

<?php else: ?>
   <!-- stuff here is for when you're not on the home page -->
    <div id="content">
    <?php echo the_content(); ?>
    </div>          
<?php endif; ?>

接下来,一些观察结果:

  • 您的代码区分大小写。这可能是问题的根源
  • 您的代码将产生损坏的HTML

试试这个尺寸:

<?php if (is_front_page()): ?>
    <div id="eventBoxes">
        <ul>
<?php
  $vReturn = preg_split("#</li>#i", eme_get_events_list('limit=6'), 0, PREG_SPLIT_NO_EMPTY);
  foreach($vReturn as $item) {
    if (stripos($item,'<div id="homepage">yes</div>') !== false) {
      echo $item.'</li>';
    }
  }
?>
        </ul>
        <!-- you are almost certainly missing a </div> here -->
        <br class="clear" />

<?php else: ?>
   <!-- stuff here is for when you're not on the home page -->
    <div id="content">
    <?php echo the_content(); ?>
    </div>          
<?php endif; ?>