WordPress.org

Ready to get started?Download WordPress

Forums

get_the_category returns empty array (4 posts)

  1. Dmitrek
    Member
    Posted 8 years ago #

    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.

  2. Mark (podz)
    Support Maven
    Posted 8 years ago #

    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>

  3. Mark (podz)
    Support Maven
    Posted 8 years ago #

    oh... set the headers in css

    .header1
    { .... }

    etc

  4. Dmitrek
    Member
    Posted 8 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.