The Joomla! Forum ™





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 17 posts ] 
Author Message
PostPosted: Fri May 25, 2007 10:15 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Jan 06, 2007 11:57 pm
Posts: 37
Hi, in all articles there are next and prev article buttons, is there any way to have instead the buttons the title of the next and prev article? This would be more user-friendly i think and more SEO.

thanks in advance

_________________
http://www.neohw.com


Top
 Profile  
 
PostPosted: Fri May 25, 2007 10:54 pm 
User avatar
Joomla! Exemplar
Joomla! Exemplar

Joined: Fri Aug 12, 2005 7:19 am
Posts: 9205
Location: Leeds, UK
Sorry I've not seen anything that does that but it sounds a good idea.

_________________
"Exploited yesterday... Hacked tomorrow"
Blog http://brian.teeman.net/
Joomla Hidden Secrets http://hiddenjoomlasecrets.com/


Top
 Profile  
 
PostPosted: Sun May 27, 2007 4:23 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun May 27, 2007 2:07 pm
Posts: 16
Location: Singapore
hi i need to change my readmore button in newsflash to othernews?
do u have any idea?

_________________
thanks,
Dilip


Top
 Profile  
 
PostPosted: Sun May 27, 2007 8:29 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Jan 06, 2007 11:57 pm
Posts: 37
Open a new topic, please. You're Off Topic.

_________________
http://www.neohw.com


Top
 Profile  
 
PostPosted: Mon May 28, 2007 2:12 am 
User avatar
Joomla! Guru
Joomla! Guru

Joined: Wed Nov 16, 2005 2:02 am
Posts: 588
Location: Breklum - Nordfriesland
That's not a big deal.

In components/com_content/content.php replace the code from line 1490 to the end of the if statement in the function showItem()  by the following:
Code:
            // array of content items in same category correctly ordered
            $query = "SELECT a.id, a.title"
            . "\n FROM #__content AS a"
            . "\n WHERE a.catid = " . (int) $row->catid
            . "\n AND a.state = " . (int) $row->state
            . ($access->canEdit ? '' : "\n AND a.access <= " . (int) $gid )
            . $xwhere
            . "\n ORDER BY $orderby"
            ;
            $database->setQuery( $query );
            $list = $database->loadObjectList();

            // this check needed if incorrect Itemid is given resulting in an incorrect result
            if ( !is_array($list) ) {
                $list = array();
            }
            // location of current content item in array list
            $prev    = null;
            $current = array_shift( $list );
            $next    = array_shift( $list );
            while ( $current->id != $uid ) {
                $prev    = $current;
                $current = $next;
                $next    = array_shift( $list );
            }
            $row->prev = '';
            $row->next = '';
            if ( !empty( $prev ) ) {
                $row->prev       = $prev->id;
                $row->prev_title = $prev->title;
            }
            if ( !empty( $next ) ) {
                $row->next       = $next->id;
                $row->next_title = $next->title;
            }
        }

        // page title


Next, replace two lines of the method Navigation() in components/com_content/content.html.php, i.e. line 921
Code:
                            <?php echo _ITEM_PREVIOUS, $row->prev_title; ?></a>


and line 938:
Code:
                            <?php echo $row->next_title, _ITEM_NEXT; ?></a>


Last thing to do is to set the constants _ITEM_PREVIOUS and _ITEM_NEXT in your language file in a way that makes sense. I use
Code:
DEFINE('_ITEM_PREVIOUS','< ');
DEFINE('_ITEM_NEXT',' >');


If you don't want to edit the code yourself, I have added both files as an attachment. Just copy the files over the existing ones. Don't forget to make a backup first!


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
PostPosted: Mon May 28, 2007 7:49 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Jan 06, 2007 11:57 pm
Posts: 37
Great! thanks  ;D, i love this forum and support, simply and fast  ;)

_________________
http://www.neohw.com


Top
 Profile  
 
PostPosted: Mon Aug 06, 2007 12:46 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Thu Nov 23, 2006 11:37 am
Posts: 462
Yes, no posts for at least 30 days and I do want to reply. A belated compliment to Nibra ... Simple and elegant, well-documented. Nibra RULES!!

Just a tip for others to even further benefit from Nibra's great logical mind. Instead of "just" showing the Prev/next articles' titles, you may even consider adding (ehm..) author, title_alias, publication/lastmod date or META to either the hyperlink text or (what I did) to the hyperlink alt/title attribute.

For instance, to use title_alias, metakey and metadesc just add them to the query in /components/com_content/content.php like this
Code:
// array of content items in same category correctly ordered
            $query = "SELECT a.id, a.title, a.title_alias, a.metakey, a.metadesc"


A bit down also add them here like this
Code:
            if ( !empty( $prev ) ) {
                $row->prev       = $prev->id;
                $row->prev_title = $prev->title;
                $row->prev_title_alias = $prev->title_alias;
                $row->prev_metakey = $prev->metakey;
                $row->prev_metadesc = $prev->metadesc;
            }
            if ( !empty( $next ) ) {
                $row->next       = $next->id;
                $row->next_title = $next->title;
                $row->next_title_alias = $next->title_alias;
                $row->next_metakey = $next->metakey;
                $row->next_metadesc = $next->metadesc;


Then in the file /components/com_content/content.html.php use them any way you want, such as i.e. put the title_alias in the hyperlinks title tag by doing this
Code:
<th class="pagenav_prev">
   <a title="<?php echo $row->prev_title_alias; ?>" href="<?php echo $row->prev; ?>"><?php echo $row->prev_title; ?><span class="prevnext_small"><?php echo _ITEM_PREVIOUS;?></span></a>
</th>


O, never mind the span class there, that just me. Also sorry I left out the line numbers. My line numbers are completely messed up anyway with all the mods. See Nibra's original post.

Naturally you can use other php to just fill the string, i.e. in pseudo code
HYPERLINK_TITLE_ATT = ''

if title_alias not empty
add title_alias tot the HYPERLINK_TITLE_ATT
/if

if metadesc not empty
strip to set number of characters
add to HYPERLINK_TITLE_ATT
else
  $metaexist = false;
/if

then do your thing with pseudo codesomething

or perhaps even pseudocode
if $metaexist = false && user has edit rights
echo HEY DUDE YOU FORGOT THE METADATA FOR THE (prev\next) ARTICLE something

else
echo something
/if

_________________
In Chinese the word 'crisis' consists of two characters. One means 'danger,' the other 'opportunity.'


Last edited by theLoneDeranger on Mon Aug 06, 2007 12:49 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Mon Nov 26, 2007 8:28 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Jan 06, 2007 11:57 pm
Posts: 37
What about the navigation between pages of the same article? I use a mambot (mospaging_scrool) to show pages in an horizontal box wich allows to select pages to load.

It also replaces the prev and next button to navigate between pages ot the same article, do vou think that the anchor text for next and prev links could be change with the next/prev page title?

Here's the code of the mambot.
The part wich interests me is:
Quote:
  $row->text .= '
' . $prev . ' - ' . $next .'
';

All the code...
Quote:

/**

* @version $Id: mospaging.php 2574 2006-02-23 18:48:16Z stingrey $

* @package Joomla

* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.

* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php

* Joomla! is free software. This version may have been modified pursuant

* to the GNU General Public License, and as distributed it includes or

* is derivative of works licensed under the GNU General Public License or

* other free or open source software licenses.

* See COPYRIGHT.php for copyright notices and details.

*

*Fonction enhanced by inetis Sarl, http://www.inetis.ch

*/



// no direct access

defined( '_VALID_MOS' ) or die( 'Restricted access' );



$_MAMBOTS->registerFunction( 'onPrepareContent', 'botMosPaging_scroll' );



/**

* Page break mambot

*

* Usage:

* {mospagebreak_scroll}

* {mospagebreak_scroll title=The page title}

* or

* {mospagebreak_scroll heading=The first page}

* or

* {mospagebreak_scroll title=The page title&heading=The first page}

* or

* {mospagebreak_scroll heading=The first page&title=The page title}

*

*/

function botMosPaging_scroll( $published, &$row, &$params, $page=0 ) {

global $mainframe, $Itemid, $database, $_MAMBOTS;



// simple performance check to determine whether bot should process further

if ( strpos( $row->text, 'mospagebreak_scroll' ) === false ) {

return true;

}



// expression to search for

$regex = '/{(mospagebreak_scroll)\s*(.*?)}/i';



// check whether mambot has been unpublished

if (!$published || $params->get( 'intro_only' )|| $params->get( 'popup' )) {

$row->text = preg_replace( $regex, '', $row->text );

return;

}



// find all instances of mambot and put in $matches

$matches = array();

preg_match_all( $regex, $row->text, $matches, PREG_SET_ORDER );



// split the text around the mambot

$text = preg_split( $regex, $row->text );



// count the number of pages

$n = count( $text );



// we have found at least one mambot, therefore at least 2 pages

if ($n > 1) {

// check if param query has previously been processed

if ( !isset($_MAMBOTS->_content_mambot_params['mospaging']) ) {

// load mambot params info

$query = "SELECT params"

. "\n FROM #__mambots"

. "\n WHERE element = 'mospaging_scroll'"

. "\n AND folder = 'content'"

;

$database->setQuery( $query );

$database->loadObject($mambot);



// save query to class variable

$_MAMBOTS->_content_mambot_params['mospaging_scroll'] = $mambot;

}



// pull query data from class variable

$mambot = $_MAMBOTS->_content_mambot_params['mospaging_scroll'];



$botParams = new mosParameters( $mambot->params );



$title = $botParams->def( 'title', 1 );



// adds heading or title to Title

if ( $title ) {

$page_text = $page + 1;

$row->page_title = _PN_PAGE .' '. $page_text;

if ( !$page ) {

// processing for first page

parse_str( html_entity_decode( $matches[0][2] ), $args );



if ( @$args['heading'] ) {

//$row->page_title = $args['heading'];

$row->page_title = '';

} else {

$row->page_title = '';

}

} else if ( $matches[$page-1][2] ) {

parse_str( html_entity_decode( $matches[$page-1][2] ), $args );



if ( @$args['title'] ) {

$row->page_title = ': '. stripslashes( $args['title'] );

}

}

}



// reset the text, we already hold it in the $text array

$row->text = '';



$hasToc = $mainframe->getCfg( 'multipage_toc' );



if ( $hasToc ) {

// display TOC

createTOC_scroll( $row, $matches, $page );

} else {

$row->toc = '';

}



// traditional mos page navigation

require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php' );

$pageNav = new mosPageNav( $n, $page, 1 );



// page counter

$row->text .= '';



// page text

$row->text .= $text[$page];



$row->text .= '
';

$row->text .= '
';

}



return true;

}



function createTOC_scroll( &$row, &$matches, &$page ) {

global $Itemid;



$limitstart = mosGetParam( $_REQUEST, 'limitstart');



$nonseflink = 'index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $Itemid;

$link = 'index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $Itemid;

$link = sefRelToAbs( $link );



$heading = $row->title;

// allows customization of first page title by checking for `heading` attribute in first bot

if ( @$matches[0][2] ) {

parse_str( html_entity_decode( $matches[0][2] ), $args );



if ( @$args['heading'] ) {

$heading = $args['heading'];

$row->title .= ' - '. $heading;

}

}

// TOC Header

$row->toc = '





';

}

// pour la navigation de bas de page

function createNavigation_scroll( &$row, $page, $n ) {

global $Itemid;



$link = 'index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $Itemid;



if ( $page < $n-1 ) {

$link_next = $link .'&limit=1&limitstart='. ( $page + 1 );

$link_next = sefRelToAbs( $link_next );



$next = '' ._CMN_NEXT . _CMN_NEXT_ARROW .'';

} else {

$next = _CMN_NEXT;

}



if ( $page > 0 ) {

$link_prev = $link .'&limit=1&limitstart='. ( $page - 1 );

$link_prev = sefRelToAbs( $link_prev );



$prev = ''. _CMN_PREV_ARROW . _CMN_PREV .'';

} else {

$prev = _CMN_PREV;

}



$row->text .= '
' . $prev . ' - ' . $next .'
';

}

?>


_________________
http://www.neohw.com


Top
 Profile  
 
PostPosted: Thu Oct 16, 2008 4:26 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Thu Oct 16, 2008 4:23 pm
Posts: 4
Hi all - as this post is quite old - I'm using Joomla V 1.5.7 and the content.php file only has around 40 lines, not 1400.

Please can someone highlight how to update the prev and next links to state their associated titles dynamically instead.

Many thanks,
Sean


Top
 Profile  
 
PostPosted: Tue Nov 18, 2008 2:08 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Thu Oct 16, 2008 4:23 pm
Posts: 4
Can someone please help?


Top
 Profile  
 
PostPosted: Wed Nov 19, 2008 1:49 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Dec 26, 2007 12:30 pm
Posts: 13
Ditto that 'please'.
And, how to change << Prev - Next >> at the bottom of a multi-page article to read << Previous - Next Part of Article>>.
Thanks all.


Top
 Profile  
 
PostPosted: Tue Jan 06, 2009 9:36 am 
Joomla! Intern
Joomla! Intern

Joined: Sat Nov 22, 2008 2:18 pm
Posts: 62
Hi
You just go to plugins then Content - Page Navigation and change the setting.
i hope i could help you.


Top
 Profile  
 
PostPosted: Thu Feb 19, 2009 3:58 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Tue Sep 25, 2007 1:54 pm
Posts: 2
I just applied this mod to a site of mine, works great except there is no space between prev & article title and next & article title.

For example: < PrevArticle Title Article TitleNext >

Any help?

Thanks.


Top
 Profile  
 
PostPosted: Thu May 14, 2009 7:55 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Feb 13, 2009 10:58 am
Posts: 15
Location: Staffordshire, England
Hi, When i navigate to some pages with the standard prev and next buttons with Joomla 1.5.4 and SH404SEF i get cat= added to the end of the new urls. Anyone got any idea how to resolve this please?


Top
 Profile  
 
PostPosted: Tue Apr 20, 2010 2:22 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Mon Jan 07, 2008 4:46 pm
Posts: 124
I can't believe this topic is so old and no one has had this problem since. My navigation links only say "Prev" and "Next" and I really need them to include the title of the previous and next article, otherwise they are essentially useless for both users and search engines. I see no options for adding the title in the plugin parameters and I'm not sure how to change the code since the suggestions above were made several years ago and I'm now using Joomla 1.5.14. Does anyone have more recent information on how to achieve this?


Top
 Profile  
 
PostPosted: Tue Apr 20, 2010 2:38 pm 
User avatar
Joomla! Exemplar
Joomla! Exemplar

Joined: Fri Aug 12, 2005 7:19 am
Posts: 9205
Location: Leeds, UK
Check the joomla extensions directory as there are solutions available

_________________
"Exploited yesterday... Hacked tomorrow"
Blog http://brian.teeman.net/
Joomla Hidden Secrets http://hiddenjoomlasecrets.com/


Top
 Profile  
 
PostPosted: Tue Apr 20, 2010 2:59 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Mon Jan 07, 2008 4:46 pm
Posts: 124
Ok thanks! The one plugin is in Chinese so i couldn't figure that one out but the PageNav one works great (except yeah there's no space between the article title and the "prev"/"next" but as they say good enough for government work! lol)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 17 posts ] 



Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group