Results 1 to 10 of 10

Thread: CSS Class for pages with sub pages?

  1. #1
    Mild Fuzz is offline Here For The Peanuts
    Join Date
    Feb 2010
    Posts
    106

    Default CSS Class for pages with sub pages?

    Is this possible? I need to be able to sniff out menu items that have subpages so as to add an indicator graphic next to them.

    Seems like this is common functionality.

  2. #2
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

  3. #3
    coenjacobs's Avatar
    coenjacobs is offline Hello World
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    6

    Default

    Never mind, question was regarding a CSS class.

    EDIT: With get_page_children(), you can get the children of the page you're looking after. Pages with results on this function will have children, zero results will have no children.

    But then again;

    Quote Originally Posted by Ryan View Post
    body.page-parent
    This is for the parent of the current page, not for a page with childs. Guess the get_page_children() function is needed after all?
    Last edited by coenjacobs; 06-07-2010 at 08:15 AM.
    Follow me on Twitter: @cnjcbs or via my blog: http://cnjcbs.com
    Yes, I have a solution for WYSIWYG widgets: Smart WYSIWYG Blocks Of Content

  4. #4
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default

    Quote Originally Posted by coenjacobs View Post
    This is for the parent of the current page, not for a page with childs. Guess the get_page_children() function is needed after all?
    No. It just means that the current page is a parent page, therefore has child pages.


    Mild Fuzz wasn't particularly specific about what they're trying to do though so I'm not sure if that particular class will help or not. It depends on what the context of the problem is.

  5. #5
    Mild Fuzz is offline Here For The Peanuts
    Join Date
    Feb 2010
    Posts
    106

    Default

    Sorry!!

    What I actually want is a class in the <li> item in the global navigation. Like an pull down arrow or similar. So we will neither necessarily be on the parent or child page, it will need to work on all pages as I intend it to be part of the nav.

  6. #6
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default

    I posted a similar question on Twitter recently and did't receive any help.

    I ended up writing a rather long winded and kinda borked rewrite of the wp_list_pages() function to do it. There has to be a better way to do it than what I did, so I won't post it here unless nobody else can come up with a more suitable solution.

  7. #7
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,997

    Default

    If you are looking for a parent or ancestor in the hierarchical tree of the current page, you can use the li.current_page_parent and li.current_page_ancestor classes.

    It would be nice if the function would return classes like "page_parent" and "page_ancestor" for parents/ancestors outside of the current hierarchical tree, but it doesn't, unfortunately. (Strangely, bbPress *does* return similar classes, it its function that lists forums.)
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  8. #8
    hakre's Avatar
    hakre is offline Here For The Peanuts
    Join Date
    Jun 2010
    Posts
    129

    Default

    If you're missing CSS classes and you consider to open a ticket in wordpress trac for it: I opened a ticket regarding improvement of those for widgets where you might want to reference your ticket to as well:

    #12615 - Add "first" and "last" CSS-class-names to each Widget in sidebars (Frontend)
    hakre on wordpress (clicking this all three minutes help to keep the cache fresh - thanks)

  9. #9
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default

    Code:
    <?php
    	echo ereg_replace(
    		"\"><a [/\?a-zA-Z0-9\-\.\:\"\=\_ >]+</a>([\t\n]+)<ul"," haschildren\\0",
    		wp_list_pages()
    	);
    ?>

  10. #10
    aaronwaggs is offline Hello World
    Join Date
    Jan 2009
    Posts
    9

    Default

    This is how I do it.

    PHP Code:
    echo preg_replace('/(<li class="page_item+)(.*<\/a>\s)/',
    '$1 has_children$2',
    wp_list_pages('echo=0')); 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •