- This topic has 33 replies, 2 voices, and was last updated 3 years, 8 months ago by Tom.
-
AuthorPosts
-
June 3, 2020 at 4:19 pm #1313326TomLead DeveloperLead DeveloperJune 5, 2020 at 1:10 am #1315116William
Unfortunately not I’m afraid
June 5, 2020 at 9:55 am #1315878TomLead DeveloperLead DeveloperCustom stuff like this can take some fiddling.
Anything now?: https://generatepress.com/forums/topic/template-tags-for-parent-child-category-separated/#post-1305635
June 5, 2020 at 10:38 am #1315924WilliamFor that code, this now appears:
array(0) { }
June 5, 2020 at 7:51 pm #1316328TomLead DeveloperLead DeveloperHmm, 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-1305635Anything?
June 6, 2020 at 6:55 am #1316741WilliamHi 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?
June 6, 2020 at 4:46 pm #1317360TomLead DeveloperLead DeveloperWe 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?
June 8, 2020 at 6:13 am #1319068WilliamSure thing – I tried your lastest suggestion and still not luck
June 8, 2020 at 3:55 pm #1319926TomLead DeveloperLead DeveloperOk, 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 🙂
June 10, 2020 at 1:30 am #1321684WilliamThat has caused a load of gobbledygoop to appear here:
https://bookanalysis.com/albert-camus/the-stranger/analysis/
June 10, 2020 at 9:48 am #1322444TomLead DeveloperLead DeveloperThat’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?
June 10, 2020 at 2:36 pm #1322748WilliamI’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
June 10, 2020 at 4:01 pm #1322800TomLead DeveloperLead DeveloperYes, 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.
June 11, 2020 at 12:54 am #1323126William‘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?
June 11, 2020 at 9:46 am #1323944TomLead DeveloperLead DeveloperWordPress 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.
-
AuthorPosts
- You must be logged in to reply to this topic.