WordPress.org

Support

Support » How-To and Troubleshooting » Can someone help me hide the sidebar based on login status?

Can someone help me hide the sidebar based on login status?

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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();
    }
    ?>

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

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

    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.

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Can someone help me hide the sidebar based on login status?’ is closed to new replies.
Skip to toolbar