WordPress.org

Ready to get started?Download WordPress

Forums

Can someone help me hide the sidebar based on login status? (6 posts)

  1. vistasucks
    Member
    Posted 7 years ago #

    Someone else in the forums here said:

    <?
    get_currentuserinfo() ;
    global $user_level;
    if ($user_level > 0) {
    echo "yes";
    } else {
    no
    }
    ?>

    Well, everything you want people to NOT be able to see will go in where yes is. Just remember that whatever code you put in there, you replace all the " with '

    I have tried placing that code in my theme's index.php file in between

    <?php get_sidebar(); ?>
    and
    <?php get_footer(); ?>

    but it doesn't work. I get an error message regarding the line below the "no", with the lone "}" on it.

    Can someone please help me? Bear in mind you're talking to someone who knows .html but not a dang thing about coding .php

  2. bluegator
    Member
    Posted 7 years ago #

    It's probably just a syntax error. If you want to completely hide the sidebar, replace <?php get_sidebar(); ?> in your index.php file with the following:

    <?
    get_currentuserinfo() ;
    global $user_level;
    if ($user_level > 0) {
         get_siderbar();
    }
    ?>
  3. vistasucks
    Member
    Posted 7 years ago #

    will that show the sidebar to a logged in user though? I only want to hide from those that aren't logged in.

  4. bluegator
    Member
    Posted 7 years ago #

    Yes, it will show the sidebar for anyone who has a userlevel > 0, which should be any logged in user.

  5. vistasucks
    Member
    Posted 7 years ago #

    Ok I did that and at first it appeared to work. I logged in as a regular user to see if the sidebar became visible but I got a badly distorted site and the error:

    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY post_date
    DESC LIMIT 0, 10' at line 1]
    SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND (post_type = 'post' AND (post_status = 'publish' OR post_author = 9 AND post_status = 'private')) AND ID NOT IN () ORDER BY post_date DESC LIMIT 0, 10

    Although if I click a page link the site looks normal again. Clicking a month in archives returns the page to the distorted version again.

    I logged out and then logged back in as admin. when I viewed the site it looked normal but with no sidebar. Clicking on a page link makes the sidebar visible again after the new page loads. Click home takes the sidebar away again.

  6. Bodhipaksa
    Member
    Posted 7 years ago #

    Just wanted to check and see if you'd spotted and corrected the "siderbar" typo before trying out that code. If you'd just copied and pasted the code above I'd imagine you'd get funny things happening with the sidebar.

Topic Closed

This topic has been closed to new replies.

About this Topic