Forums

I need to remove the link from my category parent? (14 posts)

  1. defdumbandblind
    Member
    Posted 4 years ago #

    ...and what I mean is:

    I'm using a wordpress theme that has two drop down menu lines; one that lists my page parents and when scrolled over, their children. Below that, I have one that lists my categories and their children as well.....NOW....

    ...say in the lower nav bar I have something that looks like this:

    PRODUCTS > BREAD > SOURDOUGH...

    ...but I don't want or need my visitor to be able to click on the parent link titled "Products". How do I hide and, or, delete that?

    I don't need that extra page that would archive all the category items filed under "Products", I'd just like to use it as a heading of sorts.

    Does this make sense? It seems like a simple enough query to me, but I can't seem to find an answer. Help?

    <div id="subnavbar">

    <ul id="subnav">

    <?php wp_list_categories('sort_column=name&title_li=&depth=2&exclude=8,34,21,36,35,37,38,39');?>

    </div>

  2. defdumbandblind
    Member
    Posted 4 years ago #

    Oh...PS: The code at the end of that post is from the file titled header.php from my template.

    Thanks again for any help.

  3. defdumbandblind
    Member
    Posted 4 years ago #

    I'm also in kind of a hurry since I'm on a deadline.

    Can anyone help?

  4. defdumbandblind
    Member
    Posted 4 years ago #

    _BUMP_!!!

  5. vidloader
    Member
    Posted 3 years ago #

    I need help with the same thing

    I mean it seems easy enough - I want to make the parent level unclickable.

    I've been working on it all day and it there doesn't seem to be much info on it... just a bunch of people who want to do it but no one knows how.

    sigh...

  6. vidloader
    Member
    Posted 3 years ago #

    You can try Page Link Plus plugin.. it worked for me to unlink individual parent pages BUT it also removed the menu text style which I wasn't able to restore

  7. vidloader
    Member
    Posted 3 years ago #

    apparently there is this but it seems very complicated to me

    Use get_pages() and create your own page menu list using a foreach loop.

  8. Technokinetics
    Member
    Posted 3 years ago #

    Hi vidloader,

    I think you're referring to Page Lists Plus.

    The problem that you describe results when a Page is unlinked, which removes its anchor tags, and the theme styling relies on anchor tags being present.

    The latest version (v1.1.2, released yesterday), provides an "Unlink using javascript" option, which disables links without removing their anchor tags, so shouldn't affect styling.

    Best practice is to use the original, non-javascript unlink option, and to fix your theme's styling, but the new feature provides a plan B for those who are unable to do this.

    - Tim

  9. ETTR
    Member
    Posted 3 years ago #

    We don't want to unlink parent pages, but parent categories!
    Nobody seems to have a clear solution. The best thing I've found so far is this: http://wordpress.org/support/topic/199148?replies=3
    But also that didn't work (or I did something wrong).
    Can anyone help me (and many others) on this?
    Thanks a lot!

  10. ETTR
    Member
    Posted 3 years ago #

    Solution to this problem can be found in the comments of this page:
    http://bavotasan.com/tutorials/how-to-remove-the-links-to-parent-pages-in-the-wordpress-page-list/

  11. adeneba
    Member
    Posted 3 years ago #

    Hi,
    I've modified the solution suggested above by ETTR to unlink parent categories.

    In your theme’s functions.php file, add this function :

    <?php
    
    // Supprimer les liens parents dans la liste des catégories
    // Remove parents links in categories
    
    function removeCategoriesParentLinks($arg,$addFakeLink) {
    if ($addFakeLink==true) {
      $tagStart="<a href=\"javascript:;\">";
      $tagEnd="</a>";
    } else {
      $tagStart=$tagEnd="";
    }
    $cats = wp_list_categories($arg);
    $cats = explode("</li>", $cats);
    $count = 0;
    foreach($cats as $cat) {
    if(strstr($cat,"<ul class='children'>")) {
      $cat = explode("<ul class='children'>", $cat);
      $cat[0] = str_replace('</a>',$tagEnd,$cat[0]);
      $cat[0] = preg_replace('/\<a([^>]+)\>/',$tagStart,$cat[0]);
      if(count($cat) == 3) {
        $cat[1] = str_replace('</a>',$tagEnd,$cat[1]);
    	$cat[1] = preg_replace('/\<a([^>]+)\>/',$tagStart,$cat[1]);
      }
      $cat = implode("<ul class='children'>", $cat);
    }
    $cats[$count] = $cat;
    $count++;
    }
    $cats = implode('</li>',$cats);
    return $cats;
    }
    ?>

    ... and then call it with removeCategoriesParentLinks(); instead of wp_list_categories();

    Notes :
    - You can send wp_list_categories() arguments ;
    - the additional argument '$addFakeLink' (=true/false) is used to add fake links <a href="javascript:;">my categorie</a> (useful to
    maintain css style)

  12. seimec
    Member
    Posted 3 years ago #

    If you want to keep theme styling use

    page list Plus http://wordpress.org/extend/plugins/page-lists-plus/

    like Technokinetics said. But instead of removing the parent link,

    it has a great feature that let you point the parent link to the first child(more logical) or where ever you want.

  13. Technokinetics
    Member
    Posted 3 years ago #

    Good idea, seimec. Like it.

  14. bhargavi
    Member
    Posted 3 years ago #

    I wanted to remove links for parent categories too! Didn't like any of the options above, so came up with this. Adapt and use this in your jquery file:

    //remove link for parent categories
     	$('ul.children').parent(['li']).find('a:first').removeAttr('href');

Topic Closed

This topic has been closed to new replies.

About this Topic