Results 1 to 6 of 6

Thread: Category description

  1. #1
    Martijn is offline Hello World
    Join Date
    Feb 2010
    Location
    The Netherlands
    Posts
    8

    Default Category description

    Hi, thanks for reading.
    I want to show a category description at the top of an category archive. Is this possible? For example this page (dutch) i would like to give some more information about that category.

    I'n my archive.php I got the following:

    Code:
    <?php /* If this is a category archive */ if (is_category()) { ?>
    <h2 class="title">Al het nieuws voor de categorie: <strong><?php single_cat_title(); ?></strong></h2>
    If I change something here it ofcourse effects all categories.

    So I tried it in Post -> Categories where you can add a "Description" and it says "some themes may show it". Well mine doesn't.

    What piece of code do I need to add so that my theme does show the category description?

  2. #2
    Utkarsh is offline Hello World
    Join Date
    Nov 2009
    Posts
    73

    Default

    Quote Originally Posted by Martijn View Post
    Hi, thanks for reading.
    I want to show a category description at the top of an category archive. Is this possible? For example this page (dutch) i would like to give some more information about that category.

    I'n my archive.php I got the following:

    Code:
    <?php /* If this is a category archive */ if (is_category()) { ?>
    <h2 class="title">Al het nieuws voor de categorie: <strong><?php single_cat_title(); ?></strong></h2>
    If I change something here it ofcourse effects all categories.

    So I tried it in Post -> Categories where you can add a "Description" and it says "some themes may show it". Well mine doesn't.

    What piece of code do I need to add so that my theme does show the category description?
    Use the plugin exec-php

  3. #3
    sleary's Avatar
    sleary is offline Hello World
    Join Date
    Dec 2009
    Location
    Texas
    Posts
    21

    Default

    Code:
    <?php echo category_description(); ?>
    should work.

  4. #4
    Martijn is offline Hello World
    Join Date
    Feb 2010
    Location
    The Netherlands
    Posts
    8

    Default

    Thanks for your replies.

    Quote Originally Posted by Utkarsh View Post
    Use the plugin exec-php
    I'm using it already, it's for displaying PHP in a post.

    Quote Originally Posted by sleary View Post
    Code:
    <?php echo category_description(); ?>
    should work.
    That's exactly what I was looking for, thanks!

  5. #5
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,993

    Default

    Quote Originally Posted by Martijn View Post
    Thanks for your replies.



    I'm using it already, it's for displaying PHP in a post.



    That's exactly what I was looking for, thanks!
    I use this tag, also. Here's my example script (inside the loop, before the post stuff), in context:

    PHP Code:
    <?php if(is_archive()) : ?>
      <?php $post $posts[0]; // Hack. Set $post so that the_date() works. ?>
      <?php if (is_category()) { /* If this is a category archive */  ?>
       <div class="cat-subscribe-feed">
        <a href="<?php bloginfo('url'); ?>/category/<?php $cat get_the_category(); $cat $cat[0]; echo $cat->category_nicename;?>/feed/">
         <img src="<?php bloginfo('template_directory'); ?>/images/subscribewide.jpg" width="120px" height="29" alt="Subscribe to the <?php echo single_cat_title(); ?> category feed" />
         <?php echo single_cat_title(); ?> category feed</a>
       </div>
       <h2 class="pagetitle">
        <?php echo single_cat_title(); ?>
       </h2>
       <div class="cat-description">
        <?php echo category_description(); ?>
       </div>
      
      <?php }  elseif (is_tag()) { /* If this is a tag archive */  ?>
       <div class="cat-subscribe-feed">
        <a href="<?php echo get_tag_feed_link($wp_query->get('tag_id'), 'rss2'); ?>">
         <img src="<?php bloginfo('template_directory'); ?>/images/subscribewide.jpg" width="120px" height="29" alt="Subscribe to the <?php echo single_tag_title(); ?> tag feed" />
         <?php echo single_tag_title(); ?> tag feed</a>     
       </div>
       <h2 class="pagetitle">
        <?php echo single_tag_title(); ?>
       </h2>
       <div class="cat-description">
        <?php     
         
    echo tag_description();
        
    ?>
       </div>
      
      <?php }  else {
       if (
    is_search()) { /* If this is a search */ ?>
       <h2 class="pagetitle">Search Results</h2>
       <?php ?>  
      <?php ?>
      <?php endif ?>
    Here's the bit specific to categories:
    PHP Code:
    <?php if (is_category()) { /* If this is a category archive */  ?>
       <div class="cat-subscribe-feed">
        <a href="<?php bloginfo('url'); ?>/category/<?php $cat get_the_category(); $cat $cat[0]; echo $cat->category_nicename;?>/feed/">
         <img src="<?php bloginfo('template_directory'); ?>/images/subscribewide.jpg" width="120px" height="29" alt="Subscribe to the <?php echo single_cat_title(); ?> category feed" />
         <?php echo single_cat_title(); ?> category feed</a>
       </div>
       <h2 class="pagetitle">
        <?php echo single_cat_title(); ?>
       </h2>
       <div class="cat-description">
        <?php echo category_description(); ?>
       </div>
      
      <?php }
    (The first part builds a link for the feed for the displayed category)
    And note that it can also be used for tag pages:
    PHP Code:
    <?php }  elseif (is_tag()) { /* If this is a tag archive */  ?>
       <div class="cat-subscribe-feed">
        <a href="<?php echo get_tag_feed_link($wp_query->get('tag_id'), 'rss2'); ?>">
         <img src="<?php bloginfo('template_directory'); ?>/images/subscribewide.jpg" width="120px" height="29" alt="Subscribe to the <?php echo single_tag_title(); ?> tag feed" />
         <?php echo single_tag_title(); ?> tag feed</a>     
       </div>
       <h2 class="pagetitle">
        <?php echo single_tag_title(); ?>
       </h2>
       <div class="cat-description">
        <?php     
         
    echo tag_description();
        
    ?>
       </div>
      
      <?php }
    (Likewise, the first part builds the RSS feed link for the tag. Just skip down to the H2 class="pagetitle" and following, for displaying just the Category/Tag title, and description.)
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  6. #6
    Martijn is offline Hello World
    Join Date
    Feb 2010
    Location
    The Netherlands
    Posts
    8

    Default

    Oh great idea to use it in tag's also :).

    Cheers!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •