【发布时间】:2017-08-11 23:28:42
【问题描述】:
是否可以修改此代码以以相反的顺序返回类别(即首先显示最高 ID?)它当前首先显示具有最低 ID 的输出。非常感谢!
$imageCols = JRequest::getVar("imageCols");
$thumbWidth = JRequest::getVar("categoryThumbWidth", 4);
$columnWidth = floor(100 / $imageCols);
$document =JFactory::getDocument();
$document->addStyleSheet('components/com_groovygallery/css/groovygallery.css');
$document->addScript( JURI::base().'components/com_groovygallery/js/modernizr.custom.84782.js' );
$document->addScript( JURI::base().'components/com_groovygallery/js/masonry.pkgd.min.js' );
<?php if($this->params->get('show_page_heading')){?><h2><?php echo $this->params->get('page_heading');?></h2><?php } ?>
<div id="groovyGalleryCats" data-masonry-options='{ "columnWidth": 200, "itemSelector": ".groovyGalleryCat" }'>
<?php
foreach($this->categories as $key=>$category){
$params = json_decode($category->params);
$catImage = JURI::base().$params->image;
?>
<a class="groovyGalleryCat" href="<?php echo JRoute::_('index.php?option=com_groovygallery&view=images&filter_category='.$category->id); ?>" >
<?php if($params->image){ ?><img src="<?php echo JURI::base().'components/com_groovygallery/timthumb.php?src='. $catImage . '&zc=2&w='.$thumbWidth;?>" alt="<?php echo $category->title;?>" /> <?php } ?>
<?php echo $category->title;?>
<?php //echo $category->description;?>
</a>
<?php
}
?>
</div>
<style>
a.groovyGalleryCat {width:<?php echo $columnWidth;?>%;}
</style>
<script src="<?php echo JURI::base().'components/com_groovygallery/js/init-cat.js'; ?>" defer="defer"></script>
【问题讨论】:
-
在传递给视图之前只需对 $this->categories 进行排序,或者无论您从数据库中提取这些类别还是更好。或者,如果它们总是以相反的顺序排列,您可以使用 array_reverse 。
-
我认为你的是付费组件。当代码不在我们身边时,无法为您提供帮助。您尚未提供任何数据库代码。如果您可以分享该代码,我可以为您提供帮助。