Widgetizing Buddy Press Scholar Theme sidebar-home.php Hard-coded Widgets

With the related topics below, I now have

bp-scholar-child/functions.php
<?php
register_sidebars( 1,
array(
'name' => 'Sidebar-2-Home',
'before_widget' => '',
'after_widget' => '<div class="clear"></div></div>',
'before_title' => '<div class="h4-background"><h4>',
'after_title' => '</h4></div><div id="%1$s" class="widget-wrapper">'
)
);
?>

and

bp-scholar-child/sidebars/sidebar-home.php
<?php include (TEMPLATEPATH . '/options.php'); ?>
<div id="sidebar">
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('home-sidebar') ) : ?>
<div class="widget-error">
<?php _e( 'Please log in and add widgets to this column.', 'buddypress' ) ?> /wp-admin/widgets.php?s=&show=&sidebar=home-sidebar"><?php _e( 'Add Widgets', 'buddypress' ) ?>
</div>
<?php endif; ?>

<?php if( $bp_existed == 'true' ) { //check if bp existed ?>

<?php } ?>

<?php
$show_followus = get_option('ne_buddyscholar_followuson');
$url_twitter = get_option('ne_buddyscholar_twitter_url');
$url_flickr = get_option('ne_buddyscholar_flickr_url');
$url_facebook = get_option('ne_buddyscholar_facebook_url');
$url_youtube = get_option('ne_buddyscholar_youtube_url');
?>

<?php
if ($show_followus == "yes"){
?>

<div class="h4-background"><h4> <?php _e( 'Follow us', 'bp_scholar' ) ?></h4></div>
<div class="widget-wrapper">
<?php if ($url_twitter != ""){
?>
<div id="url-twitter">
" title="<?php _e( 'Twitter', 'bp_scholar' ) ?>"><?php _e( 'Follow us on Twitter', 'bp_scholar' ) ?>
</div>
<?php } ?>
<?php if ($url_flickr != ""){
?>
<div id="url-flickr">
" title="<?php _e( 'Flickr', 'bp_scholar' ) ?>"><?php _e( 'Follow us on Flickr', 'bp_scholar' ) ?>
</div>
<?php } ?>
<?php if ($url_facebook != ""){
?>
<div id="url-facebook">
" title="<?php _e( 'Facebook', 'bp_scholar' ) ?>"><?php _e( 'Follow us on Facebook', 'bp_scholar' ) ?>
</div>
<?php } ?>
<?php if ($url_youtube != ""){
?>
<div id="url-youtube">
" title="<?php _e( 'YouTube', 'bp_scholar' ) ?>"><?php _e( 'Follow us on YouTube', 'bp_scholar' ) ?>
</div>
<?php } ?>
</div>

<?php
}
?>

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar-2-Home') ) : ?>
<?php endif; ?>
</div>

Right now, my Sidebar-2-Home is behaving in a funny way, in that if I put a widget in there, it closes immediately and won't let me add any text (if it's a text widget).

Here is a quick screencast of the behavior http://screencast.com/t/BpxIejceL78I

My goal is to have the widgets in the following oder
Subscribe By Email
Follow Us
Then Whatever Additional Widgets I Choose

With the hard coded widgets, that's next to impossible. So, I also tried installing Executable PHP widget and pasting the following into a text widget:


<?php
$show_followus = get_option('ne_buddyscholar_followuson');
$url_twitter = get_option('ne_buddyscholar_twitter_url');
$url_flickr = get_option('ne_buddyscholar_flickr_url');
$url_facebook = get_option('ne_buddyscholar_facebook_url');
$url_youtube = get_option('ne_buddyscholar_youtube_url');
?>

<?php
if ($show_followus == "yes"){
?>

<?php if ($url_twitter != ""){
?>
<div id="url-twitter">
" title="<?php _e( 'Twitter', 'bp_scholar' ) ?>"><?php _e( 'Follow us on Twitter', 'bp_scholar' ) ?>
</div>
<?php } ?>
<?php if ($url_flickr != ""){
?>
<div id="url-flickr">
" title="<?php _e( 'Flickr', 'bp_scholar' ) ?>"><?php _e( 'Follow us on Flickr', 'bp_scholar' ) ?>
</div>
<?php } ?>
<?php if ($url_facebook != ""){
?>
<div id="url-facebook">
" title="<?php _e( 'Facebook', 'bp_scholar' ) ?>"><?php _e( 'Follow us on Facebook', 'bp_scholar' ) ?>
</div>
<?php } ?>
<?php if ($url_youtube != ""){
?>
<div id="url-youtube">
" title="<?php _e( 'YouTube', 'bp_scholar' ) ?>"><?php _e( 'Follow us on YouTube', 'bp_scholar' ) ?>
</div>

and that created itty bitty little images. really small.

So, I'd love to fully widgetize my install, so that follow us can be placed anywhere and so that widgets can be placed above and below easily.

You'll also notice that I added the Tags widget to my new sidebar…and it spread out just above the footer. I'd rather that widget stay on the right side of the page…

How do you suggest I get to where I'm going?

Related Topics:
https://premium.wpmudev.org/forums/topic/widgetize-bpscholar-home-page-right-side-bar#post-32274
http://buddydress.com/2010/04/add-a-widget-anywhere-in-3-simple-steps/
https://premium.wpmudev.org/forums/topic/scholar-theme-widgets-query#post-30986

  • dainis

    hmm...i did add subscribe by email.

    otherwise, i can't find js in DOM, but I can see jQuery, and there is so much stuff in there...can you tell me where to look?

    also, are we taking the smartest path? I'd just like to widgetize the hard-coded sidebar...and the main thing is to remove the search and to be able to use follow us as a widget. are we going the long way round...or should i continue...

    happy to proceed as instructed...

  • Mason

    Hiya Dainis,

    If the page loads completely without firebug showing any errors, then it loaded fine. Normally firebug will stop on any error and display a message for you. If there are errors, once the page has finished loading the little firebug icon will turn red and display the number of errors present. If you don't see any errors then it didn't pick up any for javascript.

    Looking at your site it looks like you need to wrap all of those new widgets into a larger container like a separate sidebar and give it some rules with CSS so that it displays correctly.

    Perhaps you got the widgetizing part resolved though?

    Let us know. Thanks!

  • dainis

    can you tell me how i can display follow us as a widget? i think i might be leaving in or taking out one of these:

    <?php
    }
    ?>

    BTW: what is that called, a "code tag" a "code element?" a ???

    Basically, I've used the plugin "Executable PHP widget" before, and maybe that's what's causing the problem. However, for me, copying the code from sidebar-home.php and pasting it into a php-enabled text widget is the "path of least resistance," however, it's likely not the "best" route.

    Ideally, I'd remove the hard-coded widgets and be able to control the placement of widgets in the theme, but I'm not sure if my widget creation process is messed up, or why I seem to have "messed up" the widget back end.

    I guess my most critical question is: How can I create a follow us widget using the code from the theme? Can you give me copy and paste code, because I think I might have just left out a piece of code and that's why mine is displaying so oddly.

    Regarding the wrapper...I'm not sure if that's how the current wrapper works, or if I just didn't put the widget into the current wrapper.

    As far as the goal goes, this is what I care about:

    My goal is to have the widgets in the following oder on the index page in the rt. sidebar:
    Subscribe By Email
    Follow Us
    Then Whatever Additional Widgets I Choose

    what's the fastest route? can you give me code and instructions?

  • dainis

    I tried a different PHP plugin, it's called WP exec PHP

    With it active, only the home-sidebar (the original from the theme) does the "popping shut" action (preventing me from inputting a text widget) as described above.

    Though I do have home-sidebar looking the way I would like, I'd still like to be able to control that widget area with widgets (meaning that I'd like to widgetize the follow-us widget code in sidebar-home.php).

    I tried doing that by activating WP exec PHP and I created the following text widget

    [exec]

    <?php
    $show_followus = get_option('ne_buddyscholar_followuson');
    $url_twitter = get_option('ne_buddyscholar_twitter_url');
    $url_flickr = get_option('ne_buddyscholar_flickr_url');
    $url_facebook = get_option('ne_buddyscholar_facebook_url');
    $url_youtube = get_option('ne_buddyscholar_youtube_url');
    ?>

    <?php
    if ($show_followus == "yes"){
    ?>

    <div class="h4-background"><h4> <?php _e( 'Follow us', 'bp_scholar' ) ?></h4></div>
    <div class="widget-wrapper">
    <?php if ($url_twitter != ""){
    ?>
    <div id="url-twitter">
    " title="<?php _e( 'Twitter', 'bp_scholar' ) ?>"><?php _e( 'Follow us on Twitter', 'bp_scholar' ) ?>
    </div>
    <?php } ?>
    <?php if ($url_flickr != ""){
    ?>
    <div id="url-flickr">
    " title="<?php _e( 'Flickr', 'bp_scholar' ) ?>"><?php _e( 'Follow us on Flickr', 'bp_scholar' ) ?>
    </div>
    <?php } ?>
    <?php if ($url_facebook != ""){
    ?>
    <div id="url-facebook">
    " title="<?php _e( 'Facebook', 'bp_scholar' ) ?>"><?php _e( 'Follow us on Facebook', 'bp_scholar' ) ?>
    </div>
    <?php } ?>
    <?php if ($url_youtube != ""){
    ?>
    <div id="url-youtube">
    " title="<?php _e( 'YouTube', 'bp_scholar' ) ?>"><?php _e( 'Follow us on YouTube', 'bp_scholar' ) ?>
    </div>
    <?php } ?>
    </div>

    <?php
    }
    ?>

    [/exec]

    under WP exec PHP Sample in the rt sidebar at http://www.taoofyouth.atsis.com/

    However, that creates the following error:

    Parse error: syntax error, unexpected '<' in /home/mayyue/taoofyouth.com/wp-content/plugins/wp-exec-php/wp-exec-php.php(43) : eval()'d code on line 3

    Anyway, the main deal is: I'd like to be able to use widget areas on the home page of the scholar theme without digging into the hard-coded stuff...and the widget that I like is the follow us widget.

    Whatever the cleanest route is, please let me know, though I do have a "workaround" active at my "construction site."

    Best,
    Dainis

  • dainis

    the reason to not use it is because scholar has a nice hard-coded widget that does the job...my goal would be to un-hard-code that widget and turn it into a "real" widget...if that makes any sense...

    it's not really "necessary," and is kind of a "theme improvement," but it does seem like something that most users of scholar would face.

    I could also just take out all of the hard coded widgets, use my created widget area (or create more), and then use the social profiles widget you suggest...

    which route do you recommend?

    also relates to how WPMU DEV is planning on supporting scholar in the future. If you guys are going to widgetize the hard-coded follow us widget anyway (in the future), then I can just wait...

    do you guys publish feature release schedules?

  • Mason

    Hiya Dainis,

    We have discussed creating a social media widget, but I don't have an ETA on when or if that will be released.

    As far as which route to take, it's really up to you. Both lead to the same result so it's a matter of which method is more comfortable for you.

    We don't publish feature release schedules as we've found developers (and all of us here) tend to be optimists ;D

    We'd love to think we can get everything completed by specific dates, but the truth is that at times we miss those, something comes up or a bug is spotted that takes extra time and this can be upsetting to those who were depending on it being delivered on a certain timeframe.

    For my own projects, I've found it better not to wait for future solutions, but develop with the tools I have in front of me right now. If there is time and opportunity in the future, I'll go back and implement a new method when it's released.