WordPress.org

Ready to get started?Download WordPress

Forums

index display certain categories (4 posts)

  1. iamsof
    Member
    Posted 8 years ago #

    hi all,

    I'd like to display my default posts on the index page (which is my posts in English), and I put all of my Chinese posts in a category called "Chinese" and these posts are not inthe default category.

    The index page automatically displays all of the posts from every single category, and I tried to change the index.php codes so that the index page only displays default, however, it displays the default category as an archive and all of my blog links are gone because my index page has become an archive page.

    My question is, is it possible to only display the posts in the default cateory on the index page without having it to function as a category archive?

    Thanks.

  2. Michael Bishop

    Posted 8 years ago #

    Yes. You can add <?php query_posts(cat=-2); ?> before the loop in your index. The negative sign excludes, and the # is the ID of the category you want to exclude.

  3. iamsof
    Member
    Posted 8 years ago #

    Parse error: parse error, unexpected '=' in /home/sof/public_html/blog/index.php on line 3

    what is this problem?

  4. janantha
    Member
    Posted 8 years ago #

    Dude here is how to do it..i found the solution

    Following this.it works
    hi guys found the solution
    its something like this

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <!-- The following tests if the current post is in category 3. -->
    <!-- If it is not, the code within The Loop is executed as normal. -->
    <!-- If it is, nothing is done until the next post is processed. -->
    <?php if ( !(in_category('3')) ) { ?>

    <div class="post">

    <h2>"><?php the_title(); ?></h2>

    <small><?php the_time('F jS, Y'); ?></small>

    <div class="entry">
    <?php the_content(); ?>
    </div>

    <p class="postmetadata">Posted in <?php the_category(', '); ?>
    </div> <!-- closes the first div box -->

    <?php } ?> <!-- Close the if statement. -->

    <?php endwhile; else: ?>
    Sorry, no posts matched your criteria.
    <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.