Next and Previous buttons
Next and Previous buttons
I'm looking for a way to make a simple set of Previous and Next links at the bottom of each page. Thees links should link to the next active item in the site tree.
I have been looking at both cms_selflink, buletmenu, and EllNav, but none of them offers the functionality I want, so now I'm thinking of making my own plugin or module.
To do that, however, I need to figure out how parts of the API works. After looking through the code for buletmenu, and a number of other plugins i have deducted that I can get a complete tree from the database with ContentManager::GetAllContent(), but this seems a bit to complicated for my purpouse, I'd much rather be able to check the hirachy of the current page, and then check for the previous and next page in the tree by checking first child, next sibling, etc.
Is it possible to use the ContentManager to grab an item by its hirachy rather than its id/alias? Or is there an easier aproach?
I have been looking at both cms_selflink, buletmenu, and EllNav, but none of them offers the functionality I want, so now I'm thinking of making my own plugin or module.
To do that, however, I need to figure out how parts of the API works. After looking through the code for buletmenu, and a number of other plugins i have deducted that I can get a complete tree from the database with ContentManager::GetAllContent(), but this seems a bit to complicated for my purpouse, I'd much rather be able to check the hirachy of the current page, and then check for the previous and next page in the tree by checking first child, next sibling, etc.
Is it possible to use the ContentManager to grab an item by its hirachy rather than its id/alias? Or is there an easier aproach?
Re: Next and Previous buttons
Check this thread: http://forum.cmsmadesimple.org/index.ph ... 107.0.html
It looks like he implemented exactly what you're looking for!
It looks like he implemented exactly what you're looking for!
Many modules available from the http://dev.cmsmadesimple.org
The CMS Made Simple Developer Cookbook is now available from Packt Publishers!
The CMS Made Simple Developer Cookbook is now available from Packt Publishers!
Re: Next and Previous buttons
Not excatly, but the code looks usefull in making what I'm looking for.
I'll play around with the SQL query, and se if I can make it work. Should be possible.
I'll play around with the SQL query, and se if I can make it work. Should be possible.
Re: Next and Previous buttons
It seems like an interesting task...mbvdk wrote: I'll play around with the SQL query, and se if I can make it work. Should be possible.

Code: Select all
elseif (isset($params['link']))
{
$condition = $order_by = false;
switch (strtolower($params['link']))
{
case 'next':
$condition = '>';
$order_by = 'hierarchy';
break;
case 'prev':
case 'previous':
$condition = '<';
$order_by = 'hierarchy DESC';
break;
}
if ($condition && $order_by)
{
$query = "SELECT DISTINCT t1.content_id, t1.content_alias ";
$query .= "FROM ".cms_db_prefix()."content AS t1, ".cms_db_prefix()."content AS t2 ";
$query .= "WHERE t1.active = 1 ";
$query .= "AND t2.content_id = ".$gCms->variables['content_id']." ";
$query .= "AND t1.hierarchy ".$condition." t2.hierarchy ";
$query .= "ORDER BY t1.".$order_by." LIMIT 1";
$dbresult = $db->Execute($query);
while ($row = $dbresult->FetchRow())
{
$content = new content();
$pageid = $content->mId = $row['content_id'];
$alias = $content->mAlias = $row['content_alias'];
$url = $content->GetUrl();
unset($content);
}
}
unset($condition);
unset($order_by);
}
Code: Select all
if (isset($params['page']))
{
...
}
Code: Select all
{cms_selflink link="prev" text="PREVIOUS PAGE"} or {cms_selflink link="previous" text="PREVIOUS PAGE"}
Code: Select all
{cms_selflink link="next" text="NEXT PAGE"}
- this will work only for content pages with 'active=1', include pages which are not displayed in menu
- do not set parameter 'page'
- I mean set parameter 'link' with value 'prev' or 'next' instead of parameter 'page'.
And that is it.

Last edited by 100rk on Thu Jun 23, 2005 4:54 pm, edited 1 time in total.
Re: Next and Previous buttons
Thanks 100rk!
That piece of code, was just what I needed to make a functional set of buttons for the project I was working on. I would never have figured that out on my own, what I was working on was generating (guessing) and testing for possible next/previous possitions in the hirachy. My sql-knowledge is both quite limited and quite rusty.
I ended up implementing a modified version of your code into my already modified cms_selflink, so now the version I'm using is quite different from the original.
It now has the following options:
That piece of code, was just what I needed to make a functional set of buttons for the project I was working on. I would never have figured that out on my own, what I was working on was generating (guessing) and testing for possible next/previous possitions in the hirachy. My sql-knowledge is both quite limited and quite rusty.
I ended up implementing a modified version of your code into my already modified cms_selflink, so now the version I'm using is quite different from the original.

It now has the following options:
- (optional) page - Page ID or alias to link to.
- (optional) dir next/prev (previous) - If this is used it replaces the page parameter
Note! Only one of the above may be used in the same cms_selflink statement!! - (optional) text - Text to show for the link. If not given, the Page Name is used instead.
- (optional) menu 1/0 - If 1 the Menu Text is used for the link text in stead of the Page Name
- (optional) target - Optional target for the a link to point to. Useful for frame and javascript situations.
- (optional) class - Class for the a link. Useful for styling the link.
- (optional) lang - Display link-labels (Next Page / Previous Page) in different languages (0 no link.) Danish or English for now
Re: Next and Previous buttons
I am glad to help You, but this few lines of code was only short PHP training for me. This is also answer to Your question about my name: just forget it - it is not so important for me. Just publish Your code for other CMSMS users.
Have a nice day!
P.S. If You want to do a perfect job, try to implement also some parameter for additions, like JavaScript events (onmouseover, onmouseout....), css id etc.
Have a nice day!

P.S. If You want to do a perfect job, try to implement also some parameter for additions, like JavaScript events (onmouseover, onmouseout....), css id etc.
Last edited by 100rk on Mon Jun 27, 2005 10:32 pm, edited 1 time in total.
Re: Next and Previous buttons
Hmm that sounds like a good idea.
So I have now added an Option more="more options" this will just put the value passed in more inside the a-tag.
like this:
{cms_seflink page="home" more='OnMouseIn="MouseIn" OnMouseOut="MouseOut"'}
will result in the following code
and Option id=css_id to add a css_id tag for the for the a-tag
So I have now added an Option more="more options" this will just put the value passed in more inside the a-tag.
like this:
{cms_seflink page="home" more='OnMouseIn="MouseIn" OnMouseOut="MouseOut"'}
will result in the following code
Code: Select all
<a href="http://site.com/index.php?page=home" OnMouseIn="MouseIn" OnMouseOut="MouseOut">Home</a>
Re: Next and Previous buttons
Did you ever get around to doing this stuff ? If so can I have a link to the code?mbvdk wrote: Hmm that sounds like a good idea.
So I have now added an Option more="more options" this will just put the value passed in more inside the a-tag.
like this:
{cms_seflink page="home" more='OnMouseIn="MouseIn" OnMouseOut="MouseOut"'}
will result in the following codeand Option id=css_id to add a css_id tag for the for the a-tagCode: Select all
<a href="http://site.com/index.php?page=home" OnMouseIn="MouseIn" OnMouseOut="MouseOut">Home</a>
Would it be possible to have local rather than full url links as an option?
e.g.
index.php?page=home"
as oposed to
http://www.yourdomain.co/index.php?page=home"
Does this work with URL re-writing to Google friendly links?
Russ
Last edited by Russ on Tue Nov 29, 2005 8:04 am, edited 1 time in total.
Re: Next and Previous buttons
This sounds like a good plugin.
Has it been posted anywhere? I can't seem to find it in the forge.
Has it been posted anywhere? I can't seem to find it in the forge.
Re: Next and Previous buttons
Correct, this is now in the core distribution. In fact, the new default site uses it pretty liberally.
Re: Next and Previous buttons
Cool. I really like megabob's implementation of this in FCKEditor (it's about the only thing I like about FCKEditor but that's another story).
Perhaps he could update it with all the new parameters and make this plugin as easy to use as it is useful. I don't ask for much. Oh no.
Perhaps he could update it with all the new parameters and make this plugin as easy to use as it is useful. I don't ask for much. Oh no.

Re: Next and Previous buttons
Hi,
I'm just implementing a site with CMS Made Simple now and wanted to replace the prev/next text links with buttons.
My efforts in combination with the wealth of info here resulted in the following
{cms_selflink dir="previous" lang='0' text='' more=''}
{cms_selflink dir="next" lang='0' text='' more=''}
It's in a table 'cause I wanted the button's positions to remain fixed if one is not visible.
However I have one problem - I cannot seem to remove the text link under the button it seems to be a left over from the tag function.
Please note - I do not have any real experience with CSS, if there is a neat solution to this could you please demonstrate by modifying my code shown here.
Regards
Michael
I'm just implementing a site with CMS Made Simple now and wanted to replace the prev/next text links with buttons.
My efforts in combination with the wealth of info here resulted in the following
{cms_selflink dir="previous" lang='0' text='' more=''}
{cms_selflink dir="next" lang='0' text='' more=''}
It's in a table 'cause I wanted the button's positions to remain fixed if one is not visible.
However I have one problem - I cannot seem to remove the text link under the button it seems to be a left over from the tag function.
Please note - I do not have any real experience with CSS, if there is a neat solution to this could you please demonstrate by modifying my code shown here.
Regards
Michael
Re: Next and Previous buttons
Hi,
Thought about it some more, and solved this issue. I use the code below above and below the content in my template to have a "previous" "back" and "next" button. The extra text I was complaining about was an error in syntax.
{cms_selflink dir="previous" lang='0' text='' more='>
{cms_selflink dir="next" lang='0' text='' more='>
Naturally use whatever images suit you best for the buttons.
Regards
Michael G
Thought about it some more, and solved this issue. I use the code below above and below the content in my template to have a "previous" "back" and "next" button. The extra text I was complaining about was an error in syntax.
{cms_selflink dir="previous" lang='0' text='' more='>
{cms_selflink dir="next" lang='0' text='' more='>
Naturally use whatever images suit you best for the buttons.
Regards
Michael G
Re: Next and Previous buttons: Small bug fix
I think there's a small bug in the cms_selflink tag... When I specify "menu=1", I get empty links. As far as I can tell, the menu_text is only loaded if "dir" is specified. I changed the code to fix the problem for me, and I'm posting it here so others can verify it and/or apply the fix to the production code.
The fix goes right after line 37, as shown in this code fragment:
Maybe after I've learned my way around and figured out the rules, I'll figure out how to update the code myself. Until then, I'll leave it to the trained professionals. 
Hope this helps!
Michael
The fix goes right after line 37, as shown in this code fragment:
Code: Select all
$pageid = $content->Id();
$alias = $content->Alias();
$name = $content->Name(); //mbv - 21-06-2005
$url = $content->GetUrl();
$menu_text = $content->MenuText(); //** FIX: THIS LINE ADDED **

Hope this helps!
Michael
Re: Next and Previous buttons
Patricia, thanks for spending time to show a N00B the way things work! I've been thinking that it would be a fair amount of work to figure out the way we do things here at CMSMS. I hadn't realized how accessable the SVN versions were. It will undoubtably save me much frustration going forward.
Michael
Michael