Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Sidebars & Widgets (http://forum.bytesforall.com/forumdisplay.php?f=14)
-   -   [SOLVED] Hide the right sidebar for subscribers (http://forum.bytesforall.com/showthread.php?t=14019)

dcclxi May 3, 2011 08:39 PM

[SOLVED] Hide the right sidebar for subscribers
 
Hello,

First thank so much for this theme, I have spent months looking for something flexible enough but still easy to use and Atahualpa is simply perfect!

My question is about the sidebars. I would like to know how I can hide the right sidebar if the user is "only" a subscriber.

The website I have set up is only accessible to registered users. They are divided into two classes: those who are subscribers and those are not. The subscribers have a restricted view of the content (they only see posts from one category only). That restriction unfortunately does not spread to all widgets, so I would like to hide the right sidebar (to hide its widgets).

I took a look at the theme code via the WP Editor, but I can't work out where the Atahualpa code creates the HTML/CSS for the sidebars. I thought that perhaps I could add a
if (!current_user_can('delete_posts') ) { ... } // user is a subscriber
somewhere, but I don't find the right place.

I would prefer not to have to do any code change, but so far it is the only solution that is likely to work.

I would really appreciate any help on this...
dcclxi

lmilesw May 3, 2011 10:30 PM

I did a little digging and the following will hide the right sidebar if a user is logged in. Not sure how you would limit to subscriber etc. but maybe it's a start. I put this in CSS Inserts.
HTML Code:

<?php if ( is_user_logged_in() ) { ?>
.colthree, td#right {
    display: none;
}
<?php } ?>


dcclxi May 4, 2011 08:52 PM

Thank you so much for such a quick answer!

I tried it, it half works: the sidebars (I went for hiding both the left and right one) are hidden, but the central area then shrinks to the width of the (disappeared) left sidebar (or at least looks like it). I can't work out why.

I kept playing a bit with the code and eventually got to this (in css.php) :

HTML Code:

/*-------------------- LAYOUT to keep it all together -----*/
       
table#layout {
        font-size: 100%;
        width: 100%;
        table-layout: fixed;
        }

.colone {width: <?php echo $bfa_ata['left_sidebar_width']; ?>px;}
.colone-inner {width: <?php echo $bfa_ata['left_sidebar2_width']; ?>px;}
.coltwo { width: 100% }
.colthree-inner {width: <?php echo $bfa_ata['right_sidebar2_width']; ?>px;}
.colthree {width: <?php echo $bfa_ata['right_sidebar_width']; ?>px;}

/* code change, start */
<?php if ( !current_user_can('delete_posts') ) { ?>
        .colone, .colthree {
                ...
        }
<?php } ?>
/* code change, end */

The php line ensures this code change only applies to subscribers (see table at http://codex.wordpress.org/Roles_and_Capabilities).
The "..." bit can be:
HTML Code:

display: none;
which leads to a weird behaviour. Or:
HTML Code:

width: 0px;
which does shrink both sidebars to 0px, allows the central area to spread wider, but the sidebar content logically overflows (hence not hidden).

If you have any idea... There must be a place in all the php files of the theme where the user's choice regarding whether to display or not a sidebar (left, left inner, right inner, right) is retrieved. Perhaps that is where the code change should be done?

lmilesw May 4, 2011 08:57 PM

I avoid editing theme files except for bug fixes and the like as they won't survive an upgrade and I don't want to have to document all the changes I made to a particular installation so I can "redo" the hacks. That's why I stick primarily with code in the theme options and is why I like this theme so much in that you can do most anything you want within the theme options if you think through it.

dcclxi May 4, 2011 09:27 PM

I don't like editing the theme either, I wish I could find another way to hide these sidebars. I'll keep searching :-).

lmilesw May 4, 2011 09:39 PM

Was the code you put in CSS Inserts something like the following without any of the other code you tried?
HTML Code:

<?php if ( is_user_logged_in() ) { ?>
.colthree, td#right, .colone, td#left {
    display: none;
}
<?php } ?>

I just put that in my test site and when logged in see no sidebars. It would seem all you have to do if figure out how to determine the code for what type of use is logged in.

dcclxi May 5, 2011 09:17 AM

I tried this but there was an issue so perhaps I didn't put it in the right place. Where did you add this CSS code?

lmilesw May 5, 2011 11:07 AM

In ATO>Add HTML/CSS Inserts>CSS Inserts

dcclxi May 5, 2011 08:55 PM

It works!! Brilliant!!!
I got the code to work only for subscribers by changing the php if condition:

HTML Code:

<?php if ( !current_user_can('delete_posts') ) { ?>
.colthree, td#right, .colone, td#left {
    display: none;
}
<?php } ?>

I am really stupid for not finding the CSS insert place in the theme interface (!). My excuse is that I am sleep depraved because feeding at day and night a 2-month old little boy :-).

Thanks a lot for your help!


All times are GMT -6. The time now is 09:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.