Moving The Article <PREV NEXT> to Beez Template Override

Everything to do with Joomla! 1.5 templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Locked
User avatar
nomis
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Thu Oct 13, 2005 9:12 am
Location: UK

Moving The Article <PREV NEXT> to Beez Template Override

Post by nomis » Thu Jan 28, 2010 1:17 pm

This post assumes you're familia with template overrides...

I've been digging around looking for a solution for this and having referenced quite a few separate posts and have come up with a solution so thought would post it up here as others seem to be asking for similar functionality.

Note this is NOT for altering the pagination layout of a single article that you have split into seperate 'pages' using Pagebreak.

This is for when you view (Read more) a complete article from a category blog menu item and you then want to move to the previous <Prev or next Next> article in that category respecting the ordering set in your menu link.

Obviously this functionality comes built in with Joomla as part of:
/content/pagenavigation.php
which you can choose to show or hide in your menu editor - Parameters > Show Navigation

What I've done is copied the code from pagenavigation.php, adjusted where it grabs a few of the query variables and dumped it into the Beez default article template override.

I've not changed any of the styling or the table layout of the <Prev Next> - that's up to you and your needs but now it's in the template override it's the right place to deal with it rather than messing with core. (if you have your menu Show Navigation parameter set to Show you'll see it twice once from the Joomla core and once once the override so set this parameter to Hide)

You may also need to keep an eye on Joomla updates in case /content/pagenavigation.php is upgraded in a major way and the way that <Prev Next> is calculated is changed - these changes will then have to be migrated to your template override.

However for now here's <Prev Next> dropped into the bottom of the following Beez template override file:
/templates/beez/html/com_content/article/default.php

Code: Select all

<?php // @version $Id: default.php 11917 2009-05-29 19:37:05Z ian $
defined('_JEXEC') or die('Restricted access');
?>

<div id="page">

<?php if (($this->user->authorize('com_content', 'edit', 'content', 'all') || $this->user->authorize('com_content', 'edit', 'content', 'own')) && !($this->print)) : ?>
<div class="contentpaneopen_edit<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>">
	<?php echo JHTML::_('icon.edit', $this->article, $this->params, $this->access); ?>
</div>
<?php endif; ?>

<?php if ($this->params->get('show_page_title',1) && $this->params->get('page_title') != $this->article->title) : ?>
<h1 class="componentheading<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>">
        <?php echo $this->escape($this->params->get('page_title')); ?>
</h1>
<?php endif; ?>

<?php if ($this->params->get('show_title')) : ?>
<h2 class="contentheading<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>">
	<?php if ($this->params->get('link_titles') && $this->article->readmore_link != '') : ?>
	<a href="<?php echo $this->article->readmore_link; ?>" class="contentpagetitle<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>">
		<?php echo $this->escape($this->article->title); ?></a>
	<?php else :
		echo $this->escape($this->article->title);
	endif; ?>
</h2>
<?php endif; ?>

<?php if ((intval($this->article->modified) !=0 && $this->params->get('show_modify_date')) || ($this->params->get('show_author') && ($this->article->author != "")) || ($this->params->get('show_create_date'))) : ?>
<p class="articleinfo">
	<?php if (intval($this->article->modified) !=0 && $this->params->get('show_modify_date')) : ?>
	<span class="modifydate">
		<?php echo JText::sprintf('LAST_UPDATED2', JHTML::_('date', $this->article->modified, JText::_('DATE_FORMAT_LC2'))); ?>
	</span>
	<?php endif; ?>

	<?php if (($this->params->get('show_author')) && ($this->article->author != "")) : ?>
	<span class="createdby">
		<?php JText::printf('Written by', ($this->article->created_by_alias ? $this->escape($this->article->created_by_alias) : $this->escape($this->article->author))); ?>
	</span>
	<?php endif; ?>

	<?php if ($this->params->get('show_create_date')) : ?>
	<span class="createdate">
		<?php echo JHTML::_('date', $this->article->created, JText::_('DATE_FORMAT_LC2')); ?>
	</span>
	<?php endif; ?>
</p>
<?php endif; ?>

<?php if (!$this->params->get('show_intro')) :
	echo $this->article->event->afterDisplayTitle;
endif; ?>

<p class="buttonheading">
	<?php if ($this->print) :
		echo JHTML::_('icon.print_screen', $this->article, $this->params, $this->access);
	elseif ($this->params->get('show_pdf_icon') || $this->params->get('show_print_icon') || $this->params->get('show_email_icon')) : ?>
	<img src="<?php echo $this->baseurl ?>/templates/<?php echo $mainframe->getTemplate(); ?>/images/trans.gif" alt="<?php echo JText::_('attention open in a new window'); ?>" />
	<?php if ($this->params->get('show_pdf_icon')) :
		echo JHTML::_('icon.pdf', $this->article, $this->params, $this->access);
	endif;
	if ($this->params->get('show_print_icon')) :
		echo JHTML::_('icon.print_popup', $this->article, $this->params, $this->access);
	endif;
	if ($this->params->get('show_email_icon')) :
		echo JHTML::_('icon.email', $this->article, $this->params, $this->access);
	endif;
	endif; ?>
</p>

<?php if (($this->params->get('show_section') && $this->article->sectionid) || ($this->params->get('show_category') && $this->article->catid)) : ?>
<p class="iteminfo">
	<?php if ($this->params->get('show_section') && $this->article->sectionid) : ?>
	<span>
		<?php if ($this->params->get('link_section')) : ?>
			<?php echo '<a href="'.JRoute::_(ContentHelperRoute::getSectionRoute($this->article->sectionid)).'">'; ?>
		<?php endif; ?>
		<?php echo $this->escape($this->article->section); ?>
		<?php if ($this->params->get('link_section')) : ?>
			<?php echo '</a>'; ?>
		<?php endif; ?>
		<?php if ($this->params->get('show_category')) : ?>
			<?php echo ' - '; ?>
		<?php endif; ?>
	</span>
	<?php endif; ?>
	<?php if ($this->params->get('show_category') && $this->article->catid) : ?>
	<span>
		<?php if ($this->params->get('link_category')) : ?>
			<?php echo '<a href="'.JRoute::_(ContentHelperRoute::getCategoryRoute($this->article->catslug, $this->article->sectionid)).'">'; ?>
		<?php endif; ?>
		<?php echo $this->escape($this->article->category); ?>
		<?php if ($this->params->get('link_category')) : ?>
			<?php echo '</a>'; ?>
		<?php endif; ?>
	</span>
	<?php endif; ?>
</p>
<?php endif; ?>

<?php echo $this->article->event->beforeDisplayContent; ?>

<?php if ($this->params->get('show_url') && $this->article->urls) : ?>
<span class="small">
	<a href="<?php echo $this->escape($this->article->urls); ?>" target="_blank">
		<?php echo $this->escape($this->article->urls); ?></a>
</span>
<?php endif; ?>

<?php if (isset ($this->article->toc)) :
	echo $this->article->toc;
endif; ?>

<?php echo JFilterOutput::ampReplace($this->article->text); ?>

<?php
#########################################################################
//<Prev Next> Copied in from /content/pagenavigation.php
//Check for //MODIFIED to see which variables have been modified to reflect grabbing parameter from within the aritcle
		$db 		= & JFactory::getDBO();
		$user		= & JFactory::getUser();
		$nullDate	= $db->getNullDate();

		$date		=& JFactory::getDate();
		$config 	= & JFactory::getConfig();
		$now 		= $date->toMySQL();

		$uid 		= $this->article->id; //MODIFIED
		$option 	= 'com_content';
		$canPublish = $user->authorize('com_content', 'publish', 'content', 'all');

		if ($this->params->get('orderby_sec')) {
			$order_method = $this->params->get('orderby_sec');
		} else {
			$order_method = $this->params->get('orderby');
		}
		// additional check for invalid sort ordering
		if ( $order_method == 'front' ) {
			$order_method = '';
		}

		// Determine sort order
		switch ($order_method)
		{
			case 'date' :
				$orderby = 'a.created';
				break;

			case 'rdate' :
				$orderby = 'a.created DESC';
				break;

			case 'alpha' :
				$orderby = 'a.title';
				break;

			case 'ralpha' :
				$orderby = 'a.title DESC';
				break;

			case 'hits' :
				$orderby = 'a.hits';
				break;

			case 'rhits' :
				$orderby = 'a.hits DESC';
				break;

			case 'order' :
				$orderby = 'a.ordering';
				break;

			case 'author' :
				$orderby = 'a.created_by_alias, u.name';
				break;

			case 'rauthor' :
				$orderby = 'a.created_by_alias DESC, u.name DESC';
				break;

			case 'front' :
				$orderby = 'f.ordering';
				break;

			default :
				$orderby = 'a.ordering';
				break;
		}

		$xwhere = ' AND ( a.state = 1 OR a.state = -1 )' .
		' AND ( publish_up = '.$db->Quote($nullDate).' OR publish_up <= '.$db->Quote($now).' )' .
		' AND ( publish_down = '.$db->Quote($nullDate).' OR publish_down >= '.$db->Quote($now).' )';

		// array of articles in same category correctly ordered
		$query = 'SELECT a.id,'
		. ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'
		. ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug'
		. ' FROM #__content AS a'
		. ' LEFT JOIN #__categories AS cc ON cc.id = a.catid'
		. ' WHERE a.catid = ' . (int) $this->article->catid
		. ' AND a.state = '. (int) $this->article->state
		. ($canPublish ? '' : ' AND a.access <= ' .(int) $user->get('aid', 0))
		. $xwhere
		. ' ORDER BY '. $orderby; //MODIFIED $this->article->catid and $this->article->state
		$db->setQuery($query);
		$list = $db->loadObjectList('id');
				// this check needed if incorrect Itemid is given resulting in an incorrect result
		if ( !is_array($list) ) {
			$list = array();
		}

		reset($list);

		// location of current content item in array list
		$location = array_search($uid, array_keys($list));

		$rows = array_values($list);
		$row->prev = null;
		$row->next = null;

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

		$pnSpace = "";
		if (JText::_('&lt') || JText::_('&gt')) {
			$pnSpace = " ";
		}

		if ($row->prev) {
			$row->prev = JRoute::_(ContentHelperRoute::getArticleRoute($row->prev->slug, $row->prev->catslug));
		} else {
			$row->prev = '';
		}

		if ($row->next) {
			$row->next = JRoute::_(ContentHelperRoute::getArticleRoute($row->next->slug, $row->next->catslug));
		} else {
			$row->next = '';
		}


		// output
		if ($row->prev || $row->next)
		{
			$html = '
			<table align="center" class="pagenav">
			<tr>'
			;
			if ($row->prev)
			{
				$html .= '
				<th class="pagenav_prev">
					<a href="'. $row->prev .'">'
						. JText::_( '&lt' ) . $pnSpace . JText::_( 'Prev' ) . '</a>
				</th>'
				;
			}

			if ($row->prev && $row->next)
			{
				$html .= '
				<td width="50">&nbsp;
					
				</td>'
				;
			}

			if ($row->next)
			{
				$html .= '
				<th class="pagenav_next">
					<a href="'. $row->next .'">'
						. JText::_( 'Next' ) . $pnSpace . JText::_( '&gt' ) .'</a>
				</th>'
				;
			}
			$html .= '
			</tr>
			</table>'
			;

			// Get the plugin parameters
			$pluginParams = new JParameter( $plugin->params );
			$position 	 = $pluginParams->get('position', 1);

			if ($position) {
			// display after content
				$row->text .= $html;
			} else {
			// display before content
				$row->text = $html . $row->text;
			}
		}
	echo $html;
#########################################################################
?>

<?php echo $this->article->event->afterDisplayContent; ?>

</div>

gdanx
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Tue Jan 17, 2006 11:30 pm

Re: Moving The Article <PREV NEXT> to Beez Template Override

Post by gdanx » Sat Feb 05, 2011 6:23 pm

thank you for this, it helped me alot! :)

shahzadkhanz
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Fri Jun 10, 2011 5:05 am

Re: Moving The Article <PREV NEXT> within categories

Post by shahzadkhanz » Tue Jul 05, 2011 9:29 am

Hi,

I want page navigation categories articles. Please help me. Its urgent

Thanks
Shahzad


Locked

Return to “Templates for Joomla! 1.5”