Skip to:
Content
Pages
Categories
Search
Top
Bottom

Different home pages for logged-in/logged-out users

  • @hotdvl666

    Member

    Hi,

    I have a BuddyPress-enabled WordPress site at http://i.7thzone.net/. I am running on WordPress MU 2.9.1 and the latest version of BuddyPress.

    I was wondering how I can display a different page for logged out users (to tell them what the site is about, etc.), and the activity stream for logged-in users when they access the home page (index.php).

    I don’t know PHP very well, so if I have to edit my theme, please guide me on how to do it. I’m using the Unplugged theme.

    Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • @marco72

    Participant

    Here’s what I’ve done:

    1. create a new page template (don’t call it home.php!) with all the html/php you need for your front page. Upload it on your theme folder via ftp.

    2. create a new page in the dashboard using your template. Set it as home page on the Reading section.

    3. I used the Login With Ajax plugin to redirect logged in user to the activity page. But any method of redirection could work.

    @philipwalter

    Participant

    Depending on how comfortable you are with code, you can use conditional tags, if statements, and includes to do just about anything you want. I have several custom headers in my theme that load up depending on what kind of page is being displayed. You could have different template files (and thus, entirely different looking pages) load based on whether or not a user is logged in, and also what level of user is logged in.

    For example, you could place the following in your header.php file:

    <?php if (is_user_logged_in() && current_user_can('level_2') && !current_user_can('level_8')) {
    include (TEMPLATEPATH . 'path to custom header file 1');
    } elseif (is_user_logged_in() && current_user_can('level_8')) {
    include (TEMPLATEPATH . 'path to custom header file 2');
    } elseif (is_user_logged_in()) {
    include (TEMPLATEPATH . 'path to custom header file 3');
    } elseif (!is_user_logged_in()) {
    include (TEMPLATEPATH . 'path to custom header file 4');
    } ?>

    This basically says, if the person looking at the site is a logged-in user AND they are an author AND they are not admin, load template file 1. If the person is logged in AND is admin, load template file 2. If the person is any other type of logged in user, load template file 3. If the person is not logged in, load template file 4.

    I have been doing this sort of thing on my site with great results, but again, it does require a bit of tinkering with the template files and a certain comfort level with code.

    @marco72

    Participant

    Nice trick philipwalter, it takes it one step further.

    @philipwalter

    Participant

    yeah … you can do a lot with that sort of thing if you just take a bit of time to learn it. This little tutorial really opened my mind to the possibilities – Frontend Admin Menu in WordPress – That guy’s website is great. Lots to learn.

    @philipwalter

    Participant

    For hotdvl666 – You could start by, say, creating a copy of the index.php file from the bp-default theme folder, and placing that into your Unplugged theme folder. This will over-ride the original.

    You could then add the following to the top of the index.php copy you placed in your theme’s folder:

    <?php if (!is_user_logged_in()) { ?>

    Place HTML you want non-logged-in users to see here.

    <?php } else { ?>

    Then on the last line of your copy, you just have to close the if … else statement:

    <?php } ?>

    That seems to me like a good starting place. It basically just says, if the user is not logged in, I’m gonna display the HTML you enter, otherwise, I’m gonna do the normal theme thing to do. This is minimally invasive and should work fine. If it breaks something, just remove the index.php copy from your theme’s folder.

    @philipwalter

    Participant

    One more thing to remember if you do this – the HTML you place for non-logged-in users needs to represent a full HTML page with all the tags, like the HTML, HEAD, BODY tags, etc, because non-logged-in users will only see what’s above the “else”.

    @hotdvl666

    Member

    Thank you! You guys have been of great help.

    @Philip: I have done what you’ve said, exactly, but it seems like I can only make the code work if I edit header.php.

    Here’s the code I used (I adapted the method you used in your first reply and second reply):

    <?php if (is_user_logged_in()) { ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

    <head profile="http://gmpg.org/xfn/11">

    <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

    <title><?php bp_page_title() ?></title>

    <?php do_action( 'bp_head' ) ?>

    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />

    <?php if ( function_exists( 'bp_sitewide_activity_feed_link' ) ) : ?>

    <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> | <?php _e('Site Wide Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_sitewide_activity_feed_link() ?>" />

    <?php endif; ?>

    <?php if ( function_exists( 'bp_member_activity_feed_link' ) && bp_is_member() ) : ?>

    <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> | <?php bp_displayed_user_fullname() ?> | <?php _e( 'Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_member_activity_feed_link() ?>" />

    <?php endif; ?>

    <?php if ( function_exists( 'bp_group_activity_feed_link' ) && bp_is_group() ) : ?>

    <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> | <?php bp_current_group_name() ?> | <?php _e( 'Group Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_group_activity_feed_link() ?>" />

    <?php endif; ?>

    <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> <?php _e( 'Blog Posts RSS Feed', 'buddypress' ) ?>" href="<?php bloginfo('rss2_url'); ?>" />

    <link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> <?php _e( 'Blog Posts Atom Feed', 'buddypress' ) ?>" href="<?php bloginfo('atom_url'); ?>" />

    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />

    <?php wp_head(); ?>

    </head>

    <body <?php body_class() ?> id="bp-default">

    <?php do_action( 'bp_before_header' ) ?>

    <div id="header">

    <h1 id="logo">" title="<?php _e( 'Home', 'buddypress' ) ?>"><?php bp_site_name() ?></h1>

    <ul id="nav">

    <li<?php if ( bp_is_front_page() ) : ?> class="selected"<?php endif; ?>>

    " title="<?php _e( 'Home', 'buddypress' ) ?>"><?php _e( 'Home', 'buddypress' ) ?>

    <?php if ( 'activity' != bp_dtheme_page_on_front() && bp_is_active( 'activity' ) ) : ?>

    <li<?php if ( bp_is_page( BP_ACTIVITY_SLUG ) ) : ?> class="selected"<?php endif; ?>>

    /<?php echo BP_ACTIVITY_SLUG ?>/" title="<?php _e( 'Activity', 'buddypress' ) ?>"><?php _e( 'Activity', 'buddypress' ) ?>

    <?php endif; ?>

    <li<?php if ( bp_is_page( BP_MEMBERS_SLUG ) || bp_is_member() ) : ?> class="selected"<?php endif; ?>>

    /<?php echo BP_MEMBERS_SLUG ?>/" title="<?php _e( 'Members', 'buddypress' ) ?>"><?php _e( 'Members', 'buddypress' ) ?>

    <?php if ( bp_is_active( 'groups' ) ) : ?>

    <li<?php if ( bp_is_page( BP_GROUPS_SLUG ) || bp_is_group() ) : ?> class="selected"<?php endif; ?>>

    /<?php echo BP_GROUPS_SLUG ?>/" title="<?php _e( 'Groups', 'buddypress' ) ?>"><?php _e( 'Groups', 'buddypress' ) ?>

    <?php if ( bp_is_active( 'forums' ) && bp_is_active( 'groups' ) && ( function_exists( 'bp_forums_is_installed_correctly' ) && !(int) bp_get_option( 'bp-disable-forum-directory' ) ) && bp_forums_is_installed_correctly() ) : ?>

    <li<?php if ( bp_is_page( BP_FORUMS_SLUG ) ) : ?> class="selected"<?php endif; ?>>

    /<?php echo BP_FORUMS_SLUG ?>/" title="<?php _e( 'Forums', 'buddypress' ) ?>"><?php _e( 'Forums', 'buddypress' ) ?>

    <?php endif; ?>

    <?php endif; ?>

    <?php if ( bp_is_active( 'blogs' ) && bp_core_is_multisite() ) : ?>

    <li<?php if ( bp_is_page( BP_BLOGS_SLUG ) ) : ?> class="selected"<?php endif; ?>>

    /<?php echo BP_BLOGS_SLUG ?>/" title="<?php _e( 'Blogs', 'buddypress' ) ?>"><?php _e( 'Blogs', 'buddypress' ) ?>

    <?php endif; ?>

    <!--<?php wp_list_pages( 'title_li=&depth=1&exclude=' . bp_dtheme_page_on_front() ); ?>-->

  • Back to The 7th Zone »
  • <?php do_action( 'bp_nav_items' ); ?>

    <!-- #nav -->

    <div id="search-bar">

    <div class="padder">

    <form action="<?php echo bp_search_form_action() ?>" method="post" id="search-form">

    <input type="text" id="search-terms" name="search-terms" value="" />

    <?php echo bp_search_form_type_select() ?>

    <input type="submit" name="search-submit" id="search-submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />

    <?php wp_nonce_field( 'bp_search_form' ) ?>

    </form><!-- #search-form -->

    <?php do_action( 'bp_search_login_bar' ) ?>

    </div><!-- .padder -->

    </div><!-- #search-bar -->

    <?php do_action( 'bp_header' ) ?>

    </div><!-- #header -->

    <?php do_action( 'bp_after_header' ) ?>

    <?php do_action( 'bp_before_container' ) ?>

    <center>Network: The 7th Zone :: Home | Grand Theft Auto HQ | Hot Devil 666's HQ | Silent Fiona's HQ

    </center><p>

    <div id="container">

    <?php } else { ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

    <head profile="http://gmpg.org/xfn/11">

    <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

    <title><?php bp_page_title() ?></title>

    <?php do_action( 'bp_head' ) ?>

    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />

    <?php if ( function_exists( 'bp_sitewide_activity_feed_link' ) ) : ?>

    <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> | <?php _e('Site Wide Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_sitewide_activity_feed_link() ?>" />

    <?php endif; ?>

    <?php if ( function_exists( 'bp_member_activity_feed_link' ) && bp_is_member() ) : ?>

    <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> | <?php bp_displayed_user_fullname() ?> | <?php _e( 'Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_member_activity_feed_link() ?>" />

    <?php endif; ?>

    <?php if ( function_exists( 'bp_group_activity_feed_link' ) && bp_is_group() ) : ?>

    <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> | <?php bp_current_group_name() ?> | <?php _e( 'Group Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_group_activity_feed_link() ?>" />

    <?php endif; ?>

    <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> <?php _e( 'Blog Posts RSS Feed', 'buddypress' ) ?>" href="<?php bloginfo('rss2_url'); ?>" />

    <link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> <?php _e( 'Blog Posts Atom Feed', 'buddypress' ) ?>" href="<?php bloginfo('atom_url'); ?>" />

    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />

    <?php wp_head(); ?>

    </head>

    <body <?php body_class() ?> id="bp-default">

    <?php do_action( 'bp_before_header' ) ?>

    <div id="header">

    <h1 id="logo">" title="<?php _e( 'Home', 'buddypress' ) ?>"><?php bp_site_name() ?></h1>

    <ul id="nav">

    <li<?php if ( bp_is_front_page() ) : ?> class="selected"<?php endif; ?>>

    " title="<?php _e( 'Home', 'buddypress' ) ?>"><?php _e( 'Home', 'buddypress' ) ?>

    <?php if ( 'activity' != bp_dtheme_page_on_front() && bp_is_active( 'activity' ) ) : ?>

    <li<?php if ( bp_is_page( BP_ACTIVITY_SLUG ) ) : ?> class="selected"<?php endif; ?>>

    /<?php echo BP_ACTIVITY_SLUG ?>/" title="<?php _e( 'Activity', 'buddypress' ) ?>"><?php _e( 'Activity', 'buddypress' ) ?>

    <?php endif; ?>

    <li<?php if ( bp_is_page( BP_MEMBERS_SLUG ) || bp_is_member() ) : ?> class="selected"<?php endif; ?>>

    /<?php echo BP_MEMBERS_SLUG ?>/" title="<?php _e( 'Members', 'buddypress' ) ?>"><?php _e( 'Members', 'buddypress' ) ?>

    <?php if ( bp_is_active( 'groups' ) ) : ?>

    <li<?php if ( bp_is_page( BP_GROUPS_SLUG ) || bp_is_group() ) : ?> class="selected"<?php endif; ?>>

    /<?php echo BP_GROUPS_SLUG ?>/" title="<?php _e( 'Groups', 'buddypress' ) ?>"><?php _e( 'Groups', 'buddypress' ) ?>

    <?php if ( bp_is_active( 'forums' ) && bp_is_active( 'groups' ) && ( function_exists( 'bp_forums_is_installed_correctly' ) && !(int) bp_get_option( 'bp-disable-forum-directory' ) ) && bp_forums_is_installed_correctly() ) : ?>

    <li<?php if ( bp_is_page( BP_FORUMS_SLUG ) ) : ?> class="selected"<?php endif; ?>>

    /<?php echo BP_FORUMS_SLUG ?>/" title="<?php _e( 'Forums', 'buddypress' ) ?>"><?php _e( 'Forums', 'buddypress' ) ?>

    <?php endif; ?>

    <?php endif; ?>

    <?php if ( bp_is_active( 'blogs' ) && bp_core_is_multisite() ) : ?>

    <li<?php if ( bp_is_page( BP_BLOGS_SLUG ) ) : ?> class="selected"<?php endif; ?>>

    /<?php echo BP_BLOGS_SLUG ?>/" title="<?php _e( 'Blogs', 'buddypress' ) ?>"><?php _e( 'Blogs', 'buddypress' ) ?>

    <?php endif; ?>

    <!--<?php wp_list_pages( 'title_li=&depth=1&exclude=' . bp_dtheme_page_on_front() ); ?>-->

  • Back to The 7th Zone »
  • <?php do_action( 'bp_nav_items' ); ?>

    <!-- #nav -->

    <div id="search-bar">

    <div class="padder">

    <form action="<?php echo bp_search_form_action() ?>" method="post" id="search-form">

    <input type="text" id="search-terms" name="search-terms" value="" />

    <?php echo bp_search_form_type_select() ?>

    <input type="submit" name="search-submit" id="search-submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />

    <?php wp_nonce_field( 'bp_search_form' ) ?>

    </form><!-- #search-form -->

    <?php do_action( 'bp_search_login_bar' ) ?>

    </div><!-- .padder -->

    </div><!-- #search-bar -->

    <?php do_action( 'bp_header' ) ?>

    </div><!-- #header -->

    <center>Network: The 7th Zone :: Home | Grand Theft Auto HQ | Hot Devil 666's HQ | Silent Fiona's HQ

    </center><p>

    <div id="container">

    <div id="content">

    <div class="padder">

    <div class="page" id="blog-page">

    <h2 class="pagetitle">Welcome to the party!</h2>

    <div class="post" id="post-68">

    <div class="entry">

    <p>Social networking at The 7th Zone is like partying! …and more! Joining in the fun at The 7th Zone is nothing like you’ve experienced on Facebook, MySpace, or any major social networking sites! Akin to a crazed, wild college party, The 7th Zone is where fun-loving youths, as well as video game enthusiasts and tech geeks can hang out!</p>

    <p>Staying up late to snag that cool-sounding medal in Halo 3, or piloting that Annihilator helicopter in Grand Theft Auto IV’s Free Mode? Fancy that VAIO Z laptop, or are you going nuts over a MacBook Pro refresh? Think the iPad is gimmicky and expected so much more? Prefer metal over the Jonas brothers, and classic Hip Hop over auto-tuned sh*t? This site is for you, the cool kid!</p>

    <p>Right here at The 7th Zone Community, you can create your own free blogs. With 500 MB of upload space, a feature-packed plugins set, and 117 beautiful themes, just how much more can you get for $0? More details here.</p>

    <p>Join us now. Registration is as easy as a few clicks! Hit the jump below to register yourself!</p>

    <div align="right">

    <h2>Register Me! »</h2>

    </div>

    <p>Edit this entry.</p>

    </div>

    </div>

    </div><!-- .page -->

    <?php do_action( 'bp_after_blog_page' ) ?>

    </div><!-- .padder -->

    </div><!-- #content -->

    <?php locate_template( array( 'sidebar.php' ), true ) ?>

    <?php get_footer(); ?>

    <?php } ?>

    For some reason, my site still displays whatever page I’m on for non-logged in users, and it does so after the footer for the else case. I have no clue what I did wrong. I have no experience in PHP code, but it looks fine to me. Is there an error I made somewhere?

    It also seems that if I set the activity stream to be the home page, the custom home page title that I’ve set in the All-in-One SEO pack doesn’t seem to take effect too. If I want to show logged in users the activity stream as the home page, with my custom home page title, how do I go about doing that?

    Thanks.

@hotdvl666

Member

Hi guys,

I’m happy to say I’ve figured out how to include the activity stream on my site’s index. However, my code for header.php is still not working as intended. The page still shows below the footer.

@hotdvl666

Member

Alright, it seems that I had it figured out. I moved the code to index.php and it worked the way I wanted.

Thanks for all the help people!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Different home pages for logged-in/logged-out users’ is closed to new replies.
Skip to toolbar