WordPress.org

Ready to get started?Download WordPress

Forums

Conditional Statement in Prologue (4 posts)

  1. jacob00
    Member
    Posted 5 years ago #

    Hi

    Trying to have a conditional statement in Prologue theme that shows a different form if a user is not a member (or not logged in). This is my attempt but it's not working:

    <?php
    	if( current_user_can( 'publish_posts' ) ) require_once dirname( __FILE__ ) . '/post-form.php';
    
    	} else {
    
    	if( current_user_can( 'level_0' ) ) require_once dirname( __FILE__ ) . '/banner-form.php';
    
    ?>
  2. popper
    Member
    Posted 5 years ago #

    Try with this:

    <?php if ( is_user_logged_in() )://check if user is logged in ?>
    <?php echo('hello, user');  // if he is, do stuff ?>
    <?php else: echo('hello, non user'); // if he isn't do other stuff?>
    <?php endif;?>

    It works for me in local. Of course, it just echoes "Hello, user/non-user", but it'll work with your forms too.

    Hope that helps

  3. jacob00
    Member
    Posted 5 years ago #

    Any ideas on how to make it work with my code from P2 as seen above?

  4. popper
    Member
    Posted 5 years ago #

    It's the same, you just replace the echoes with the file you want to include:

    <?php if ( is_user_logged_in() )://check if user is logged in ?>
    				<?php include_once(dirname(__FILE__) . '/searchform.php');  // if he is, do stuff ?>
    				<?php else: include_once(dirname(__FILE__) . '/comments.php'); // if he isn't do other stuff?>
    				<?php endif;?>

    Above The logged in user would see the search form, and the user not logged in would see the comment form. Just replace searchform.php and comments.php with whatever you want to include in your case.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.