Skip to:
Content
Pages
Categories
Search
Top
Bottom

Parent / Childrelationship in forum loop


  • kevinjohngallagher
    Member

    @kevinjohngallagher

    At the risk of looking like a double whammy in regards to the non nesting iterations of our outputted code, just using TRs with different classes, i’ve hit across another wee issue – but this time i’m sure there’s a simple solution I just can’t see the relavent code.

    I want to be able to know if a forum has children or not, or more specifically when we move up or down a level in the “xPath” iteration.

    I’m using a method of using $GLOBALS->forum_parent but what this currently requires me doing is testing to see if the forum has a parent that is not a category, then checking to see if the parent is the same as the previous forums parent, and then output relavent code to nest the forum in an actual parent child format:

    Category

    – Forum

    – Forum

    – – Forum

    – – Forum

    – Forum

    This obviously creates havok and rather messy code for the closing of the nestings.

    I realise that for small websites this will look like a formatting issue, but once you reach more than 2 levels in a parent child relationship, the ability to control nested relationships makes a huge difference.

    Thanks for the help folks

    EDIT:

    Ok, i think i’ve found half the solution to the issue, and maybe i can phrase the question better now in BBterms…

    I want to know, via PHP, before any code has been sent to the browser for the forum, if it is a FIRST CHILD or a LAST CHILD.

    Now obviously, BBpress knows this because it’s outputting bb-last-child bb-first-child css, but how can I access these settings on the front-page.php ?

    Thanks alot for all the help

Viewing 8 replies - 1 through 8 (of 8 total)

  • kevinjohngallagher
    Member

    @kevinjohngallagher

    Well, there’s no good way of putting this without making it look like i’m flogging my own dead horse, but here goes:

    Can someone tell me why we’re working out vital data in regards to each forum on as CSS links?

    Why on Earth don’t we work out each attribute at the start of the loop, and then feed off an object, giving our template developers and therefore users far more options?

    As it stands, we call bb_forum_class(); inside the TR, which then creates the $bb_forums_loop object; which calls classes();, and that works out all the attributes of the forum, but rather than sending them back as a usable object the whole thing returns a string of CSS code.

    Why not allow template developers access to:

    $bb_forums_loop->first_child

    $bb_forums_loop->last_child

    $bb_forums_loop->bb_root

    etc?

    I mean, the code itself if great, and the job you’ve done is really good, but it fixes one singular issue (getting the right CSS output), rather than fixing the bigger problem of not knowing all attributes of the forum. Not only does it lead to very messy templates (if someone can be bothered to deal with it – and i’ve not seen a template that has yet), but it does indeed duplicate alot of the work.


    kevinjohngallagher
    Member

    @kevinjohngallagher

    Funnily enough i’ve made the same hack solution as instructed in this topic: https://bbpress.org/forums/topic/hiding-subforums-subforums-from-subforum-pages

    The problem is, the idea of checking for the forum parent id is ok when dealing with a singular table. If it’s got the same parent fine, if it’s not do something else. But the whole thing starts to get messy when dealing with non-linear tables. If your forum has multiple sub forums or parent child relationships the whole thing starts to crumble, or if you’re using a javascript DOM indexer 9say you want open close functionality), or if you’re aiming for a a UL/LI version instead of tables (i’m not against tables for tabular data btw – but for parent child iterations screen readers prefer UL/LI loops).

    I’ll post my theme with these hacks and hopefully you can see what I mean, because i’m a bit stunned about how rigid this all is given the excellent coding that’s been developed by the authors so far.


    kevinjohngallagher
    Member

    @kevinjohngallagher

    So, the issue with the method implemented in : https://bbpress.org/forums/topic/hiding-subforums-subforums-from-subforum-pages

    is that it only checks for the lineage of the forum before it.

    This causes problems when you have multiple children to multiple children, as thus:

    category

    – Forum1

    – – Child 1

    – – – Child1’s child

    – – Child 2

    That method will make BBpress think that Child 2 is actually under Child1’s Child, because when testing if their parents are the same they clearly are not.

    Instead, we have to create a nesting code that counts the depth to which we go as we trawl through each parent/child relationship – which is daft as there is a walker->depth function that we just don’t have access to via $GLOBALS.

    EDIT:

    Update – not knowing if it’s the last forum in a category is starting to kill me a little.


    _ck_
    Participant

    @_ck_

    You can work around this problem by doing a scan of the $forums global before entering the main loop and checking the “rank” or “type” of forum for each listing.

    In fact you can replace the loop entirely with your own routine, as long as you global $forum you can set the $forum to any which one you want and the internal functions will still work.

    So essentially do a pre-loop through the forums, build your own array of how you’d like the output, and then do the main loop to output the forums in the order/design that you’d like. Just be sure to set $forum to the current forum you are working with before calling any of the forum functions.

    ps. You *can* access

    $bb_forums_loop->first_child
    $bb_forums_loop->last_child
    $bb_forums_loop->bb_root

    if you wish. Just do a global $bb_forums_loop; outside of the loop, then inside the loop they are available to you.


    kevinjohngallagher
    Member

    @kevinjohngallagher

    Hi _CK_,

    Once again thanks for a great technical answer.

    Can i follow it up with a quickie though:

    Where in the documentation is all of those methods listed?

    Are there other things i can call from $bb_forums_loop that may help is theme developers?

    Where is the documentation for them?

    P.S. your answer really helped me alot, i’ll rewrite by current code now :)


    Sam Bauers
    Participant

    @sambauers

    I just realised that all you want is a bb_get_forum_class_names() function.

    This is now in trunk, see [2089] .


    Sam Bauers
    Participant

    @sambauers

    The new function is only useful inside the forum loop by the way. Just like other loop bound template functions – like bb_forum_pad().

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar