0

I'm a novice and Ii'm trying to edit my theme. I need to show the category after text "Listed in:":

//echo $todaydate;
if(is_array($rec_dates) && strtolower(trim($is_recurring)) == strtolower(trim('Recurring event')) && in_array($todaydate,$rec_dates)){ /* if recurring event */
$c = $counter++;
$recurrence_days = get_post_meta($post->ID,'recurrence_days',true); //on which day
//  print_r($rec_dates);
$end_date1 = strtotime(date("Y-m-d", strtotime($todaydate)) . " +$recurrence_days day");
$end_date = get_formated_date(date('Y-m-d', $end_date1));
$start_date1 = strtotime(date("Y-m-d", strtotime($todaydate)) . " +$recurrence_days day");
$start_date = get_formated_date(date('Y-m-d', $start_date1));
    $post_info .=' 
    <a class="event_title" href="'.get_permalink($post->ID).'">'.$post->post_title.'</a><small>'.
    __('<b>Listed in: </b>').***which code here to show the category?***.'<br>'.
    __('<b>Location: </b>').get_post_meta($post->ID,'address',true) .'<br>'.
    __('<b>Start Date: </b>').get_formated_date(get_post_meta($post->ID,'st_date',true)).' '.get_formated_time(get_post_meta($post->ID,'st_time',true)) .'<br />'. 
    __('<b>End Date: </b>').get_formated_date(get_post_meta($post->ID,'end_date',true)).' '.get_formated_time(get_post_meta($post->ID,'end_time',true)) .'</small>';
}else if(strtolower($is_recurring) == strtolower('Regular event')){ /* if regular event */
        $post_info .=' 
    <a class="event_title" href="'.get_permalink($post->ID).'">'.$post->post_title.'</a><small>'.
    __('<b>Listed in: </b>').***which code here to show the category?***.'<br>'.
    __('<b>Location: </b>').get_post_meta($post->ID,'address',true) .'<br>'.
    __('<b>Start Date: </b>').get_formated_date(get_post_meta($post->ID,'st_date',true)).' '.get_formated_time(get_post_meta($post->ID,'st_time',true)) .'<br />'. 
    __('<b>End Date: </b>').get_formated_date(get_post_meta($post->ID,'end_date',true)).' '.get_formated_time(get_post_meta($post->ID,'end_time',true)) .'</small>';                            
}
endwhile;
$post_info .='</span>';
}

1 Answer 1

0

This might help you to get categories of particular post

$catList =get_the_category($post->ID);
foreach($catList as $single){
echo $single->cat_name;
}

You can also check from below links

5
  • ok for the loop. But what i write here? __('<b>Listed in: </b>').***which code here to show the category?***.'<br>'.
    – mfab67
    Nov 11, 2014 at 16:08
  • $category = get_the_category(); $catName = $category[0]->cat_name; __('<b>Listed in: </b>'). $catName .'<br>'.
    – ManuA
    Nov 11, 2014 at 16:28
  • It doesn't show anything. $category = get_the_category(); $catName = $category[0]->cat_name; $post_info .=' <a class="event_title" href="'.get_permalink($post->ID).'">'.$post->post_title.'</a><small>'. __('<b>Listed in: </b>').$catName.'<br>'. __('<b>Location: </b>').get_post_meta($post->ID,'address',true) .'<br>'. __('<b>Start Date: </b>').get_formated_date(get_post_meta($post->ID,'st_date',true)).
    – mfab67
    Nov 11, 2014 at 19:03
  • $category = get_the_category($post->ID);.this should work
    – ManuA
    Nov 12, 2014 at 5:13
  • No, i already tried it but it doesn't show anything.
    – mfab67
    Nov 12, 2014 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.