WordPress.org

Ready to get started?Download WordPress

Forums

Something like parent_is('4') (5 posts)

  1. xortw
    Member
    Posted 9 years ago #

    Does someone have a solution for the following problem?
    I'am trying to make some pages different based on whether there parent page is (for example) page 4. However there is not such thing as a parent_is('4') function in the Conditional_Tags list on http://codex.wordpress.org/Conditional_Tags . Did I overlooked something or is the only solution hard-coding all child-pages of page 4?

    Timon

  2. nateomedia
    Member
    Posted 9 years ago #

    Parent "Page" or parent "category"? I'd like to know how to do this with parent category -- something like is_category_parent(). Or the reverse, if there was a way to say that it is the child of a category -- like is_category(child=10).

  3. xortw
    Member
    Posted 9 years ago #

    Well it is 'parent Page' in my case.

  4. pepito
    Member
    Posted 8 years ago #

    If all you want is a quick fix and your problem is limited to being able to include children of a parent category when testing for is_category(), you could do this:

    Check functions.php inside /wp-includes/ and around line 1295 you'll see the function that actually does the is_category test. It begins:

    function is_category ($category = '') {

    and then proceeds to do a number of tests. I added one more test:


    else if ($category == $cat_obj->category_parent) {
    return true;
    }


    That way, I can have a conditional tag that will result in "true" if a post or posts are either in a category or in a child of said category.

    This may not be of use to you, but, after lurking on these boards for too long, I thought I'd start sharing some of the things we've been doing to get around the understandable limitations of this Blog-turned-CMS called WordPress.

  5. Kafkaesqui

    Posted 8 years ago #

    "Blog-turned-CMS"

    Thought I'd note that WordPress hasn't made any turns. WordPress may be a blogging system with CMS-like features, but it is for blogs first and foremost.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags