WordPress.org

Ready to get started?Download WordPress

Forums

Conditional Statement for Post Form (7 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. MichaelH
    Member
    Posted 5 years ago #

  3. Scotm
    Member
    Posted 5 years ago #

    I've seen several examples but can't make it work with my specific instance. I'm pretty sure the code I've shown worked with the original Prologue, but perhaps someone can see an obvious problem with the 'else' statement.

    Cheers

  4. noel
    Member
    Posted 5 years ago #

    You probably want something like this:

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

    noel

    Thanks for the help, but I'm afraid it doesn't work. I get the same sort of error:

    "Parse error: syntax error, unexpected '}' in ////themes/P2/index.php on line 17"

    Any ideas?

  6. loyalpk
    Member
    Posted 5 years ago #

    do you want to show a banner to regular visitors i am using wp greet box instead... like i did at http://trendblog.org

  7. noel
    Member
    Posted 5 years ago #

    scotm: I posted bad code. This is what you want:

    <?php
    	if( current_user_can( 'publish_posts' ) ) {
            require_once dirname( __FILE__ ) . '/post-form.php';
    	} elseif( current_user_can( 'level_0' ) ) {
            require_once dirname( __FILE__ ) . '/banner-form.php';
            }
    ?>

    Sorry for the mixup.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags