Support » Themes and Templates » get_the_category returns empty array

  • Hello. I’ve tried to set up a wordpress with the custom headers, based on current category selected. I am using permalinks and get_the_category within the following sample:

    $cat = get_the_category();
    print_r($cat);
    $cat = $cat[0];
    print(‘.’.$cat.’.’);
    $cat=$cat->cat_ID;
    print(‘.’.$cat.’.’);

    Returns:
    .Array ( ) …
    in every page.

Viewing 3 replies - 1 through 3 (of 3 total)
  • try something like this:

    <h1 id="header"
    class="<?php if(is_home()) echo('header1');
    elseif(is_category('Pets') ) echo('header2');
    elseif(is_category('Logs') ) echo('header3');
    elseif(is_category('Hair') ) echo('header4');
    elseif(is_single()) echo('header5');
    elseif(is_page())echo('header6'); ?>"><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a></h1>

    oh… set the headers in css

    .header1
    { …. }

    etc

    Thread Starter dmitrek

    (@dmitrek)

    in_category will not work in my case because of the user-management-basis. I would like to leave the site to the owners and since they are not able to add a new code (while still able to upload new pictures for header) I need the solution with getting a category_id number.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get_the_category returns empty array’ is closed to new replies.