Get the name of the first category

I am trying to create a single page that lists the content of each category. I have managed to create the list. I now need to get the name of the category. I have the following code:

<ul>
    <li> CATEGORY NAME HERE </li>

    <?php query_posts('cat=0'); ?>
    <?php while ( have_posts() ) : the_post(); ?>
        <li>
            <a href="<?php echo get_permalink(); ?>">
            <?php the_title(); ?></a>
        </li>
    <?php endwhile; ?>
</ul>

How to call the name of the first category (0)?

Read More

Current edit: Why won’t multiple works?

<div class="first-col">
    <ul>
        <?php query_posts('cat=0'); ?>
        <?php while ( have_posts() ) : the_post(); ?>

        <li> <?php $category = get_the_category(); 
        echo $category[0]->cat_name;
        ?> </li>
        <li>
            <a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a>
        </li>
        <?php endwhile; ?>
    </ul>
</div>

<div class="first-col">
    <ul>
        <li> <?php $category = get_the_category(); 
        echo $category[0]->cat_name;?> </li>

        <?php query_posts('cat=3'); ?>
        <?php while ( have_posts() ) : the_post(); ?>
            <li>
                <a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a>
            </li>
        <?php endwhile; ?>

    </ul>
</div>

Related posts

Leave a Reply

3 comments

  1. According to wordpress developers codex:

        $categories = get_the_category();
    if ( ! empty( $categories ) ) {
        echo '<a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">' . esc_html( $categories[0]->name ) . '</a>';
    }
    

    This will give you the first category and also link it to that category’s page.