You have to pass the parent category id to get the child of corresponding categories.
$categories=get_categories(
array( 'parent' => $cat_id )
);
Thank you,
Vignesh Pichamani.
Hi, thank you for your answers.
I have already tested that solution, but unfortunately it does not help me.
Will try to explain the structure of my categories a bit better.
The page “Categories” displays;
– Category 1 (Title)
— Post 1 (Title & image)
— Post 2 (Title & image)
– Category 2 (Title)
— Post 1 (Title & image)
— Post 2 (Title & image)
Current situation that i need to fix look like this:
– Category 1 (Title)
— Post 1 (Title & image)
—- Post 1.1 (Child to “Post 1” – Should not be listed)
— Post 2 (Title & image)
– Category 2 (Title)
— Post 1 (Title & image)
—- Post 1.1 (Child to “Post 1” – Should not be listed)
— Post 2 (Title & image)
-
This reply was modified 8 years, 3 months ago by
mrtargets.
by default, posts do not have a hierarchical structure, as for example static pages would have.
how do you define your posts as ‘Child to’ another post?
what theme are you using?
Thanks for your reply.
It was me who had missed a little in my explanation, sorry for that.
Here is an updated version of the structure:
– Category 1 (Title)
—- Category 1.1 (Posts in this child category should not be listed on page)
— Post 1 (Title & image)
— Post 2 (Title & image)
– Category 2 (Title)
—- Category 2.1 (Posts in this child category should not be listed on page)
— Post 1 (Title & image)
— Post 2 (Title & image)
It is by the way a theme I have written myself, no pre-written framework.
-
This reply was modified 8 years, 3 months ago by
mrtargets.
-
This reply was modified 8 years, 3 months ago by
mrtargets.
How does Michael’s SE link not help you? get_terms() with a parent argument of 0 will only return top level terms, which appears to be exactly what you want.
Hello again
I do not know how to make me clearer but when I use “parent => 0” I get the following structure:
– Main category
— All posts in the system, no matter what category they are in – parent or child.
The way I want the structure to look like is as follows:
– Main category – Should not show
— Subcategory 1 – Print out name och category
— Post in Subcategory 1 – Print out title and image
—- Child to Subcategory 1 – NOT visible
—– Posts in children to subcategory 1 – not shown
— Subcategory 2 – Print out name och category
— Post in Subcategory 2 – Print out title and image
—- Child to Subcategory 2 – NOT visible
—– Posts in children to subcategory 2 – not shown
Well, it wasn’t clear before that you did not want the main category. Thank you for clarifying.
If you do not want the main category, do not use 'parent'=> 0, instead of 0, use the ID of the subcategory’s parent, the “Main category” ID. For each sub-category returned, use get_posts() using the ‘cat’ argument to get posts with the respective term assigned.
Hello again and thank you very much to all those who thought about this issue.
I will sit down and rewrite the code from start to finish and we’ll see where I land. Believe that I may have thought wrong from the beginning: P