[Resolved] Template tags for parent/child category separated

Home Forums Support [Resolved] Template tags for parent/child category separated

Home Forums Support Template tags for parent/child category separated

Viewing 15 posts - 16 through 30 (of 34 total)
  • Author
    Posts
  • #1313326
    Tom
    Lead Developer
    Lead Developer
    #1315116
    William

    Unfortunately not I’m afraid

    #1315878
    Tom
    Lead Developer
    Lead Developer
    #1315924
    William

    For that code, this now appears:

    array(0) { }

    #1316328
    Tom
    Lead Developer
    Lead Developer

    Hmm, so no categories exist with that parent.

    I tried child_of instead: https://generatepress.com/forums/topic/template-tags-for-parent-child-category-separated/#post-1305635

    Anything?

    #1316741
    William

    Hi there, the child category is ‘The Stranger’ with the parent category being ‘Albert Camus’ on this page:

    https://bookanalysis.com/albert-camus/the-stranger/analysis/

    Would you like access to the site, to help debug this quicker?

    #1317360
    Tom
    Lead Developer
    Lead Developer

    We have a policy where we don’t actually make changes to customer sites – the chance of errors is too high, unfortunately.

    Did my latest code output anything on the page?

    #1319068
    William

    Sure thing – I tried your lastest suggestion and still not luck

    #1319926
    Tom
    Lead Developer
    Lead Developer

    Ok, one more try: https://generatepress.com/forums/topic/template-tags-for-parent-child-category-separated/#post-1305635

    If that doesn’t work I’ll whip up a local install and work through it 🙂

    #1321684
    William

    That has caused a load of gobbledygoop to appear here:

    https://bookanalysis.com/albert-camus/the-stranger/analysis/

    #1322444
    Tom
    Lead Developer
    Lead Developer

    That’s good! You can remove the var_dump() line to remove the mess.

    The list that shows up under it are all categories that are children to the current category – does that look right?

    #1322748
    William

    I’ve removed that line and now a bullet point list appears for all the categories:

    https://bookanalysis.com/albert-camus/the-stranger/analysis/

    For the above page, the child category is ‘The Stranger’ that should appear

    #1322800
    Tom
    Lead Developer
    Lead Developer

    Yes, right now it’s displaying all the categories that are an ancestor (child or distant child) of the current category you’re viewing.

    It looks like The Stranger is last one the list there. I’m not sure how you would specify which category to display if there are multiples like this. You could target the first one or last one quite easily, but I’m not sure if it’s that simple in your case.

    #1323126
    William

    ‘Albert Camus’ is the parent category and the only child category to it is ‘The Stranger’ so I’m not sure why others are displaying?

    #1323944
    Tom
    Lead Developer
    Lead Developer

    WordPress itself should handle this quite well, but it depends on the value we’re getting as the current category. If the current post we’re viewing has more than one category, it’s going to grab the first category it can and then find children for it.

    For complex relationships like this, you may want to look into something like Pods (https://pods.io/) or Advanced Custom Fields.

    Otherwise, you’re starting to look at a quite complex custom solution using PHP.

Viewing 15 posts - 16 through 30 (of 34 total)
  • You must be logged in to reply to this topic.