JoomGallery.net |图像排序升序

JoomGallery.net | image ordering asc

我想为我的艺术系学生使用这个简单的图片滑块作为 joomgallery:

https://github.com/danielhpavey/joomgallery-slider

唯一的问题是顺序。我如何获得按 ID 而不是按文件名排序的升序图像?

谢谢彼得

<?php
class images
{
    public function __construct()
    {
        $file = JPATH_ROOT. '/components/com_joomgallery/interface.php';
        if(!file_exists($file)){
            JError::raiseError(500, 'JoomGallery seems not to be installed');
        } else {
            require_once $file;
            $this ->interface = new JoomInterface();
        }
    }
    public function getFirstImage()
    {
        $images = $this ->talkToJoomgallery();
        return $images[0];
 
    }
    public function getImages()
    {
        $images = $this ->talkToJoomgallery();
        return $images;
    }
    public function talkToJoomgallery()
    {
        
        $images = $this ->interface ->getPicsByCategory( $this ->categoryid );
        $imagepath = $this ->joomgalleryImagePath();
        $theimages = array();
        $c = 0;
        foreach ($images as $i){
            $theimages[$c]=  array( 
                    'imgpath' => JURI::base() . $imagepath . $i->catpath . '/' . $i->imgfilename 
                    ,'imgtitle' => $i->imgtitle
                    ,'imgtext' => $i->imgtext
                    );
        
            $c ++;
        }
        shuffle($theimages);
                    
        return $theimages;
    }
    private function joomgalleryImagePath()
    {
        
        return $this ->interface ->getJConfig( 'jg_pathoriginalimages' );
    }
    public function __set($property, $value){
    $this->$property = $value;
    }
}

您的图片仅根据图片 ID 加载,但此命令正在重新索引数组,即 shuffle($theimages); 您可以通过

注释掉该行
//shuffle($theimages)

对于订购图像,您也可以在 helper.php 文件

中更改这一行
$images = $this->interface->getPicsByCategory($this->categoryid);

$images = $this->interface->getPicsByCategory($this->categoryid,null,'ordering' );

这将按照您在 joomla 管理员后端拖放图像的方式对图像进行排序。

根据您的最新查询进行更新

假设您想添加一个可以通过管理员控制的参数值(排序)。您需要更改 xml 文件 mod_joomgallery_slider.xml 只需像这样添加一个新字段

<field
 name = "sorting"
 type = "radio"
 label = "Sorting"
 description = "Sort by Ordering or random"
 default = "ordering"
 >
 <option value = "ordering">Ordering</option>
 <option value = "rand()">Random</option>
 </field>

接下来获取 helper.php 文件中的参数然后像这样更改函数 talkToJoomgallery()

public function talkToJoomgallery()
    {
        //Externally calling a module param
        jimport( 'joomla.html.parameter' );
        jimport( 'joomla.application.module.helper' );
        $module = JModuleHelper::getModule('mod_joomgallery_slider');
        $moduleParams = new JRegistry();
        $moduleParams->loadString($module->params);
        $sorting = $moduleParams->get( 'sorting' );

        $images = $this ->interface ->getPicsByCategory( $this ->categoryid,null,$sorting );
        $imagepath = $this ->joomgalleryImagePath();

        $theimages = array();
        $c = 0;
        foreach ($images as $i){
            $theimages[$c]=  array( 
                    'imgpath' => JURI::base() . $imagepath . $i->catpath . '/' . $i->imgfilename 
                    ,'imgtitle' => $i->imgtitle
                    ,'imgtext' => $i->imgtext
                    );

            $c ++;
        }
        //var_dump($theimages); exit;
        //shuffle($theimages);

        return $theimages;

    }

更新:在单个页面上显示 2 个滑块模块。

一些文件需要更改:

在 mod_joomgallery_slider.php 文件中更改顶部的这一行

include('helper.php');

include_once('helper.php');

这确保文件被包含一次。

另一个更改是删除 default.php 中的函数 imageText 并将其包含在 helper.php class 中,否则将抛出 function redeclaration error。但是现在 default.php 文件仍然报错,因为函数 imageText 没有被定义,但是你已经将该函数添加到 helper.php。所以 default.php 只有在你改变

时才会起作用
echo imageText( $i, $params );

echo $image->imageText( $i, $params );// You are calling helper object

记得更改 if 和 else 条件。