• Resolved oh_hello

    (@oh_hello)


    Hi there,

    All I’m trying to do is grab the category’s title in single.php, but I’m not having any luck I’m afraid.

    The whole template for single.php is below, single_cat_title is at about line 6. What am I doing wrong? Thanks in advance.

    <?php get_header(); ?>
    
    	<div id="content">
    
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <h1><?php single_cat_title(); ?> <span class="inhead">- view all <?php the_category(', ') ?> items</span></h1>
    	<h2><?php the_title(); ?></h2>
    				<?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
    	<?php endwhile; else: ?>
    
    	<?php endif; ?>	
    
    	</div>
    
    <?php get_footer(); ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    All I’m trying to do is grab the category’s title in single.php

    Well, there’s your problem. There is no category title when single.php is being displayed. The single.php is used when you’re displaying a Single Post, not a Category Archive.

    single_cat_title is not supposed to do anything unless a Category Archive (or Tag Archive) is being displayed. That’s its whole purpose.

    If you want to display the categories of a Post, use the_category inside the Loop.

    Thread Starter oh_hello

    (@oh_hello)

    Thanks for the reply, is there a way to grab the_category without having it link to the Archives?

    It’s a little more advanced, but you could try this:

    http://codex.wordpress.org/Template_Tags/get_the_category

    Thread Starter oh_hello

    (@oh_hello)

    Beautiful, thanks for the help.

    Great, exactly what I was looking for. I wanted to add the category name in the <title> of the page. Thanks alot.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘single_cat_title not displaying anything’ is closed to new replies.