WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Password Protected entries not show up on main page? (8 posts)

  1. wellofdreams
    Member
    Posted 8 years ago #

    Is it possible for posts from a certain section/cetegory of your blog not show up on the main index page?

    For example, I want a certain section to contain private password protected entries, and there's no point in having them cluttering up the main pages...

  2. Mark McKibben
    Member
    Posted 8 years ago #

    You should take a look at this article in the Codex

  3. wellofdreams
    Member
    Posted 8 years ago #

    Thanks ^_^

    I wasn't sure where I was supposed to put the code, so I replaced this: <?php while (have_posts()) : the_post(); ?>

    with 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('26') && is_home()) ) { ?>

    <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; ?>

    But got this error:

    Parse error: parse error, unexpected T_ENDWHILE in /home/.hauser/wellofdreams/blog.canny-cat.com/wp-content/themes/cannycat/index.php on line 56

  4. www.onlinecasinoselite.com
    Member
    Posted 7 years ago #

    How can I esclude password protected posts from main page?

    something such as "if(is_protected()) { continue; }" ?

  5. Kafkaesqui

    Posted 7 years ago #

    <?php if( $post->post_password ) { continue; } ?>

  6. www.onlinecasinoselite.com
    Member
    Posted 7 years ago #

    It works!! Thanks!!

    but if I configured the main index to show the 10 latest posts, if I have one protected, it shows 9. How could I increase or decrease the counter? I mean, what var contains it?

  7. Kafkaesqui

    Posted 7 years ago #

    "How could I increase or decrease the counter?"

    You can't. Anything acting on posts (i.e. The Loop) is stuck working with a pre-existing number in the $posts object because there's no functionality letting you tell it to go back and get one more.

    The goal would be to pass over password-protected posts *before* they end up in the $posts object in the first place. For that, a simple little plugin can do the job...

    Exclude Password Posts plugin:
    Dowload plugin | View source

  8. www.onlinecasinoselite.com
    Member
    Posted 7 years ago #

    resolved

Topic Closed

This topic has been closed to new replies.

About this Topic