2

I have the following Menu structure:

Genre - Fiction - Autobiography - Sci Fi - Other [class="hide"]

The menu created is then /genre/fiction/, /genre/other/. I am trying to not display the /other within the list of menu items which I can easily do by using JavaScript to hide the parent list item. But this is still visible to the crawlers which I am trying to avoid. I could put it under an unpublished/hidden menu but that would mean i loose the top level 'genre' since the /other will become top level since Other won't have any parent.

So the only method I can imagine is to create a mod_menu override (default_url.php) and check for a class set in the backend and if the class is set for any menu item, do not display it.

Where would the if/else condition go in the following code for it to not appear or at the very least; for there to be no link even if the text is displayed? I tried putting it in line 4 but all the links simply turned into a link to the homepage.

    switch ($item->browserNav) :
    default:
    case 0:
?><a <?php echo $class; ?>href="<?php echo $flink; ?>" <?php echo $title; ?>><?php echo $linktype; ?></a><?php
        break;
    case 1:
        // _blank
?><a <?php echo $class; ?>href="<?php echo $flink; ?>" target="_blank" <?php echo $title; ?>><?php echo $linktype; ?></a><?php
        break;
    case 2:
        // window.open
        $options = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,'.$params->get('window_open');
            ?><a <?php echo $class; ?>href="<?php echo $flink; ?>" onclick="window.open(this.href,'targetWindow','<?php echo $options;?>');return false;" <?php echo $title; ?>><?php echo $linktype; ?></a><?php
        break;
endswitch;
  • 1
    Are you using $class? Because that's going to give if class="class" rather than if class What was the syntax you used for the if statement? – caustic Mar 4 '15 at 1:31
  • Yep I was outputting the $class and now you said it, I noticed it as well. I support I will have to extract the class information from that $class string and do my thing? Thanks. – sifu Mar 6 '15 at 1:24
2

Using the method you're going with here, this is how I would imagine achieving this;

  1. First of all, there's a possibility that your menu name might have multiple classes, so you need to check if your class name is is contained within $class, as opposed to exactly equal to it. You could do this with PHP's strpos function (though be careful about partial matches - more on that later).
  2. Now, because your switch statement appears to output a different variation of the same menu item (based on where the link is opening), you probably want to wrap the entire statement in an if clause to check against the class name - rather than just a subsection of it;

    $class = "apples oranges pears"; // contains 3 different classes
    
    if (strpos($class, "oranges") !== false)
    {
        // DON'T show the menu item, because 'oranges' was detected
    }
    else
    {
        // your whole switch statement goes here
        switch ($item->browserNav) :
           // blah blah blah ...
        endswitch;
    }
    

Be aware that strpos will need to evaluate to EXACTLY 'not false', (!==) as opposed to basic 'not false' (!=), because it will incorrectly interpret position 0 as false if you don't.

Regarding partial class matches - if, in the example above, you were looking for a class called pea, it would still match against peaches, so the simplest solution is just to make sure that your class name is sufficiently distinct - otherwise you will need to write more elaborate code (maybe using regular expressions, or some other useful function that I can't think of right away).

Hope that's of some use.

2

But this is still visible to the crawlers which I am trying to avoid.

Each menu item has a "Robots" option on the "Metadata" tab. Set it to "No index, no follow" and search engines should not index your page anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.