2016-06-27 12 views
1

JoomGallery.net |私は私の芸術の学生のためjoomgalleryため、このシンプルなイメージスライダーを使用したい画像の順序ASC

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]; 
 
\t 
 
    } 
 
    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; 
 
    } 
 
}

答えて

0

あなたのイメージは、イメージIDに応じてロードされるが、このコマンドは、shuffle($theimages)すなわちアレイを再インデックスされます。あなたは、これは、の順序付けを行いますあなたは

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

にhelper.phpファイルに

$images = $this->interface->getPicsByCategory($this->categoryid); 

をこの行を変更することができ、画像を注文するためにも

//shuffle($theimages) 

によってその行をコメントアウトすることができます あなたがジョムラの管理者のバックエンドで画像をドラッグアンドドロップしたやり方をイメージします。最新のQUERY

PER AS

UPDATEを使用すると、管理者によって制御することができるのparam値(ソート)を追加するとします。あなたはmod_joomgallery_slider.xml はちょうどその時、この

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; 

    } 
のような機能talkToJoomgallery()を変更helper.phpファイル内のparamを取得するには、この

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

次のように新しいフィールドを追加xmlファイルを変更することが定義さ

UPDATE:1つのページに2つのスライダモジュールを表示します。

いくつかのファイルが変更されている必要があります

mod_joomgallery_slider.phpファイルの変更では、このラインをトップ

include('helper.php'); 

include_once('helper.php'); 

これは、ファイルを一度に含まれていることを保証します。

default.phpにあるimageTextの機能を削除し、それをhelper.phpクラスに追加すると、function redeclaration errorがスローされます。しかし、今度はdefault.phpファイルがエラーを返しますが、関数imageTextは定義されませんが、すでにその関数をhelper.phpに追加しています。だからデフォルト。あなたは

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

あれば、他の条件の両方に変更することを忘れないように

echo imageText($i, $params); 

を変更した場合、PHPのみ動作します。

+0

お返事ありがとうございました。多分私の質問はちょっと混乱していたかもしれません。私はすでにシャッフル($ theimages)が画像をファイル名でシャッフルすることに気付きました。そこで私はjoomgallery自体の注文を確実に得るために、 "idによる画像の昇順"の解決策を求めました。私が必要とするのは、スライダーがjoomgalleryの画像/画像の順番を取ることです。ドラッグアンドドロップで順序を変更すると、スライドショーの順序が変わります。ありがとうpeter –

+0

@ PeterReillもう一度答えを確認してください、私はあなたの要件に従ってそれを変更しました。 –

+0

この素晴らしいコードをありがとう。できます! –

関連する問題