WordPress.org

Support

Support » Themes and Templates » [Resolved] Same category titles on every single post page – please help

[Resolved] Same category titles on every single post page – please help

  • Hello,

    On my single.php, I have the category(s) up top, but the same three categories keep appearing on every post – “MUSIC | MOVIES | NEWS” – I have tried several different php code variations and nothing is working. The following code is what I have and seems to give me what I want, EXCEPT it repeats the same 3 categories in every post.

    <h1 class="section"><?php the_category(' |') ?></h1>

    I have been working on this problem for awhile and feel like there is a very simple solution but I cannot get it work no matter what I try. I am not a programmer and have read all the docs and searched and read every other question pertaining – please any help would MUCH appreciated.

    Thanks in advance,
    Janean

Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi

    @esmi

    Forum Moderator

    The code you are using displays links to the categories that the currently displayed post belongs to – assuming that you’re using it within The Loop. So it looks like all of your posts are filed under Music, Movies and News.

    What is it that you’re trying to do?

    Thanks Esmi for your reply.
    I want to show the different categories that the post has been appointed.

    Do I just need to put the code within the loop? If so, where would be the appropriate place?

    Here’s my loop for a single post:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<div id="post-<?php the_ID(); ?>" class="single-post">
    	<h2 class="title"><?php the_title(); ?></h2>
    	<h3 class="author">By <?php the_author() ?></h3>
    	<?php the_content(); ?>
    	<?php the_tags( '<p class="tags"><strong>TAGS:</strong ', ', ', '</p>'); ?>
    	</div>
    
    	<div class="comments-template">
    
    	<?php comments_template(); ?>
    
    	<?php endwhile; else: ?>
    
    	<p>Sorry, no posts matched your criteria.</p>
    
    	<?php endif; ?>
    
    	</div>

    thanks for your help!

    esmi

    @esmi

    Forum Moderator

    It does depend where you want to show the post’s category list but, looking at your site, the foot of the post just below the tags and before the comment form seems to be one logical place. Try using:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div id="post-<?php the_ID(); ?>" class="single-post">
    
    <h2 class="title"><?php the_title(); ?></h2>
    <h3 class="author">By <?php the_author() ?></h3>
    
    <?php the_content(); ?>
    
    <?php the_tags( '<p class="tags"><strong>TAGS:</strong ', ', ', '</p>'); ?>
    <p class="categories">Filed under <?php the_category(', '); ?></p>
    </div>
    
    <div class="comments-template">
    <?php comments_template(); ?>
    
    <?php endwhile; else: ?>
    
    <p>Sorry, no posts matched your criteria.</p>
    <?php endif; ?>
    
    </div>

    That worked! Thanks so much!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Same category titles on every single post page – please help’ is closed to new replies.
Skip to toolbar