Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a password-protected page, for whom I'd like to use a custom template to query posts from a specific category. How can I achieve that query_posts should work only after users submit the password of the page? I'm trying with this but doesn't work (page only displays header and footer)

<?php
/*
Template Name: xxxx
*/
?>

        <?php get_header(); ?>
            <?php if ( post_password_required() ) : ?>
            <?php query_posts('cat=9'); ?>
            <?php while ( have_posts() ) : the_post(); ?>


            <a href="<?php the_permalink(); ?>"><h1 style="padding-top:0;margin-top:-5px" class="entry-title"><?php the_title(); ?></h1></a>
                <div class="entry-content" style="padding:0"><?php the_content(); ?></div>
                                        <div class="entry-meta">
                    <?php edit_post_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?>
                    </div>


            <?php endwhile; ?>
            <?php endif; ?>


        <?php get_footer(); ?>
share|improve this question
Solved with this code :) pastebin.com/HkH9UyBF – MultiformeIngegno Nov 6 '12 at 12:29
So the answer stays hidden on an external site? Shall I close the question, or will you add an answer here? – toscho Nov 6 '12 at 13:27
Uhm, I don't have enough rep to answer my questions.. – MultiformeIngegno Nov 6 '12 at 17:52

1 Answer

up vote 0 down vote accepted

separate the queries for the current page and the query for all posts in a category.
Untested example:

<?php
/*
Template Name: xxxx
*/
?>

<?php while ( have_posts() ) : the_post(); ?>
<?php get_header(); ?>
<?php if ( post_password_required() ) :
    $args = array(
        'cat' => 9,
        'numberposts' => -1,
        );
    $posts = get_posts( $args );
    foreach( $posts as $post ) : setup_postdata($post); ?>
        <a href="<?php the_permalink(); ?>">
            <h1 style="padding-top:0;margin-top:-5px" class="entry-title"><?php the_title(); ?></h1>
        </a>
        <div class="entry-content" style="padding:0"><?php the_content(); ?></div>
        <div class="entry-meta">
            <?php edit_post_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?>
        </div>
    <?php endforeach; ?>

<?php endif; ?>
<?php get_footer(); ?>
<?php endwhile; ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.