Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Plugins & Atahualpa (http://forum.bytesforall.com/forumdisplay.php?f=16)
-   -   Help with parent category php? Please!! (http://forum.bytesforall.com/showthread.php?t=7809)

theadventurebite Jun 27, 2010 04:23 PM

Help with parent category php? Please!!
 
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:

http://theadventurebite.com/cookinga...ing-home-page/

Here is the original code which does work:

Code:

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;
break;
case 'post_title':

here is what I tried:

Code:

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;
break;
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!

Dani:)

juggledad Jul 6, 2010 05:05 AM

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
Quote:

Returns an array of objects, one object for each category assigned to the post.
3) what does $my_parent point to?


All times are GMT -6. The time now is 08:49 AM.

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