WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Cant seem to display category description in archive.php (11 posts)

  1. dave-g-o
    Member
    Posted 4 years ago #

    Hi all,

    I am trying to display a category description in an archive page. The following code will display the category title in my archive page:

    <?php if (have_posts()) { ?>
    					<?php $post = $posts[0]; ?>
    						<h2 class="title">
    							The Archive for
    							<?php
    							if (is_category()) { single_cat_title(); }
    							elseif (is_tag()) { ?>  posts tagged "<?php single_tag_title(); ?>" <? }
    							elseif (is_day()) { the_time('F jS, Y'); }
    							elseif (is_month()) { the_time('F, Y'); }
    							elseif (is_year()) { the_time('Y'); }
    							elseif (is_author()) { the_author(); }
    							 ?>
    						</h2>

    I have tried calling the category_description with no luck. Does anyone know a simple solution?

    Thanks

  2. Edward Caissie
    Theme Review Admin
    Posted 4 years ago #

    Did you insert into your code the following:

    echo category_description();

    It should display the current category, or the description from the first category called in a list of categories.

    There are more examples on the codex page here: http://codex.wordpress.org/Template_Tags/category_description

    I know I often forget to 'echo' some functions, that's why I am suggesting it ... hope it helps.

  3. dave-g-o
    Member
    Posted 4 years ago #

    Cool thanks, any idea where abouts?

  4. Stian Andreassen
    Member
    Posted 4 years ago #

    Try <?php echo category_description(); ?> right below the </h2>

  5. dave-g-o
    Member
    Posted 4 years ago #

    Ok just tried that and not seeing any descriptions:

    http://www.magic-photography.co.uk/

    if you click on the 'recent gigs' (category list) only a title appears?

    Thanks again

  6. Stian Andreassen
    Member
    Posted 4 years ago #

    Sorry, I was inaccurate. You must include the ID for the category:

    <?php echo category_description(ID); ?>

    For example:

    <?php echo category_description(3); ?>
  7. dave-g-o
    Member
    Posted 4 years ago #

    ya but I dont know what the category is, as I will want this to appear under each unique category,
    So if you click category 1 you see a title and description, categor 2 a different title and description, and so on..

  8. dave-g-o
    Member
    Posted 4 years ago #

    either way it still did not work putting in a '3' or any number..

    Any ideas anyone?

  9. Edward Caissie
    Theme Review Admin
    Posted 4 years ago #

    At the end of the codex page I linked to there is an example that appears to be what you are looking for ...

    ... in your code try this:

    <?php
      if (is_category()) { single_cat_title(); echo category_description(); }
      elseif (is_tag()) { ?>  posts tagged "<?php single_tag_title(); ?>" <? }
      elseif (is_day()) { the_time('F jS, Y'); }
      elseif (is_month()) { the_time('F, Y'); }
      elseif (is_year()) { the_time('Y'); }
      elseif (is_author()) { the_author(); }
    ?>

    Although I did not notice the words: "The Archive for" as I would expect, make sure you are editing the correct archive page. This link may help as well: http://codex.wordpress.org/Templates_Hierarchy

  10. dave-g-o
    Member
    Posted 4 years ago #

    as yes. I removed 'archive for' on purpose. Thanks for the help I will give it a go.

  11. dave-g-o
    Member
    Posted 4 years ago #

    worked perfectly, thanks so much

Topic Closed

This topic has been closed to new replies.

About this Topic