如何调用标签并以降序(最新的第一个)顺序显示?

时间:2013-08-06 05:42:55

标签: php if-statement foreach content-management-system

我正在尝试按降序显示一个显示帖子(在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; ?>

2 个答案:

答案 0 :(得分: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; 

    ?>

答案 1 :(得分: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 }?>