Posts: 15
Threads: 5
Joined: Oct 2012
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
Posts: 2,928
Threads: 195
Joined: Feb 2011
2013-01-09, 01:04:47
(This post was last modified: 2013-01-09, 01:05:39 by Connie.)
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!
Posts: 15
Threads: 5
Joined: Oct 2012
(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
Posts: 1,108
Threads: 70
Joined: Aug 2009
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...
Posts: 3,491
Threads: 106
Joined: Mar 2010
Posts: 2,928
Threads: 195
Joined: Feb 2011
(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 ;=)
Posts: 3,491
Threads: 106
Joined: Mar 2010
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).
Posts: 2,928
Threads: 195
Joined: Feb 2011
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
Posts: 321
Threads: 15
Joined: Feb 2012
2013-01-10, 23:23:05
(This post was last modified: 2013-01-10, 23:29:32 by D.O..)
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.
My website made with GetSimple CMS is
Arte & Società
www.artesocieta.eu
An indipendent website about Italian Contemporary Visual Arts
Posts: 15
Threads: 5
Joined: Oct 2012
2013-01-10, 23:40:13
(This post was last modified: 2013-01-11, 18:03:12 by Connie.)
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'), 0, 10); $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
?>
Posts: 2,928
Threads: 195
Joined: Feb 2011
Andy, thanks for sharing your snippet!
I edited your post in order to mark that snippet as code...
Cheers, Connie
Posts: 321
Threads: 15
Joined: Feb 2012
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>";
?>
My website made with GetSimple CMS is
Arte & Società
www.artesocieta.eu
An indipendent website about Italian Contemporary Visual Arts
Posts: 3,491
Threads: 106
Joined: Mar 2010
(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')));
Posts: 321
Threads: 15
Joined: Feb 2012
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>";
?>
My website made with GetSimple CMS is
Arte & Società
www.artesocieta.eu
An indipendent website about Italian Contemporary Visual Arts
Posts: 3,491
Threads: 106
Joined: Mar 2010
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.
Posts: 321
Threads: 15
Joined: Feb 2012
2013-01-17, 06:07:35
(This post was last modified: 2013-01-17, 06:08:06 by D.O..)
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>";
?>
My website made with GetSimple CMS is
Arte & Società
www.artesocieta.eu
An indipendent website about Italian Contemporary Visual Arts
Posts: 3,491
Threads: 106
Joined: Mar 2010
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-plugin-recent-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.php?tid=1256&pid=31320#pid31320
Posts: 321
Threads: 15
Joined: Feb 2012
Thanks for these tips, mate! Now I am curious to test your plugin. It seems to be interesting.
My website made with GetSimple CMS is
Arte & Società
www.artesocieta.eu
An indipendent website about Italian Contemporary Visual Arts
|