Add is_tree function to core of WordPress

  1. Inactive


    is_tree() offers a way to affect all the subpages of any page dynamically. For example, you can set styles or includes or whatever without stating the (future and therefore unknown) page numbers.

    You can read about this here:

    Scroll down to Snippet #4.

    Here's the function, but you have to add it to use it, since it ISN'T built-in.

    function is_tree($pid) {      // $pid = The ID of the page we're looking for pages underneath
    	global $post;         // load details about this page
                   return true;   // we're at the page or at a sub page
                   return false;  // we're elsewhere
    Posted: 10 years ago #

  2. Inactive


    You don't get the value of it or what? Let's say you want to use a specific sidebar file or include ONLY for the pages under your "services" section, in which "services" is the parent of all the sub-pages of types of services... Or, you only want some information to appear in the sidebar.php file IF the browser is displaying a sub-page of "services" (there are many scenarios)

    The ability to say if (is_tree('services')) {//do whatever} else {//do something else} means that ANY NEW pages you add under services (but NOT sub-sub-pages) will trigger whatever instructions you provide when a sub-page of services is displayed.

    Does that help? Rather than having to declared all existing pages and give the instructions and hope that no new pages are added... you can account for any new pages via the is_tree() function.

    Why should it have to be added to the functions.php file when it could simply BE in the core functions and ready to roll?

    My two. HTH

    Posted: 10 years ago #

  3. Inactive


    Your passionate advocacy of is_tree sounded just like what i needed to fix my submenu problem... but I can't get it to work *&%$#(@! Can you or someone help me? Newbee WordPress guy.

    I have a double scissor-type drop menu, that wouldn't work with wp-list pages so I'm hardcodeing my navigation. You can see it here at http://wereorganized.biz/.

    I pasted the is_tree function(exacty as from your post) into my functions.php, then added this to the list item that contained the nested unordered list of my submenu:

    <li<?php if (is_tree('garage-cabinets')) { echo " class=\"current\""; } ?>><b>GARAGE CABINETS</b>

    I was expecting the "current" class to be added to any submenu li of garage cabinets, what I got was this error:
    Fatal error: Call to undefined function is_tree() in /home/content/77/5846477/html/wp-content/themes/modern-style/header.php on line 57

    Can you give me a clue as to what I'm doing wrong?

    Posted: 10 years ago #
  4. Povilas

    My first impression was that syncbox is right.
    Then I remembered one recent project and some solutions in it. It was sort of a news portal, but it also has a lot of static pages (by static I mean Pages, not Posts).
    There was actually a lot of pages dedicated to services there (services was also mentioned by syncbox). At first I was trying something along the is_tree() philosophy. Then bad things happened. For your information the structural representation of the tree I had to build:

    Services (top level page)
    - Service group 1 (second lvl)
    -- Service group 1.1 (third lvl)
    --- Service 1.1.1 (4th lvl)
    --- Service 1.1.2 (4th lvl)
    --- Service 1.1.3 (4th lvl)
    -- Service group 1.2 (third lvl)
    --- Service 1.2.1 (4th lvl)
    --- Service 1.2.2 (4th lvl)
    -- Service 1.2 (third lvl)
    -- Service 1.3 (third lvl)
    - Service group 2 (second lvl)
    - Service group 3 (second lvl)
    - Service group 4 (second lvl)

    So the bad things here:
    1. Layouts: top level service page, second level service group page, third level service group page and a separate service (no matter what level) page had its own layout
    2. Structure: service groups have minor service groups. Still, both, minor and major, groups can have their own services.

    The thing here is that _I could have_ used is_tree() if I only had service groups that have services, but if the structure is complex, it is useless and produces a lot of code and if. Hence I went the simple way: I made different page templates and let the user set them. It is much more dynamic that way and requires no coding at all - copy the structure, reshape it and produce another layout.

    I don't vote :)

    Posted: 9 years ago #

RSS feed for this topic


You must log in to post.

  • Rating

    19 Votes
  • Status

    This idea is under consideration