Skip to:
Content
Pages
Categories
Search
Top
Bottom

query_posts topic content – private forum


  • acornale
    Participant

    @acornale

    Hi,

    I’m building a forum based website at the moment. You can see the progress here (it’s no where near finished yet): http://pkuconnect.wp-dev.com.au/

    At the bottom of the home page, there are 3 columns: News & Events, Forum Activity, Latest Recipes. Forum Activity and Latest Recipes are both private forums (News & Events are just posts).

    Now, when you aren’t logged in, the forum and recipes boxes on the home page are empty. However, when you are logged in, they show the 4 latest topics titles with links to the topics for more information – similar to how the latest news and events is working.

    What I want to do is show the latest 4 topic titles in each forum to EVERYONE and not just logged in users so that non-logged in users aren’t shown blank boxes. The aim is to prompt the user to log in once they click on one of the links to view more. I can do this by editing the 404.php template. However, for the life of me, I can’t figure out how to feed topic titles and links through to the home page from private forums to non-logged in users.

    Is there a way to query_posts from private forums for non-logged in users?

    Andrew

Viewing 4 replies - 1 through 4 (of 4 total)

  • Robin W
    Moderator

    @robin-w

    I presume the forums are currently private?

    What code are you using to display the latest 4 topics


    acornale
    Participant

    @acornale

    Correct. The forums are currently private. When I’m logged in, the feeds work fine but for non-logged in users, they see blank boxes.

    This is the code I’m using to display the latest 4 topics:

    <?php query_posts( array( ‘post_parent’ => ’89’, ‘post_type’ => ‘topic’, ‘posts_per_page’ => ‘4’, ‘order’ => ‘DESC’, ‘offset’ => ‘0’ ) );?>
    <?php if(have_posts()):while(have_posts()):the_post();?>

    <div class=”home-forum-single”>

    <span class=”entry-date”><?php echo get_the_date(); ?></span>
    <?php the_title();?>

    </div><!– end home forum single –>

    <?php endwhile;?>
    <?php endif;?>
    <?php wp_reset_query(); ?>

    There’s also a <?php the_permalink();?> wrapped around the title above but every time I enter it in the box, it converts it to a link so I’ve taken it out for now.

    Also, the “post_parent” in the query is the private forum.


    acornale
    Participant

    @acornale

    Problem solved! Thought I’d write the solution here in case anyone has the same problem.

    In order to get the feeds coming through on the home page, the forum had to be public. However, I wanted the forum post content to be private and I wanted the user to be prompted to log in.

    The solution was simple…

    I created a custom content-single-topic.php template and added the following logic:

    <?php if ( is_user_logged_in() ) { ?>

    // display all the post content here

    <?php } else { ?>

    <p class=”message register”>This forum is accessible to approved users only</p>
    <p class=”message”>Please log in to continue.<br></p>
    <?php wp_login_form(); ?>

    <? } ?>

    —-

    I dont know what I didn’t think of this earlier. The logic is simple… all forums are public by default but you must be logged in to view the forum topic content. If you’re not logged in, it asks you to log in and then redirects you to the right topic page.


    Robin W
    Moderator

    @robin-w

    great – glad you’re fixed !!

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.