どのようにしてループページネーションを実現できますか? 5つの記事があり、ページ付けを追加し、1ページ目に「次へ」ボタンがあります。2〜4ページに、「次へ」ボタンと「前へ」ボタンの両方があります。最後の5ページ目にあります。 「前へ」ボタンしかありません。すべてのページに「次へ」ボタンと「前へ」ボタンの両方を配置するにはどうすればよいですか?したがって、5ページ目に到達して「次へ」を押すと、ループやサークルのように、1ページ目に移動します。
記事のページ付けは、_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つの方法があります。
plg_pagenavigation
_に基づいて新しいプラグインを作成し、編集を適用します。次に、新しいプラグインを公開し、pagenavigation
を非公開にします。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
_を検索し、存在する場合はオーバーライドとして使用します。それはまだコアハックですが、維持する方が簡単かもしれません。