Wordpress Themes - WP Forum at BFA
Click here to register or to donate.
Auto self-registration is not available here - far too many spammers. This forum has many, many backlinks and because of that there is an intense desire among spammers to drop their links here.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme » Plugins & Atahualpa »

Help with parent category php? Please!!

Old Jun 27, 2010, 04:23 PM
136 posts · May 2010
Hi All,

I am having some trouble getting some code to work properly and was looking for any insight.

I am trying to get a plugin to pull the post's category name as the title....which it does. BUT it is pulling the sub category name and not the actual top level "parent" category.

Here is the site:


Here is the original code which does work:

switch ($caption_title) {
case 'post_category':
$cat = get_the_category($my_parent);
$cat = $cat[0];
$cat = $cat-> name ;
$my_caption_title = $open_h3.$cat.$close_h3;
case 'post_title':
here is what I tried:

switch ($caption_title) {
case 'post_category':
$category_parent = $my_parent->category_parent;
$cat = get_the_category($parent_id);
$cat = $cat[0];
$cat = $cat-> name ;
$my_caption_title = $open_h3.$cat.$close_h3;
case 'post_title':
this resulted in it pulling the first parent category on my blog for all the slides?!?

Any ideas??

I am really desperate on this one! Can't find anything!

Thanks so much!

Old Jul 6, 2010, 05:05 AM
juggledad's Avatar
23,713 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
1) you need to get the category starting with the post
HTML Code:
global $post;
$categories = get_the_category($post->ID);
2) a post can have multiple categories assigned to it and 'get_the_category()' will
Returns an array of objects, one object for each category assigned to the post.
3) what does $my_parent point to?
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
showing child category menus when selected the parent category mlluch Page & Category Menu Bars 6 Apr 27, 2011 01:12 PM
How to display posts from one parent category only on 'results' page JakeThePeg Center area post/pages 2 Sep 20, 2010 08:44 PM
[SOLVED] Author name and bio in only one parent category. ortixia Post-Kicker, -Byline & -Footer 4 Mar 8, 2010 02:00 PM
sidebars in single posts one parent category only. ortixia Sidebars & Widgets 1 Mar 7, 2010 05:10 AM

All times are GMT -6. The time now is 09:25 AM.

Powered by vBulletin® Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.