Next and Prev article title, instead of only navigation buttons
-
- Joomla! Apprentice
- Posts: 37
- Joined: Sat Jan 06, 2007 11:57 pm
- Contact:
Next and Prev article title, instead of only navigation buttons
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
thanks in advance
- brian
- Joomla! Master
- Posts: 12787
- Joined: Fri Aug 12, 2005 7:19 am
- Location: Leeds, UK
- Contact:
Re: Next and Prev article title, instead of only navigation buttons
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/
Blog http://brian.teeman.net/
Joomla Hidden Secrets http://hiddenjoomlasecrets.com/
- dilipk
- Joomla! Apprentice
- Posts: 16
- Joined: Sun May 27, 2007 2:07 pm
- Location: Singapore
- Contact:
Re: Next and Prev article title, instead of only navigation buttons
hi i need to change my readmore button in newsflash to othernews?
do u have any idea?
do u have any idea?
thanks,
Dilip
Dilip
-
- Joomla! Apprentice
- Posts: 37
- Joined: Sat Jan 06, 2007 11:57 pm
- Contact:
Re: Next and Prev article title, instead of only navigation buttons
Open a new topic, please. You're Off Topic.
- nibra
- Joomla! Guru
- Posts: 588
- Joined: Wed Nov 16, 2005 2:02 am
- Location: Breklum - Nordfriesland
- Contact:
Re: Next and Prev article title, instead of only navigation buttons
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:
Next, replace two lines of the method Navigation() in components/com_content/content.html.php, i.e. line 921
and line 938:
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
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!
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: Select all
// 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
Code: Select all
<?php echo _ITEM_PREVIOUS, $row->prev_title; ?></a>
and line 938:
Code: Select all
<?php echo $row->next_title, _ITEM_NEXT; ?></a>
Code: Select all
DEFINE('_ITEM_PREVIOUS','< ');
DEFINE('_ITEM_NEXT',' >');
You do not have the required permissions to view the files attached to this post.
-
- Joomla! Apprentice
- Posts: 37
- Joined: Sat Jan 06, 2007 11:57 pm
- Contact:
Re: Next and Prev article title, instead of only navigation buttons
Great! thanks , i love this forum and support, simply and fast
- theLoneDeranger
- Joomla! Explorer
- Posts: 462
- Joined: Thu Nov 23, 2006 11:37 am
Re: Next and Prev article title, instead of only navigation buttons
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
A bit down also add them here like this
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
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
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: Select all
// array of content items in same category correctly ordered
$query = "SELECT a.id, a.title, a.title_alias, a.metakey, a.metadesc"
Code: Select all
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;
Code: Select all
<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>
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
Last edited by theLoneDeranger on Mon Aug 06, 2007 12:49 pm, edited 1 time in total.
In Chinese the word 'crisis' consists of two characters. One means 'danger,' the other 'opportunity.'
-
- Joomla! Apprentice
- Posts: 37
- Joined: Sat Jan 06, 2007 11:57 pm
- Contact:
Re: Next and Prev article title, instead of only navigation buttons
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:
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:
All the code...$row->text .= '' . $prev . ' - ' . $next .'';
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 .= '';
$row->text .= $pageNav->writeLeafsCounter();
$row->text .= '';
// page text
$row->text .= $text[$page];
$row->text .= '
';
$row->text .= '';
// adds navigation between pages to bottom of text
if ( $hasToc ) {
createNavigation_scroll( $row, $page, $n );
}
// page links shown at bottom of page if TOC disabled
if (!$hasToc) {
$row->text .= $pageNav->writePagesLinks( 'index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $Itemid );
}
$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 = '
'._TOC_JUMPTO.'';
// TOC First Page link
$row->toc .= '
1. Introduzione';
$i = 2;
$args2 = array();
$limitstart = mosGetParam( $_REQUEST, 'limitstart');
foreach ( $matches as $bot ) {
$link = $nonseflink .'&limit=1&limitstart='. ($i-1);
$link = sefRelToAbs( $link );
if ($limitstart==$i-1)
$selected = "selected";
else
$selected = "";
if ( @$bot[2] ) {
parse_str( html_entity_decode( $bot[2] ), $args2 );
if ( @$args2['title'] ) {
$row->toc .= '
' .$i .'. '
. stripslashes( $args2['title'] ).'';
} else {
$row->toc .= '
'
. _PN_PAGE .''. $i
;
}
} else {
$row->toc .= '
'
. _PN_PAGE .''. $i;
}
$i++;
}
$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 ' ._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 .'';
}
?>
-
- Joomla! Fledgling
- Posts: 4
- Joined: Thu Oct 16, 2008 4:23 pm
Re: Next and Prev article title, instead of only navigation butt
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
Please can someone highlight how to update the prev and next links to state their associated titles dynamically instead.
Many thanks,
Sean
-
- Joomla! Fledgling
- Posts: 4
- Joined: Thu Oct 16, 2008 4:23 pm
Re: Next and Prev article title, instead of only navigation butt
Can someone please help?
-
- Joomla! Apprentice
- Posts: 24
- Joined: Wed Dec 26, 2007 12:30 pm
Re: Next and Prev article title, instead of only navigation butt
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.
And, how to change << Prev - Next >> at the bottom of a multi-page article to read << Previous - Next Part of Article>>.
Thanks all.
-
- Joomla! Intern
- Posts: 62
- Joined: Sat Nov 22, 2008 2:18 pm
Re: Next and Prev article title, instead of only navigation butt
Hi
You just go to plugins then Content - Page Navigation and change the setting.
i hope i could help you.
You just go to plugins then Content - Page Navigation and change the setting.
i hope i could help you.
-
- Joomla! Fledgling
- Posts: 2
- Joined: Tue Sep 25, 2007 1:54 pm
Re: Next and Prev article title, instead of only navigation butt
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.
For example: < PrevArticle Title Article TitleNext >
Any help?
Thanks.
- lividsnails
- Joomla! Enthusiast
- Posts: 124
- Joined: Mon Jan 07, 2008 4:46 pm
Re: Next and Prev article title, instead of only navigation butt
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?
- brian
- Joomla! Master
- Posts: 12787
- Joined: Fri Aug 12, 2005 7:19 am
- Location: Leeds, UK
- Contact:
Re: Next and Prev article title, instead of only navigation butt
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/
Blog http://brian.teeman.net/
Joomla Hidden Secrets http://hiddenjoomlasecrets.com/
- lividsnails
- Joomla! Enthusiast
- Posts: 124
- Joined: Mon Jan 07, 2008 4:46 pm
Re: Next and Prev article title, instead of only navigation butt
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)