• Resolved mattlawlis

    (@mattlawlis)


    Whenever you open a post in your blog, you usually see the category in which the blog post was posted in.

    It does this for me for my blog, but it also does that for my pages, even though there is no option in the Admin to set categories for pages.

    I need to know how to make it to where it only lists categories for posts, and not for pages.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Kafkaesqui

    (@kafkaesqui)

    If your current theme is using a Page template (page.php), find and remove this line from it:

    <?php the_category(); ?>

    If it doesn’t, you can modify the theme’s main index template (index.php) so it will not display on a Page query:

    <?php if( !is_page() ) the_category(); ?>

    The logic of the above code goes “if NOT on a Page, run the_category()“.

    Thread Starter mattlawlis

    (@mattlawlis)

    Tried removing that code, it didn’t display the categories for posts or pages… and I want it to show the categories for posts. Here is my index.php:
    <?php
    if (!$_SERVER['QUERY_STRING']) {
    $shwSpr = 1;
    }
    get_header();
    ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post">
    <div class="data">
    <?php the_time('F jS, Y') ?>
    </div>
    <h3 class="storytitle" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
    <?php the_title(); ?>
    </a></h3>
    <div class="autor">Posted by
    <?php the_author() ?>
    in
    <?php the_category(', ') ?>
    <?php if( !is_page() ) the_category(); ?>

    [Moderated: snip]

    Kafkaesqui

    (@kafkaesqui)

    First, around here it’s preferred large blocks of code (like an entire template) be posted elsewhere and linked to. One site we often use for that is:

    https://wordpress.pastebin.ca

    Anyway, note I’ve snipped off just where the issue exists. You haven’t edited, bu rather added to, your template. Take this part:

    <div class="autor">Posted by
    <?php the_author() ?>
    in
    <?php the_category(', ') ?>
    <?php if( !is_page() ) the_category(); ?>

    And change it to:

    <div class="autor">Posted by
    <?php the_author() ?>
    <?php if( !is_page() ) : ?>
    in <?php the_category(', ') ?>
    <?php endif; ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Categories listed for Pages’ is closed to new replies.