Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List of child pages in a template
#1
Hi All

I would like to be able to create a custom template (done) that outputs all the usual GetSimple items but at the bottom of the page outputs a list of child pages (sometimes all, sometimes just the top 5). Would like to output the page title, description and of course an URL.

Link to the website: http://cycling-jersey-collection.com/

Would anybody be kind enough to show be some sample php code for this? Don't need any help on the html.

Many thanks

andy
Reply
#2
Hi Andy,

we did it like this in the sidebar of get-simple.de:

If there are sub-pages, then they will be listed. It is done with the i18N-plugin which allows to create a menue with a defined starting depht:

PHP Code:
<?php
if (count(return_i18n_menu_data(return_page_slug(),1,10)) > 0) {
            echo 
'<div class="section">';
            echo 
'<h2>Unterseiten</h2><ul>';
            
get_i18n_navigation(return_page_slug(),1,10);
            echo 
'</ul></div>';
        }
    
?>

test it, I am sure you can use it!
|--
Die deutsche GetSimple-Webseite: http://www.Get-Simple.de = the german Get-Simple-Website!
Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#3
(2013-01-09, 01:04:47)Connie Wrote: Hi Andy,

we did it like this in the sidebar of get-simple.de:

If there are sub-pages, then they will be listed. It is done with the i18N-plugin which allows to create a menue with a defined starting depht:

PHP Code:
<?php
if (count(return_i18n_menu_data(return_page_slug(),1,10)) > 0) {
            echo 
'<div class="section">';
            echo 
'<h2>Unterseiten</h2><ul>';
            
get_i18n_navigation(return_page_slug(),1,10);
            echo 
'</ul></div>';
        }
    
?>

test it, I am sure you can use it!

Danke Connie.

Unforetunately I do not want to install any i18n modules. I know they are very good, but I am tryng to keep GetSimple as simple as possible!

Andy
Reply
#4
PHP Code:
$submenu=getChildren('index'); // change to $id for current page 
$menuArray=array();
foreach (
$submenu as $menuitem){
    
$menuArray[(string)$menuitem]['title']=returnPageField($menuitem,'title');    
    
$menuArray[(string)$menuitem]['url']=returnPageField($menuitem,'url');


This should give you an array of children ($menuArray)

Output as required...
My Github Repos: Github
Website: DigiMute
Reply
#5
You could also try the Hierarchical Menus plugin
Reply
#6
(2013-01-09, 17:20:13)Carlos Wrote: You could also try the Hierarchical Menus plugin

Hi Carlos, as he does not want to use any plugin, this plugin or the other one, doesn't matter ;=)
|--
Die deutsche GetSimple-Webseite: http://www.Get-Simple.de = the german Get-Simple-Website!
Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#7
He said he doesn't "want to install any i18n modules".

I was going to suggest the Child Pages plugin, but I remembered about this one (which I think does support custom permalink structures).
Reply
#8
well, so this seems to be a personal decision not a general one, the reasons for that are unclear to me ;=)

but he got other suggestions PLUS direct code, so I think everything is possible and will work.

Cheers, Connie
|--
Die deutsche GetSimple-Webseite: http://www.Get-Simple.de = the german Get-Simple-Website!
Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#9
Hi, I am interested in child pages too and asked help to n00dles101
but sadly his tip didn't work... so I tried something like that
and - tho I am not a programmer - it worked fine!

<?php
echo "<ol>";
$submenu=getChildren($id);
$menuArray=array();
foreach ($submenu as $menuitem) {
echo "<li><a href='";
echo "?id=";
echo getPageField($menuitem,url);
echo "'>";
echo getPageField($menuitem,'title');
echo "</a></li>";
}
echo "</ol>";
?>

I hope it will be useful. Thanks again N00d.
Reply
#10
All

Many thanks for your help. Here's a code snippet of what I went for in the end.

Andy

PHP Code:
if (return_page_slug() == 'blog') { 
    
$submenu=getChildren('blog'); // change to $id for current page 
    
$menuArray=array();

    foreach (
$submenu as $menuitem){
        
$menuArray[(string)$menuitem]['date']=substr(returnPageField($menuitem,'url'), 010);
        
$menuArray[(string)$menuitem]['title']=returnPageField($menuitem,'title'); 
        
$menuArray[(string)$menuitem]['url']=returnPageField($menuitem,'url');
        
$menuArray[(string)$menuitem]['description']=returnPageField($menuitem,'metad');
}   
//foreach

//Sort the array in DESC order with the date of the blog
arsort($menuArray);

foreach (
$menuArray as $value)
{
        
$strBlogTitle $value['title']; 
        
$strBlogURL $value['url'];
        
$strBlogDate date('d M Y'strtotime($value['date'])); 
        
$strBlogDescription $value['description'];

        echo 
"<div class='post'><h2><a href=" $strBlogURL ">" $strBlogTitle "</a></h2></div>";

        
// All remaining echos removed as not relevant to all


}

}   
//if

?>
Reply
#11
Andy, thanks for sharing your snippet!
I edited your post in order to mark that snippet as code...

Cheers, Connie
|--
Die deutsche GetSimple-Webseite: http://www.Get-Simple.de = the german Get-Simple-Website!
Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#12
Hi again GetSimplers,
I was wondering if it is possible to add the date of publication of these codes. I tried with "pubDate" but it gives a date too long. I would like something simpler as 12/01/2013.
Any help?

<?php
echo "<ol>";
$submenu=getChildren($id);
$menuArray=array();
foreach ($submenu as $menuitem) {
echo "<li><a href='?id=";
echo getPageField($menuitem,url);
echo "'>";
echo getPageField($menuitem,'puDate');
echo " - ";
echo getPageField($menuitem,'title');
echo "</a></li>";
}
echo "</ol>";
?>
Reply
#13
(2013-01-12, 18:32:48)D.O. Wrote: I was wondering if it is possible to add the date of publication of these codes. I tried with "pubDate" but it gives a date too long. I would like something simpler as 12/01/2013.

That long number is a unix timestamp. You have to convert it to string (with php functions date or strftime)

Try with this:
PHP Code:
echo date('d/m/Y'strtotime(returnPageField($menuitem,'pubDate'))); 
Reply
#14
Hi Carols and thanks for rerplying. Yes, a timestamp like this.. Mon, 07 Jan 2013 13:59:07 +0100... Sadly your solution doesn't work. It prints no date...

<?php
echo "<ul>";
$submenu=getChildren('turismo');
$menuArray=array();
foreach ($submenu as $menuitem) {
echo "<li><a href='?id=";
echo getPageField($menuitem,url);
echo "'>";
echo "[".date('d/m/Y', returnPageField($menuitem,pubDate))."] ";
echo getPageField($menuitem,title);
echo "</a></li>";
}
echo "</ul>";
?>
Reply
#15
Oops, a typo. I've just edited my post.

So try:

PHP Code:
echo "[".date('d/m/Y'strtotime(returnPageField($menuitem,'pubDate')))."] "

btw it's 'pubDate', between quotes.
Reply
#16
No worries hermano. Now it works perfectly. Thanks again!
I am trying to use GS normal pages like a blog. Here's the final result...

<?php
echo "<ul>";
$submenu=getChildren($id);
$menuArray=array();
foreach ($submenu as $menuitem) {
echo "<li><a href='?id=";
echo getPageField($menuitem,url);
echo "'>";
echo "[".date('d/m/Y', strtotime(returnPageField($menuitem,pubDate)))."] ";
echo getPageField($menuitem,title);
echo "</a></li>";
}
echo "</ul>";
?>
Reply
#17
You still missing quotes in pubDate, but I suppose it works anyway (tho if you enable debug mode you'll get some soft error).

Time ago I made a quick and dirty plugin to do something like that, you may want to get some ideas from it:
http://www.cyberiada.org/cnb/getsimple-p...ent-pages/
(needs some editing as it was made for GS 3.0, not 3.1)

BTW another way to do the same, but using I18N Search: http://get-simple.info/forums/showthread...0#pid31320
Reply
#18
Thanks for these tips, mate! Now I am curious to test your plugin. It seems to be interesting.
Reply




Users browsing this thread: 1 Guest(s)