web-dev-qa-db-ja.com

開始または終了のないJoomlaページネーションループ

どのようにしてループページネーションを実現できますか? 5つの記事があり、ページ付けを追加し、1ページ目に「次へ」ボタンがあります。2〜4ページに、「次へ」ボタンと「前へ」ボタンの両方があります。最後の5ページ目にあります。 「前へ」ボタンしかありません。すべてのページに「次へ」ボタンと「前へ」ボタンの両方を配置するにはどうすればよいですか?したがって、5ページ目に到達して「次へ」を押すと、ループやサークルのように、1ページ目に移動します。

3
be well

記事のページ付けは、_ROOT/plugins/content/pagenavigation_にあるpagenavigationというコンテンツプラグインによって処理されます。問題は Joomlaはプラグインのオーバーライドを許可します ですが、この特定のプラグインを含むほとんどのプラグインはそれをサポートしていません。どちらの方法でも、変更する必要があるコードは、前述のフォルダー(約行#174)の_pagenavigation.php_にあります。

既存のコードを変更します。

_        if ($location - 1 >= 0)
        {
            // The previous content item cannot be in the array position -1.
            $row->prev = $rows[$location - 1];
        }

        if (($location + 1) < count($rows))
        {
            // The next content item cannot be in an array position greater than the number of array postions.
            $row->next = $rows[$location + 1];
        }
_

これで:

_        if ($location - 1 >= 0)
        {
            // The previous content item cannot be in the array position -1.
            $row->prev = $rows[$location - 1];
        } else {
            // Add button to return to last element
            $row->prev = $rows[count($rows)-1];
        }

        if (($location + 1) < count($rows))
        {
            // The next content item cannot be in an array position greater than the number of array postions.
            $row->next = $rows[$location + 1];
        } else {
            // Add button to return to start
            $row->next = $rows[0];
        }
_

私の知る限り、これを解決するには3つの方法があります。

  1. 上記のように、元のファイルを編集します。これはコアハックと呼ばれ、Joomlaを更新すると編集内容が上書きされる可能性があるためお勧めしません。
  2. 既存の_plg_pagenavigation_に基づいて新しいプラグインを作成し、編集を適用します。次に、新しいプラグインを公開し、pagenavigationを非公開にします。
  3. defined('_JEXEC') or die;の直後にこのコードを_ROOT/plugins/content/pagenavigation/pagenavigation.php_に追加して、プラグインをプラグインオーバーライドと互換性のあるものにします。

    _$chromePath = JPATH_THEMES . '/' . JFactory::getApplication()->getTemplate() . '/html/pagenavigation.php';
    if (file_exists($chromePath))
    require_once ($chromePath);
    
    if (!function_exists('plgContentNavigation')) {
      function plgContentNavigation( &$row, &$params, $page=0 )
      {
    _

    次に、これはファイルの最後にあります。

    _ }
    }
    _

    これにより、Joomlaはファイル_ROOT/templates/YOURTEMPLATE/html/pagenavigation.php_を検索し、存在する場合はオーバーライドとして使用します。それはまだコアハックですが、維持する方が簡単かもしれません。

2
johanpw