Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP help

  • 28-03-2011 10:07PM
    #1
    Registered Users, Registered Users 2 Posts: 10,240 ✭✭✭✭


    I'm talking some tentative steps into the world of PHP and I'm lost already. What I'm attempting to do is style the "auto-nav" in a CMS called Concrete5. Basically C5 creates your nav and then you have to tinker with php so it will recognise the css. I've followed the instructions here and I think I have everything correct up until the point that I have to start editing view.php to reference the CSS. Frankly speaking, I'm not up to it yet.

    It probably just a matter of placing the id's for each page (#home, #about, #news, #get, #services, #links) into the view.php file (see below) but that is easier said than done when you don't know what you are doing.

    Any help would be appreciated.
    @charset "utf-8";
    /* CSS Document */
    #header{margin-top:280px; float:left; width:900px; display:block;  cursor:hand;}
    
    #header ul{margin:0; padding:0 0 0 150px;}
    
    #header li{float:left; height:30px; width:80px; list-style-type:none; margin:10px 10px 0 10px;}
    
    #home, #about, #news, #get, #services, #links{background:url(images/button2.gif) no-repeat 0 0;}
    
    #home:hover, #about:hover, #news:hover, #get:hover, #services:hover #services:hover, #links:hover{background-position:0 -30px;}
    
    #home span, #about span, #news span, #get span, #services span, #links span{position:absolute; top: -9999px;}
    
    <?php 
        defined('C5_EXECUTE') or die("Access Denied.");
        $aBlocks = $controller->generateNav();
        $c = Page::getCurrentPage();
        $containsPages = false;
        
        $nh = Loader::helper('navigation');
        
        //this will create an array of parent cIDs 
        $inspectC=$c;
        $selectedPathCIDs=array( $inspectC->getCollectionID() );
        $parentCIDnotZero=true;    
        while($parentCIDnotZero){
            $cParentID=$inspectC->cParentID;
            if(!intval($cParentID)){
                $parentCIDnotZero=false;
            }else{
                $selectedPathCIDs[]=$cParentID;
                $inspectC=Page::getById($cParentID);
            }
        }     
        
        foreach($aBlocks as $ni) {
            $_c = $ni->getCollectionObject();
            if (!$_c->getCollectionAttributeValue('exclude_nav')) {
                
                
                $target = $ni->getTarget();
                if ($target != '') {
                    $target = 'target="' . $target . '"';
                }
                if (!$containsPages) {
                    // this is the first time we've entered the loop so we print out the UL tag
                    echo("<ul class=\"nav\">");
                }
                
                $containsPages = true;
                
                $thisLevel = $ni->getLevel();
                if ($thisLevel > $lastLevel) {
                    echo("<ul>");
                } else if ($thisLevel < $lastLevel) {
                    for ($j = $thisLevel; $j < $lastLevel; $j++) {
                        if ($lastLevel - $j > 1) {
                            echo("</li></ul>");
                        } else {
                            echo("</li></ul></li>");
                        }
                    }
                } else if ($i > 0) {
                    echo("</li>");
                }
    
                $pageLink = false;
                
                if ($_c->getCollectionAttributeValue('replace_link_with_first_in_nav')) {
                    $subPage = $_c->getFirstChild();
                    if ($subPage instanceof Page) {
                        $pageLink = $nh->getLinkToCollection($subPage);
                    }
                }
                
                if (!$pageLink) {
                    $pageLink = $ni->getURL();
                }
    
                if ($c->getCollectionID() == $_c->getCollectionID()) { 
                    echo('<li class="nav-selected nav-path-selected"><a class="nav-selected nav-path-selected" ' . $target . ' href="' . $pageLink . '">' . $ni->getName() . '</a>');
                } elseif ( in_array($_c->getCollectionID(),$selectedPathCIDs) ) { 
                    echo('<li class="nav-path-selected"><a class="nav-path-selected" href="' . $pageLink . '" ' . $target . '>' . $ni->getName() . '</a>');
                } else {
                    echo('<li><a href="' . $pageLink . '" ' . $target . ' >' . $ni->getName() . '</a>');
                }    
                $lastLevel = $thisLevel;
                $i++;
                
                
            }
        }
        
        $thisLevel = 0;
        if ($containsPages) {
            for ($i = $thisLevel; $i <= $lastLevel; $i++) {
                echo("</li></ul>");
            }
        }
    
    ?>
    


Comments

  • Registered Users, Registered Users 2 Posts: 342 ✭✭adm


    It probably just a matter of placing the id's for each page (#home, #about, #news, #get, #services, #links) into the view.php file (see below)

    I would usually give the body tag these id's so I'd imagine you do that in the overall site template rather than this particular view.

    But if you want to just give the <ul> an id you could try changing:
                  // this is the first time we've entered the loop so we print out the UL tag
                    echo("<ul class=\"nav\">");
    

    to
                    // this is the first time we've entered the loop so we print out the UL tag
                    echo '<ul class="nav" id="' . $c->getCollectionHandle() . '">';
    

    not familiar with concrete5 so not completely sure what $c->getCollectionHandle() returns. I just googled a bit and found this:
    http://www.concrete5.org/documentation/introduction/cheat-sheet/


    btw the $c object comes from this line earlier in the code:

    $c = Page::getCurrentPage();


Advertisement