• Hi – I’m using a theme but I’ve heavily modified it. Also I’m totally new to WP so please go easy. It seems the category links and monthly archive links share the same php page on my site, in this instance, Archive.php.

    I want to display <?php echo category_description(); ?> in the template – and the cool thing is, when I paste this into archive.php it does render the category description – except when I want to view a Monthly Archived page, it throws a fatal error as it doesn’t like the code above (I guess as there is no category description say fo rthe month of “June” etc).

    What would be a good way around this? Can someone help me by writing an If else bit of code or do I need to set up separate php pages – one for categories and one for archives. Help, I’m well new at this!

    Thanks

    Sam

Viewing 4 replies - 1 through 4 (of 4 total)
  • try this code

    <?php
    $cat_name = single_cat_title();
    $cat_id = get_cat_id($cat_name);
    echo category_description($cat_id);
    ?>

    Thread Starter samdavis

    (@samdavis)

    Thanks but I’m still getting the following error on my “Monthly” archives

    Catchable fatal error: Object of class WP_Error could not be converted to string in

    In and ideal world, my category pages would say the category description and when selecting a monthly page and/or tag page (both of which also use archive.php) it would say something like “June Posts” or “TAGNAME posts” etc

    Try:

    <?php if( is_category() ) echo category_description();
    elseif( is_date() ) echo the_date('F') . 'posts';
    elseif( is_tag() ) echo single_tag_title() . 'posts';?>
    Thread Starter samdavis

    (@samdavis)

    That was great – I used your code but in the end swapped the the_date() tag with single_month_title() and works perfectly.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Category Descriptions and pages’ is closed to new replies.