• Hi,

    Is it possible to only have the loop run if a user is logged in?
    For example, something like this:

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

    etc.

    Basically I have a category.php file for a specific category, but I only want the posts displayed if a user is logged in. I tried this a few different ways, but am not sure if it’s just my syntax that is wrong, or if it’s just not possible to do.
    Anyone able to shed any light?

    Cheers

Viewing 2 replies - 1 through 2 (of 2 total)
  • You are on the right track, and is_user_logged_in() has an example.

    Thread Starter tobydecks

    (@tobydecks)

    Thanks for replying, but I’m still stuck.

    Here’s the code

    <?php get_header(); ?>
    	<div id="content">
    	<?php include(TEMPLATEPATH."/l_sidebar.php");?>
    	<div id="contentleft">
    	<?php
            if ( is_user_logged_in() ) {
            if (have_posts()) : while (have_posts()) : the_post();
    	the_content();
    	  endwhile; else: ?>
     <p>You need to log in to view this content</p>
     <?php endif; ?>
        <div style="clear:both;"></div>
    	</div>
    
    <?php include(TEMPLATEPATH."/r_sidebar.php");?>
    </div>
    <!-- The main column ends  -->
    <?php get_footer(); ?>

    I just keep getting an unexpected end on line 17.

    Do I have curly brace issues?

    Cheers

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Running loop when logged in’ is closed to new replies.