WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Categories listed for Pages (4 posts)

  1. MattLawlis
    Member
    Posted 7 years ago #

    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!

  2. Kafkaesqui

    Posted 7 years ago #

    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()".

  3. MattLawlis
    Member
    Posted 7 years ago #

    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]

  4. Kafkaesqui

    Posted 7 years ago #

    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:

    http://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; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic