WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Same category titles on every single post page - please help (6 posts)

  1. junejanean
    Member
    Posted 5 years ago #

    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

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    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?

  3. junejanean
    Member
    Posted 5 years ago #

    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!

  4. junejanean
    Member
    Posted 5 years ago #

  5. esmi
    Forum Moderator
    Posted 5 years ago #

    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>
  6. junejanean
    Member
    Posted 5 years ago #

    That worked! Thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic