Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sidebar to show for sub pages for each page?
#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


Messages In This Thread
RE: Sidebar to show for sub pages for each page? - by RHJ - 2012-12-16, 01:05:03



Users browsing this thread: 1 Guest(s)