Forums

[resolved] Showing Category Title (3 posts)

  1. Buckycat7
    Member
    Posted 2 years ago #

    I'm working on a theme that has different category sections on the home page, like sports, news, commentary, etc. I'm trying to find a way where I can call the category title from the database so if any of the category names change we don't have to do in the code.

    I could I use something like query_post(cat=1) and then just some how call the title?

    This is the coded I'm using for the sections right now:

    <h2>Category 2</h2>
    <ul>
    
    <?php
    								query_posts("cat=7showposts=6");			if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    								<li><a href="<?php the_permalink();?>"><?php the_title();?></a></li>
    
    <?php endwhile; else: ?>
    								<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    								<?php endif; ?> 
    
    </ul>

    So I'm looking for a way to dynamically call the category title into the h2 tag. Any ideas?

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    Use Function_Reference/get_category

    <?php
    $cat = 2;
    $category=get_category($cat);
    // echo "<pre>"; print_r($category); echo "</pre>";
    echo $category->cat_name;
    ?>
  3. Buckycat7
    Member
    Posted 2 years ago #

    Thanks so much. Worked perfectly.

Topic Closed

This topic has been closed to new replies.

About this Topic