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)?
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>
You have to get the array of categories and echo the first one from the array.
http://codex.wordpress.org/Function_Reference/get_the_category
According to wordpress developers codex:
This will give you the first category and also link it to that category’s page.
there is also a shortcodes plug in that will help create lists based on categories, terms, etc. http://wordpress.org/plugins/display-posts-shortcode/