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
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!
(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
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...
(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 ;=)
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).
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
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.
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
?>
Andy, thanks for sharing your snippet!
I edited your post in order to mark that snippet as code...
Cheers, Connie
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>";
?>
(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')));
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>";
?>
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.
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>";
?>
Thanks for these tips, mate! Now I am curious to test your plugin. It seems to be interesting.