Forums

Conditional Statement for Post Form (7 posts)

  1. jacob00
    Member
    Posted 7 months 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
    moderator
    Posted 7 months ago #

  3. scotm
    Member
    Posted 7 months 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
    Administrator
    Posted 7 months 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 7 months 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 7 months 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
    Administrator
    Posted 7 months 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.

Reply

You must log in to post.

About this Topic

Tags