• Resolved terminator87

    (@terminator87)


    I’ve spend a bunch of hours on this matter and I just can’t seem to resolve it so now I’m turning to the forums. Hope somebody can help me here.

    In short: I use the Arras Theme (www.arrastheme.com, most ppl on their forum seem to be on vacation and I’m not blaming them haha) which uses filters.php to display what they call ‘nodes’ (content blocks really) which consist of a thumbnail and the title of the post underneath.

    All I want is to display the category a post belongs to as well. On top of the title, below the thumbnail. I got that going with get_the_category but one problem: it literally displays the words ‘Array’. How can I make it show ‘Category name’?!

    This is de code I have used to display the darn thing:

    function arras_categoryCUSTOM($page_type) {
    	global $post;
    
    $category = get_the_category(); echo '<h3 class="entry-title">' . $category->cat_name . '</h3>';
    /* echo $category->cat_name; */
    
    }

    And then this to get it into the node:

    $postheader .= '<h3 class="entry-title">' . get_the_category() . '</h3>';
    	$postheader .= '<h3 class="entry-title"><a href="' . get_permalink() . '" rel="bookmark">' . get_the_title() . '</a></h3>';

Viewing 4 replies - 1 through 4 (of 4 total)
  • 1 post can belong to more than 1 category, so you will need to run a foreach Loop as per the code example on https://codex.www.ads-software.com/Function_Reference/get_the_category

    Thread Starter terminator87

    (@terminator87)

    Okay, but this is not my problem. I don’t care if a post is in more than 1 category or not ’cause I will not use this.

    When I use get_the_category I can style it perfectly BUT it does not return anything but the word ‘Array’.

    When I use the_category the styling that comes with it in category-template.php (wp-includes) is so different it DOES show the correct category but not WHERE I want it to be.

    Maybe the short question is: how do I give the_category the <div> I want it to be in?

    it does not return anything but the word ‘Array’.

    Because it is an array because it has to be able to hold more than 1 category.. Use a foreach loop and grab the first catgeory name.

    Thread Starter terminator87

    (@terminator87)

    Thanks for your help! Fiddling with it it turned out one single thing was wrong in the code.

    The code that makes it work:

    $categories = get_the_category();
    	$postheader .= '<h3 class="entry-title">' . $categories[0]->cat_name . '</h3>';
    	$postheader .= '<h3 class="entry-title"><a href="' . get_permalink() . '" rel="bookmark">' . get_the_title() . '</a></h3>';
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_the_category only displays 'Array'’ is closed to new replies.