0

我试图让一个页面按降序显示帖子(在 Wolf CMS 上),我认为我正在通过使用“if”语句的方式来破坏代码。如果我删除第一个页面,则页面显示正常,但顺序不正确。它将按升序显示。这是我的代码,任何人都可以发现我的功能障碍吗?:

    <?php $findTag = 'dinorun'; 
    $mychildren = $this->findById(4)->children(); 
    if ($mychildren->childrenCount() > 0) {
    $last_articles = $mychildren->children(array('limit'=>10, 'order'=>'page.created_on DESC'));
     foreach ($last_articles as $child) : 
    $childTags = join(',', $child->tags()); 
   if (strpos($childTags, $findTag) !== FALSE) : 
   ?>
    <ul class="blogpage">
     <?php echo $child->content(); 
      echo "<div class='postend'></div></ul>"; ?>
      <?php endif; ?>
    <?php endforeach; 

    ?>

编辑:我实际上没有那个额外的;那是个错误。删除它并没有改变。

这是我使用的原始代码,它按升序显示所有内容:

<?php $findTag = 'dinorun'; ?>
<?php $children = $this->findById(4)->children(); ?>
<ul class="blogpage">
<?php foreach ($children as $child) : ?>
<?php $childTags = join(',', $child->tags()); ?>
<?php if (strpos($childTags, $findTag) !== FALSE) : ?>
<?php; echo $child->content(); 
echo "<div class='postend'></div></ul>"; ?>
  <?php endif; ?>
<?php endforeach; ?>
4

2 回答 2

0

您需要将分号删除到

尝试这个

<?php $findTag = 'dinorun'; 
    $mychildren = $this->findById(4)->children(); 
    if ($mychildren->childrenCount() > 0) {
    $last_articles = $mychildren->children(array('limit'=>10, 'order'=>'page.created_on DESC'));
     foreach ($last_articles as $child) : 
    $childTags = join(',', $child->tags()); 
   if (strpos($childTags, $findTag) !== FALSE) : 
?>
    <ul class="blogpage">
     <?php echo $child->content(); 
      echo "<div class='postend'></div></ul>"; ?>
      <?php endif; ?>
    <?php endforeach; 

    ?>
于 2013-08-06T05:50:13.427 回答
0

试试这个代码,

    <?php $findTag = 'dinorun'; ?>
<?php $mychildren = $this->findById(4)->children(); 
if ($mychildren->childrenCount() > 0) {
    $last_articles = $mychildren->children(array('limit'=>10, 'order'=>'page.created_on DESC'));
    ?>
<?php foreach ($last_articles as $child) : ?>
<?php $childTags = join(',', $child->tags()); ?>
<?php if (strpos($childTags, $findTag) !== FALSE) : ?>
<ul class="blogpage">
    <?php 
        echo $child->content(); 
        echo "<div class='postend'></div></ul>"; 
    ?>
<?php endif; ?>
<?php endforeach; ?>
<?php }?>
于 2013-08-06T05:58:57.040 回答