• Resolved donbilet

    (@donbilet)


    Hi,

    I tried to make a custom page for my homepage base on logged in and logged out user. I’d like to have full page without sidebar when user logged out and with sidebars when user logged in.

    I use this code but not working, the sidebar space still there:

    <?php
    /*
    Template Name: Home Page
    */
    ?>
    <?php get_header(); ?>
    <?php if ( is_user_logged_in() ) { ?>
    <section class="content">
    	<?php get_template_part('inc/page-title'); ?>
    	<div class="pad group">
    		<?php while ( have_posts() ): the_post(); ?>
    			<article <?php post_class('group'); ?>>
    				<?php get_template_part('inc/page-image'); ?>
    				<div class="entry themeform">
    					<?php the_content(); ?>
    					<div class="clear"></div>
    				</div><!--/.entry-->
    			</article>
    			<?php if ( ot_get_option('page-comments') == 'on' ) { comments_template('/comments.php',true); } ?>
    		<?php endwhile; ?>
    	</div><!--/.pad-->
    </section><!--/.content-->
    <?php get_sidebar(); ?>
    <?php } else { ?>
    <section class="content">
    	<?php get_template_part('inc/page-title'); ?>
    	<div class="pad group">
    		<?php while ( have_posts() ): the_post(); ?>
    			<article <?php post_class('group'); ?>>
    				<?php get_template_part('inc/page-image'); ?>
    				<div class="entry themeform">
    					<?php the_content(); ?>
    					<div class="clear"></div>
    				</div><!--/.entry-->
    			</article>
    			<?php if ( ot_get_option('page-comments') == 'on' ) { comments_template('/comments.php',true); } ?>
    		<?php endwhile; ?>
    	</div><!--/.pad-->
    </section><!--/.content-->
    <?php } ?>
    <?php get_footer(); ?>

    Can someone help? thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • bdbrown

    (@bdbrown)

    Hi donbilet. So the page template works, and there is no sidebar when the user is logged out, but the area for the sidebars is still there; meaning the content area hasn’t expanded in width? If that’s the case you should be able to adjust the content area with some CSS based on the “logged-in” class in the body tag.

    Thread Starter donbilet

    (@donbilet)

    Hi bdbrown. Yes, the content area width wasn’t expanded. Would you please share the css?

    Thanks

    bdbrown

    (@bdbrown)

    Can you post a link to your site? Thanks.

    Thread Starter donbilet

    (@donbilet)

    Ah sorry, I am still testing it on my local server.

    bdbrown

    (@bdbrown)

    Give this CSS a try in a child theme or using a plugin like Simple CSS:

    .home:not(.logged-in) .main-inner {
        background: none;
        padding-right: 0;
    }

    Also, it appears that the only difference in the page layout for a logged in user is the sidebar. If so, you can simplify your code by using one block of code for the main layout and then placing your “if” condition at the point that the sidebar loads:

    <?php
    /*
    Template Name: Home Page
    */
    ?>
    <?php get_header(); ?>
    <section class="content">
    	<?php get_template_part('inc/page-title'); ?>
    	<div class="pad group">
    		<?php while ( have_posts() ): the_post(); ?>
    			<article <?php post_class('group'); ?>>
    				<?php get_template_part('inc/page-image'); ?>
    				<div class="entry themeform">
    					<?php the_content(); ?>
    					<div class="clear"></div>
    				</div><!--/.entry-->
    			</article>
    			<?php if ( ot_get_option('page-comments') == 'on' ) { comments_template('/comments.php',true); } ?>
    		<?php endwhile; ?>
    	</div><!--/.pad-->
    </section><!--/.content-->
    <?php if ( is_user_logged_in() ) {
    	get_sidebar();
    } ?>
    <?php get_footer(); ?>
    Thread Starter donbilet

    (@donbilet)

    Thanks bdbrown, will try this code today

    Thread Starter donbilet

    (@donbilet)

    It works perfectly.

    I use this css to remove both sidebars and have same background color with content background color


    .home:not(.logged-in) .main-inner {
    background: #ffffff;
    padding-left: 0;
    padding-right: 0;
    }

    Thanks again!

    bdbrown

    (@bdbrown)

    You’re welcome. Glad it worked out. If you don’t need any further assistance here please mark the topic as Resolved. Thanks.

    Thread Starter donbilet

    (@donbilet)

    Ok. thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom Page for Logged In User’ is closed to new replies.