Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sidebar to show for sub pages for each page?
#1
Hello fellow GetSimpletons!

I'm 100% new to GS. I'm currently putting together a website in GS using default Innovation theme. I've made my pages. But I want to know how I can utilize the sidebar area to display a list of sub pages according the page being viewed?

Muchly appreciate your help!
Thank You.
Reply
#2
This is slightly technical and will require basic knowledge of html and css.
http://mvlcek.bplaced.net/get-simple/mul...avigation/
Install the I18N plugin and explore the possible combinations offered from the link.

http://mvlcek.bplaced.net/multi-level-na...-children/
I would recommend using this function. A parent page will display all the child pages it is associated with in the sub menu. This may not display "a list of sub pages according the page being viewed" but rather according to which pages you have made children of the particular parent page.

http://get-simple.info/extend/plugin/child-menu/40/
There is also the child menu plugin. I don't use this because usually the websites I do are in both English and Spanish, so I need multilingual features.
Todo arde si le aplicas la chispa adecuada.
Reply
#3
Hi and welcome to the forums...

Without having to install any plugins you could put the following function into your theme/functions.php file (create one if it doesn't exist)

Code:
function getSubMenu($page){
    $children=getChildren($page);
    foreach ($children as $subpage){
        $title=returnPageField($subpage,'menu');
        $url=returnPageField($subpage,'slug');
        echo '<li><a href="index.php?id='.$url.'">'.$title.'</a></li>';
        // or use below if you have fancy urls on
         //echo '<li><a href="/'.$url.'">'.$title.'</a></li>';
    }    
}

Then in your theme, put this in your sidebar:

Code:
<ul>
<?php getSubMenu($id); ?>
</ul>


Change $id to a specific page slug to get a specific subpages, otherwise it will create subpages for whatever page your on.
My Github Repos: Github
Website: DigiMute
Reply
#4
Ah thank you very much!
Reply
#5
how do I get the parent of the subpages to show above the subpage list?

example:

/* sidebar.inc.php */

<h2><?php get_page() ?></h2>

<ul>
<?php getSubMenu($id); ?>
</ul>

what's the correct function to get parent of the subpages? I just made up get_page() as an example.

And how do I organize the order in which they subpages appear on the list?
Reply
#6
@fairly_new,

Code:
function getSubMenu($page){
    $children=getChildren($page);
    $pagesSorted = subval_sort($children,'pubdate'); // select which field to sort on.
    foreach ($pagesSorted as $subpage){
        $title=returnPageField($subpage,'menu');
        $url=returnPageField($subpage,'slug');
        echo '<li><a href="index.php?id='.$url.'">'.$title.'</a></li>';
        // or use below if you have fancy urls on
         //echo '<li><a href="/'.$url.'">'.$title.'</a></li>';
    }    
}

This will sort the submenu on Published Date (or more corectly last edited date)

To get the field value of the current page use

Code:
//will echo the title of the current page
getPageField($id,'title');  

// returns the page title to the $page variable
$page = returnPageField($id , 'title' );

//return the parent of the current page
$parent = returnPageField($id, 'parent')


Hope this helps....
My Github Repos: Github
Website: DigiMute
Reply
#7
n00dles101 Wrote:Hi and welcome to the forums...

Without having to install any plugins you could put the following function into your theme/functions.php file (create one if it doesn't exist)

Code:
function getSubMenu($page){
    $children=getChildren($page);
    foreach ($children as $subpage){
        $title=returnPageField($subpage,'menu');
        $url=returnPageField($subpage,'slug');
        echo '<li><a href="index.php?id='.$url.'">'.$title.'</a></li>';
        // or use below if you have fancy urls on
         //echo '<li><a href="/'.$url.'">'.$title.'</a></li>';
    }    
}

Then in your theme, put this in your sidebar:

Code:
<ul>
<?php getSubMenu($id); ?>
</ul>


Change $id to a specific page slug to get a specific subpages, otherwise it will create subpages for whatever page your on.

This solution works to do what i want to accomplish, however it doesn't display the title of the page until it has been re-saved. Not a clue how this can be. Have you experienced this?
Reply
#8
what version of GS are you using?

There was an issue with caching in early versions which is sorted from 3.1 onwards...
Upgrade to 3.12 for the latest and greatest
My Github Repos: Github
Website: DigiMute
Reply
#9
n00dles101 Wrote:what version of GS are you using?

There was an issue with caching in early versions which is sorted from 3.1 onwards...
Upgrade to 3.12 for the latest and greatest

I'm using 3.1 at the moment. Will try to make an update, however.
Reply
#10
Ah ok, I see whats wrong. I'm presuming that all the submenu pages also have the menu option set, if you want to output the 'title' of the page change the function to this:

Code:
function getSubMenu($page){
    $children=getChildren($page);
    foreach ($children as $subpage){
        $title=returnPageField($subpage,'title');  // this changed from 'menu'
        $url=returnPageField($subpage,'slug');
        echo '<li><a href="index.php?id='.$url.'">'.$title.'</a></li>';
        // or use below if you have fancy urls on
         //echo '<li><a href="/'.$url.'">'.$title.'</a></li>';
    }    
}
My Github Repos: Github
Website: DigiMute
Reply
#11
n00dles101 Wrote:Ah ok, I see whats wrong. I'm presuming that all the submenu pages also have the menu option set, if you want to output the 'title' of the page change the function to this:

Code:
function getSubMenu($page){
    $children=getChildren($page);
    foreach ($children as $subpage){
        $title=returnPageField($subpage,'title');  // this changed from 'menu'
        $url=returnPageField($subpage,'slug');
        echo '<li><a href="index.php?id='.$url.'">'.$title.'</a></li>';
        // or use below if you have fancy urls on
         //echo '<li><a href="/'.$url.'">'.$title.'</a></li>';
    }    
}

Thank you!
Reply
#12
we did it like this with the i18N-navigation at www.get-simple.de

in the sidebar of template.php:

Code:
<?php
if (count(return_i18n_menu_data(return_page_slug(),1,10)) > 0) {

  echo '<div class="section">';
  echo '<h2>Unterseiten</h2>';
  echo '<ul>';
  get_i18n_navigation(return_page_slug(),1,10);
  echo '</ul>';
  echo '</div>';

}
?>

it is explained here: http://www.get-simple.de/anwendung/gs-ti...avigation/

and it shows a h2-header and the submenu only of there are sub-pages
|--

Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#13
So what you are saying is to get any of the sub pages I made I need to add all this code? I installed the I18N plugin which has taken over some of the default functions or they are just not working now. For example; I used to click a button to add keywords and description and set the page order if it's going in the menu. I can no longer get access to that. Now to put the pages in the order I want I need to do some drag n drop thing which only highlights the text and doesn't drag anything.

Is there really no other way to get access to sub pages? Was GS designed thinking people would only have one level of navigation? Or do I just have to bite the bullet and jump into the code you provided?
Reply
#14
Hello

Can anyone tell me why this part of the above code isn't working?

Code:
$pagesSorted = subval_sort($children,'pubdate'); // select which field to sort on.
<º)))><
Reply
#15
try changing to this , looks like its should be pubDate instead.

Code:
$pagesSorted = subval_sort($children,'pubDate'); // select which field to sort on.
My Github Repos: Github
Website: DigiMute
Reply
#16
Yes, already tried that.

Here's my full code:

Code:
function getChildPages($page){
    $children=getChildren($page);
    
    $pagesSorted = subval_sort($children, 'pubDate');
  
    foreach ($pagesSorted as $subpage) {
        if (returnPageField($subpage, 'private') != 'Y') {
            
        $title=returnPageField($subpage,'title');
        $url=returnPageField($subpage,'slug');
        $md=returnPageField($subpage, 'metad');
        echo '<h2 class="m700 red">'.$title.'</h2>';
        echo '<p class="m500">'.$md.'</p>';
        echo '<a href="index.php?id='.$url.'#m2" class="readon m700">» lees meer</a>';
        // or use below if you have fancy urls on
         //echo '<li><a href="/'.$url.'">'.$title.'</a></li>';
        }
    }    
}
<º)))><
Reply
#17
mgilvey Wrote:s there really no other way to get access to sub pages? Was GS designed thinking people would only have one level of navigation?
<

mgilvey,

no, with that plugin GS works with many levels. Your problems must sit elsewhere,

Cheers, Connie
|--

Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#18
@uitdecom

You'll have to use or do something different to sort by pubDate -- it is not stored as "2012/12/31 ..." or something directly sortable like that, but as textual English ("Mon, 31 Dec 2012 ...").
Reply
#19
Thank you both for the quick replies.

I changed the child_menu plugin for my purposes.
<º)))><
Reply
#20
Thanks for many good ideas!

Here's my own attempt to make submenues:
Code:
<?php

function getSubMenu($current_page)
{
    /*
     *   Get the parentpage if there is one.
     */
    $parent_page = returnPageField($current_page, 'parent');
    if ($parent_page == null)
    {
        /*
         *  Theres is no parentpage, and we can use the current page
         *  as reference.
         */
        $reference_page = $current_page;
    }
    else
    {
        /*
         *  There is a parentpage, and we will use that page as
         *  reference.
         */
        $title          = returnPageField($parent, 'menu');
        $reference_page = $parent_page;
    }
    /*
     *   Gets all the subpages if there are any.
     */
    $sub_pages      = getChildren($reference_page);
    /*
     *  Only if there are any subpages will we make a submenu.
     */
    if (!empty($sub_pages))
    {
        $ordered_sub_pages = subval_sort($sub_pages, 'menuOrder');
        /*
         *  There is at least one subpage. And we will ha a submenu.
         *  This submenu should be designed in the CSS-file!
         */
        echo '<div class="sub_menu">';
        /*
         *  In order to get correct links with fancy urls.
         */
        $s                 = $_SERVER['PHP_SELF'];
        $i                 = strrpos($s, '/');
        $d                 = substr($s, 0, $i);
        /*
         * For each of the child pages there will be a link.
         */
        foreach ($ordered_sub_pages as $sub_page)
        {
            $pri   = returnPageField($sub_page, 'menuOrder');
            $title = returnPageField($sub_page, 'menu');
            $url   = returnPageField($sub_page, 'slug');
            /*
             *  I did not design the submenu with <tr> and <td>.
             *  This was the only way I was able to do it.
             */
            echo '<p><a ';
            $u     = $d . '/' . $url;
            if ($sub_page == $current_page)
            {
                /*
                 *  This is the page that we are on. And the
                 *  link should be a little different.
                 */
                echo ' class="current"';
            }
            /*
             *  The rest of the link is the same for all of them.
             */
            // echo ' href="index.php?id=' . $url . '">' . $title . '</a></p>';
            /*
             *   This one is for fancy urls.
             */
            echo ' href="' . $u . '">' . $title . '</a></p>';
        }
        echo '</div>';
}   }

?>
I have used it here!
Reply




Users browsing this thread: 1 Guest(s)