如何调用标记并按降序(最新的第一个)显示


How can I call a tag and display in descending (newest first) order?

我正试图获得一个按降序显示帖子的页面(在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; ?>

您需要将分号删除到

试试这个

<?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 $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 }?>