我被赋予了修复由其他人创建的网站的可怕任务。我差点儿来,但是我遇到了绊脚石。
基本上,我有一个主页,应该在2行列布局中显示6个事件。如果在创建帖子时添加了 HOMEPAGE 属性,则该事件应仅显示在主页上。但是,现在每个帖子都添加到主页,无论是否添加了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
答案 0 :(得分:1)
首先,根据要求,我将分解此代码为您做的事情:
<?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; ?>
接下来,一些观察结果:
尝试使用此尺寸:
<?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; ?>