GetSimple Support Forum
Custom URL - 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: Custom URL (/showthread.php?tid=284)



Custom URL - tamascsaba - 2010-01-08

Hy

I would like add custom URL to the menu e.g. forum (/punbb) or my blog (mypage.com/blog).
how can I solve it?

Thx!

Tamás Csaba


Custom URL - Zegnåt - 2010-01-08

Currently, there is no standard way to add non-page links to the GetSimple menu. You could either hard-code them into the template or rewrite the template so it will redirect the visitor to a certain URL when they are on a certain page.

I was pondering over this very issue, I bet there will be a plug-in for adding links when version 2 is out. I can’t imagine only us two having this problem.


Custom URL - internet54 - 2010-01-09

I had the same issue, so I just hard-coded it into a component so that I could call it from the theme files. I know that doesn't make the most sense, but it leaves it easily editable for quick fixes.


Custom URL - Nijikokun - 2010-01-09

I've made it simpler for users to use i guess.. still hardcoded into theme though.

New function for theme_functions.php in admin/inc/
Code:
function set_navigation_item($items, $menu, $url, $title = "url", $order = "11")
    {
        // Setting the order to last by default
        $items[] = array(
            'menu'         => $menu,
            'url'        => $url,
            'title'        => $title,
            'custom'    => true,
            'menuOrder' => $order
        );
        
        return $items;
    }

New get_navigation(); function to replace old one.
Code:
function get_navigation($currentpage, $extra = "") {
        
        global $PRETTYURLS;
        global $SITEURL;
        
        $menu = '';

        $path = "data/pages";
        $dir_handle = @opendir($path) or die("Unable to open $path");
        $filenames = array();
        while ($filename = readdir($dir_handle)) {
            $filenames[] = $filename;
        }
        
        $count="0";
        $pagesArray = array();
        if (count($filenames) != 0) {
            foreach ($filenames as $file) {
                if ($file == "." || $file == ".." || is_dir("data/pages/".$file) || $file == ".htaccess"  ) {
                    // not a page data file
                } else {
                    $thisfile = @file_get_contents('data/pages/'.$file);
                    $data = simplexml_load_string($thisfile);
                    if ($data->private != 'Y') {
                        $pagesArray[$count]['menuStatus'] = $data->menuStatus;
                        $pagesArray[$count]['menuOrder'] = $data->menuOrder;
                        $pagesArray[$count]['menu'] = stripslashes(htmlspecialchars_decode($data->menu, ENT_QUOTES));
                        $pagesArray[$count]['url'] = $data->url;
                        $pagesArray[$count]['title'] = stripslashes(htmlspecialchars_decode($data->title, ENT_QUOTES));
                        $pagesArray[$count]['parent'] = $data->parent;
                        $count++;
                    }
                }
            }
        }
        
        if($extra != ""){
            foreach($extra as $item)
            {
                $pagesArray[] = $item;
            }
        }
        
        $pagesSorted = subval_sort($pagesArray,'menuOrder');
        if (count($pagesSorted) != 0) {
            foreach ($pagesSorted as $page) {
                $sel = ''; $classes = '';
                $url_nav = $page['url'];
                
                if($page['custom']) {
                    if  ($currentpage == $url_nav) { $classes = "current"; } else { $classes = ""; }
                    $menu .= '<li class="' . $classes . '"><a href="' . $url_nav . '" title="' . $page['title'] . '">'. $page['menu'] .'</a></li>'."\n";
                } else if ($page['menuStatus'] == 'Y') {
                    if ("$currentpage" == "$url_nav") { $classes = "current ". $url_nav; } else { $classes = $url_nav; }
                    if ($page['menu'] == '') { $page['menu'] = $page['title']; }
                    if ($page['title'] == '') { $page['title'] = $page['menu']; }
                    if ($PRETTYURLS == '1') {
                        if ($page['parent'] != '' ) { $page['parent'] = tsl($page['parent']); }
                        if ($url_nav == 'index' ) { $url_nav = ''; }
                        $menu .= '<li class="'. $classes .'" ><a href="'. $SITEURL . @$page['parent'] . $url_nav .'" title="'. $page['title'] .'">'.$page['menu'] .'</a></li>'."\n";
                    } else {
                        $menu .= '<li class="'. $classes .'" ><a href="'. $SITEURL .'index.php?id='.$url_nav.'" title="'. $page['title'] .'">'.$page['menu'].'</a></li>'."\n";
                    }
                }
            }
            
            echo $menu;
        }
        
        closedir($dir_handle);
    }

Using it:
Code:
<?php
$items = set_navigation_item($items, 'twitter', 'http://twitter.com');
$items = set_navigation_item($items, 'google', 'http://google.com');
$items = set_navigation_item($items, 'top', 'top/','url',1); // menu item name, url, title, priority

get_navigation(return_page_slug(), $items);
?>

Example: http://nijikokun.com

seems pointless now after coding it D: cause hardcoding it is a lot easier.