Jump to content


This topic is now archived and is closed to further replies.


Wordpress 3.1 HOW to Display PARENT Category for any sub-category post

Recommended Posts

I am using the Classipress Classified Ads theme which must disable various WP functions and rewrite them to work at all.  Classipress uses the wp_term_taxonomy table to assign ALL categories in the "taxonomy" field the value "ad_cat".


So, all queries are by default looking for Categories and sub-categories of posts that are marked by "ad_cat" in this taxonomy.


So post category id 142 might be one child of category id 12, etc. etc.  But all posts are grouped by the common distinction of "ad_cat" so that they can be separated from pages and blogs.


A series of posts are then listed as ADS belonging to such groups as Parent Category... Rentals....sub-category ... Apartments ( with, in my case just two levels...Parent...child of)


But I cannot find a single wordpress function or query which in or outside of the loop of posts looks at the ad/post category id number and then goes UP the hierarchy to retrieve the PARENT Category which the child belongs to and then display the "nice name" such as "Rentals".


It seems that there ought to be a query that keeps track of the parent category of every child category with that information ready to be displayed in every single ad every single time no matter where it is called from or how the ad is sorted.


I created a function which shows the Parent category name extracted from the breadcrumb script but it only returns this information on pages related to the parent category to start with.


Is there a fool-proof "always on" query which displays the Parent category of each post whether as a post summary in a list of posts or on a single post page as easily as it already displays the post title, sub category name, and all post particulars?


So an Ad for "Apartment Rentals" as the sub-category or for "House Rentals" as the sub-category, whether shown in a list of Ad summary boxes or on a single page by itself, always has the Parent category name displayed with the Title and other information?


So that, for instance, a search for NEWEST ADS might show the following....(right now it just shows the "Sub category" name)


Breadcrumbs relies on current page values for categories.... I need something INDEPENDENT of the page values where the ads might be displayed



New Apartment in Belle Haven


"Rentals" >> "Apartment Rentals"




Customized Chevrolet Bel Air


"Cars" >> "Customizations"




Thank you very much for your help!



Share this post

Link to post
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.