Sub-Pages Action
NOT Included in any Wikka version yetLast edited by NickAldwin:
Replaces old-style internal links with new pipe-split links.
Fri, 20 May 2016 07:38 UTC [diff]
Replaces old-style internal links with new pipe-split links.
Fri, 20 May 2016 07:38 UTC [diff]
What
- Create a menu with links to sub-pages.
- A page is considered a sub-page if the first x chars are the same as the current page.
- Optional you can define an other page than the current by using the "page" parameter.
Use
- Include on the page where you would like to include this menu this string:
{{subpages}} or
{{subpages page="HomePage"}}
Features
- If there are no subpages found, nothing will be included.
- The "page" parameter needs to be a existing page, otherwise the current page will be used.
- The first x chars that are identical to the parent-page are removed. If you like to see the full name, uncomment the right code in the foreach-loop.
- Layout (hor, vert, colors,...) can be done by giving the right option to the "ul.subpage" class in CSS.
Parameters
name | type | required? | default | description |
---|---|---|---|---|
page | string | optional | current page | The page that will be used to show the subpages from. |
Installation
- Save the code below as actions/subpages/subpages.php
- Give it the same file permissions as the php files in the actions directory.
- Note: function ExistsPage is included in 1.1.6.0
Code
<?php
// Shows pagenames that have the current pagename as start.
// by OnegWR, may 2005, license GPL
// modified by NickAldwin, April 2010
if( is_array($vars) AND isset($vars['page']) AND $this->ExistsPage($vars['page']) ){
$sp_tag = $vars['page'];
}else{
$sp_tag = $this->GetPageTag();
}
$sp_len = strlen($sp_tag);
$sp_links = array();
$sp_str = "SELECT `tag` FROM `".$this->config["table_prefix"]."pages` ".
"WHERE `tag` LIKE '".$sp_tag."%' ".
"AND `latest` = 'Y' ORDER BY `tag` ASC";
if ($sp_pages = $this->LoadAll( $sp_str )){
foreach($sp_pages as $sp_page){
if ($sp_tag == $sp_page['tag']) continue;
//$sp_links[]=$this->Link($sp_page['tag']); // Show full name
$sp_links[]=$this->Link($sp_page['tag'],'',substr($sp_page['tag'],$sp_len));
}
if( count( $sp_links ) > 0 ){
print "\t\t<ul class=\"subpages\">\n\t<li>";
print implode("</li>\n\t<li>", $sp_links);
print "</li>\n</ul>\n\n";
}
}
?>
// Shows pagenames that have the current pagename as start.
// by OnegWR, may 2005, license GPL
// modified by NickAldwin, April 2010
if( is_array($vars) AND isset($vars['page']) AND $this->ExistsPage($vars['page']) ){
$sp_tag = $vars['page'];
}else{
$sp_tag = $this->GetPageTag();
}
$sp_len = strlen($sp_tag);
$sp_links = array();
$sp_str = "SELECT `tag` FROM `".$this->config["table_prefix"]."pages` ".
"WHERE `tag` LIKE '".$sp_tag."%' ".
"AND `latest` = 'Y' ORDER BY `tag` ASC";
if ($sp_pages = $this->LoadAll( $sp_str )){
foreach($sp_pages as $sp_page){
if ($sp_tag == $sp_page['tag']) continue;
//$sp_links[]=$this->Link($sp_page['tag']); // Show full name
$sp_links[]=$this->Link($sp_page['tag'],'',substr($sp_page['tag'],$sp_len));
}
if( count( $sp_links ) > 0 ){
print "\t\t<ul class=\"subpages\">\n\t<li>";
print implode("</li>\n\t<li>", $sp_links);
print "</li>\n</ul>\n\n";
}
}
?>
History
- Published on main site (2005-05-09) - OnegWR
- Fixed counting bug & instructions (2011-04-11) - NickAldwin
CategoryUserContributions