Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

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

Help with parent category php? Please!!


  #1  
Old Jun 27, 2010, 05:23 PM
theadventurebite
 
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:

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
  #2  
Old Jul 6, 2010, 06:05 AM
juggledad's Avatar
juggledad
 
23,765 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
Quote:
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

Bookmarks



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 02:12 PM
How to display posts from one parent category only on 'results' page JakeThePeg Center area post/pages 2 Sep 20, 2010 09:44 PM
[SOLVED] Author name and bio in only one parent category. ortixia Post-Kicker, -Byline & -Footer 4 Mar 8, 2010 03:00 PM
sidebars in single posts one parent category only. ortixia Sidebars & Widgets 1 Mar 7, 2010 06:10 AM


All times are GMT -6. The time now is 04:57 PM.


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