GetSimple Support Forum
Sidebar to show for sub pages for each page? - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16)
+--- Thread: Sidebar to show for sub pages for each page? (/showthread.php?tid=3282)



Sidebar to show for sub pages for each page? - Fairly_New - 2012-06-18

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.


Sidebar to show for sub pages for each page? - yurifanboy - 2012-06-18

This is slightly technical and will require basic knowledge of html and css.
http://mvlcek.bplaced.net/get-simple/multi-level-navigation/
Install the I18N plugin and explore the possible combinations offered from the link.

http://mvlcek.bplaced.net/multi-level-navigation/nav-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.


Sidebar to show for sub pages for each page? - n00dles101 - 2012-06-18

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.


Sidebar to show for sub pages for each page? - Fairly_New - 2012-06-19

Ah thank you very much!


Sidebar to show for sub pages for each page? - Fairly_New - 2012-06-23

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?


Sidebar to show for sub pages for each page? - n00dles101 - 2012-06-25

@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....


Sidebar to show for sub pages for each page? - pierre - 2012-08-21

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?


Sidebar to show for sub pages for each page? - n00dles101 - 2012-08-21

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


Sidebar to show for sub pages for each page? - pierre - 2012-08-21

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.


Sidebar to show for sub pages for each page? - n00dles101 - 2012-08-21

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>';
    }    
}



Sidebar to show for sub pages for each page? - pierre - 2012-08-21

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!


Sidebar to show for sub pages for each page? - Connie - 2012-08-22

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-tipps-tricks/i18n-navigation-konditionale-anzeige-von-unterseiten-navigation/

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


Sidebar to show for sub pages for each page? - mgilvey - 2012-08-29

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?


Sidebar to show for sub pages for each page? - uitdecom - 2012-10-03

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.



Sidebar to show for sub pages for each page? - n00dles101 - 2012-10-03

try changing to this , looks like its should be pubDate instead.

Code:
$pagesSorted = subval_sort($children,'pubDate'); // select which field to sort on.



Sidebar to show for sub pages for each page? - uitdecom - 2012-10-03

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>';
        }
    }    
}



Sidebar to show for sub pages for each page? - Connie - 2012-10-03

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


Sidebar to show for sub pages for each page? - Carlos - 2012-10-03

@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 ...").


Sidebar to show for sub pages for each page? - uitdecom - 2012-10-03

Thank you both for the quick replies.

I changed the child_menu plugin for my purposes.


RE: Sidebar to show for sub pages for each page? - RHJ - 2012-12-16

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!