Forums

two home pages (5 posts)

  1. hamedhemmati1
    Member
    Posted 1 month ago #

    Is it possible to have two home pages? I would like to have a basic home page for those who come to visit my website and another one for users that are logged in. I want to modify the second so it would be more relevant for the user that is logged on to the site and not just everybody. something similar to what facebook does.

  2. mfields
    Member
    Posted 1 month ago #

    Sure, this should be rather easy actually. In whichever file controls your homepage ( could be index.php, home.php, page.php or a custom template ). you will want to incorporate the following logic structure:

    if( is_user_logged_in() ) {
      /* Do custom logged in stuff */
    }
    else {
      /* Do NOT logged in stuff */
    }

    Hope this helps,
    -Mike

  3. hamedhemmati1
    Member
    Posted 1 month ago #

    that's easy enough. I just have to figure out how to mix and match PHP with HTML. there is a sidebar that I would like to add for logged in users but it is already a mix of PHP and HTML.

    <div id="second-section" class="widget-section">
    			<?php if ( !function_exists('dynamic_sidebar')
    			        || !dynamic_sidebar('second-section') ) : ?>
    
    			<div class="widget-error">
    				<?php _e( 'Please log in and add widgets to this section.', 'buddypress' ) ?> <a href="<?php echo get_option('siteurl') ?>/wp-admin/widgets.php?s=&show=&sidebar=second-section"><?php _e( 'Add Widgets', 'buddypress' ) ?></a>
    			</div>
    
    			<?php endif; ?>
    		</div>

    also one other question I have is there any way to use roles in the if statement? for instance instead of is_user_logged_in something like is_user_administrator

  4. mfields
    Member
    Posted 1 month ago #

    Something like this should work for the sidebar:

    <?php if( is_user_logged_in() ) : ?>
    <div id="second-section" class="widget-section">
    	<?php if ( !function_exists('dynamic_sidebar')
    			|| !dynamic_sidebar('second-section') ) : ?>
    
    	<div class="widget-error">
    		<?php _e( 'Please log in and add widgets to this section.', 'buddypress' ) ?> <a href="<?php echo get_option('siteurl') ?>/wp-admin/widgets.php?s=&show=&sidebar=second-section"><?php _e( 'Add Widgets', 'buddypress' ) ?></a>
    	</div>
    
    	<?php endif; ?>
    </div>
    <?php else: ?>
    	<div id="other_sidebar">
    
    	</div>
    <?php endif; ?>

    also one other question I have is there any way to use roles in the if statement? for instance instead of is_user_logged_in something like is_user_administrator

    This is pretty easy for admin. You can use: is_admin() in a conditional structure. I don;t think that there are other functions like this though. You can fine tune using current_user_can(). This function takes one argument which is the name of the capability you are testing for. something like:

    if( current_user_can( 'edit_posts' ) ){
       /* DO STUFF */
    }

    or

    if( current_user_can( 'level_6' ) ){
       /* DO STUFF */
    }

    more info on roles here:
    http://codex.wordpress.org/Roles_and_Capabilities

  5. hamedhemmati1
    Member
    Posted 1 month ago #

    thanks for all your help. this looks really easy. I have just moved to using wordpress. I used to work community server based on ASP and it used to be a pain creating conditions for displaying different things but it looks much simpler with wordpress. That solves most of my customizing questions. I really appreciate it. :)

Reply

You must log in to post.

About this Topic

Tags

No tags yet.