ThemeShaper Forums » Thematic

[closed]

New Feature in Revision 274 (SVN)

(22 posts)
  • Started 5 years ago by Chris
  • Latest reply from sareiodata
  • This topic is not a support question
  1. Thematic will look into its own widgets folder or into a child themes widgets folder and add and activate additional widgets. Just create a folder 'widgets' under your child theme folder and copy your own widget_whatever.php file into this folder.

    Useful for all theme developer to distribute own widgets with there Thematic child themes.

    Cheers,

    Chris

    Posted 5 years ago #
  2. this is what I call a good news ;)

    Posted 5 years ago #
  3. Awesome.

    Posted 5 years ago #
  4. You can actually do this? :) Great news! I tried to make an extra widget for a childtheme hopping that wordpress 2.7 will overwrite the widget file in thematic only to find out it only overwrites the standard templates.(no extra files)

    Posted 5 years ago #
  5. If you're already playing with this feature .. get Revision 281 (SVN) .. fixed a minor bug.

    Posted 5 years ago #
  6. cramae
    Member

    Hey all,

    I grinding my way through creating my first WordPress blog and finding thematic very cool. Between the forum here and the WordPress codex I've managed to figure most things out. But creating my own widgets still baffles me.

    Could you explain a bit more about how to make this 'widgets' folder work or maybe I should say a widget in the folder to work. I've added the folder and a widgets.php file in it with the following code and it doesn't show up in my widgets list. If I put the same code in my functions.php file it works. I know I'm missing something simple here, but plugins vs. widgets vs. hooks/filter is all still very new to me.

    <?php

    function find_a_degree_init() {
    register_sidebar_widget('Find a degree', 'find_a_degree');
    }
    add_action('widgets_init', 'find_a_degree_init');

    function find_a_degree() { ?>

    HTML CODE HERE

    <?php
    }
    ?>

    Thank in advance!

    Posted 5 years ago #
  7. Take a look into this widget .. It's one I wrote to implement the blogoscoop.net statistic button into the sidebar of my blog.


    <?php
    /*
    Plugin Name: Blog Buttons
    Description: Adds a sidebar widget to show the blogoscoop.net statistic button
    Author: Chris GoƟmann
    Version: 1.0
    Author URI: http://www.wupperpiraten.de
    */

    function widget_blog_buttons($args) {
    extract($args);
    $options = get_option('widget_blog_buttons');
    echo $before_widget;
    echo $before_title . $options['title'] . $after_title; ?>

    <img src="http://stats.blogoscoop.net/xxx/x.gif"
    alt="blogoscoop" border="0" width="80" height="15" />

    <?php echo $after_widget;
    }

    // Admin section
    function widget_control_blog_buttons() {
    global $wpdb;
    $options = get_option('widget_blog_buttons');

    if ( $_POST['blog_buttons-submit'] ) {

    $options['title'] = strip_tags(stripslashes($_POST['dkret-blog_buttons-title']));
    update_option('widget_blog_buttons', $options);
    }

    $title = htmlspecialchars($options['title'], ENT_QUOTES);

    // The Box content
    echo '<p style="text-align:right;"><label for="dkret-search-title" />' . __('Title:', 'dkret') . ' <input style="width: 200px;" id="dkret-blog_buttons-title" name="dkret-blog_buttons-title" type="text" value="'.$title.'" /></p>';
    echo '<input type="hidden" id="dkret-submit" name="blog_buttons-submit" value="1" />';
    }

    $options = get_option('widget_blog_buttons');
    if ( !is_array($options) )
    $options = array('title'=>''. __('Blog Buttons', 'thematic') .'',);
    update_option('widget_blog_buttons', $options);

    register_sidebar_widget(__('Blog Buttons','thematic'), 'widget_blog_buttons');
    register_widget_control(__('Blog Buttons','thematic'), 'widget_control_blog_buttons', 300, 200);
    ?>

    Let me know if you need more help.

    Cheers,

    Chris

    Posted 5 years ago #
  8. cramae
    Member

    Chris - THANKS! Sorry for the slow reply, but I was pulled on to other things lately. I was easily able to figure out what my widgets were missing from that.

    However, I am still confused about one thing though. (Bare with me this is going to be a bit long) My understanding of this original post is that I can create my own child theme widgets folder and put my custom widgets in there. I can't seem to get this to work. I've created a folder called widgets, but nothing I put in there shows up in the admin. For example I took your exact code and put it in my functions.php file - worked great - created a custom_widgets.php file in the child theme widgets folder - nothin'.

    I should clarify that the reason I just don't use the functions.php file (which I am currently) is I've made custom edits to the widgets.php file in thematic. My understanding of theme frameworks is this is a bad thing when it comes time to upgrade to a new version. So what my ultimate goal isn't only to put in custom widgets in the widgets folder, but to override the widget.php file in thematic with my own custom_widgets.php file. Is this even possible?

    Lastly, (I promise) Despite any false impression I may have given. I am sooo not a PHP programmer. I can understand enough to read/guess what it is doing, and copy and paste stuff together, so please explain things to me like I'm an idiot, 'cause I am :) So thanks you and everyone else on this forum, everyone around my office thinks I'm a programming genius because of what I learned from here. Only me and now you know the truth :)

    Posted 5 years ago #
  9. Hey,

    the widgets folder is designed to contain single widget files not a file collecting several widgets. You can break up your custom_widgets.php into single files or you can copy your customs_widgets.php into the base directory of your child theme and include it in your functions.php using require_once(STYLESHEETPATH . '/customs_widgets.php');

    .. and never ever edit widgets.php .. there's no reason for doing this ;-)

    Let me know if this works for you.

    Cheers,

    Chris

    Posted 5 years ago #
  10. cramae
    Member

    Perfect! With your help I've now successfully removed all my custom code and it works like a charm. Even installed version 0.9 with no ill side effects anywhere. I still have more questions to satisfy my OCD personality when it comes to organization, but that will be another time and place. Thanks again.

    Posted 5 years ago #
  11. I'm having a similar problem, and reading this thread five times hasn't helped yet.

    I've got each plugin in its own file. I place the in a "widgets" directory and the admin page didn't see them. I tried using the "require_once' from my functions.php and it didn't see them.

    The only way I seem to be able to add widgets is symlinking them into the plugins directory. Has this functionality changed?

    By the way, the code that's supposed to pick up php files in the widgets directory is supposed to scrub (and not try to load) the periods indicating previous directories, but it picks up '.' and '..' and throws errors when it can't load them.

    Posted 4 years ago #
  12. Hi,

    Plugins / Widgets??? What are you talking about?

    This feature was designed for Widgets not for Plugins. If you take a widget and drop it into the 'widgets' directory, it'll work as designed.

    Chris

    Posted 4 years ago #
  13. Thanks for the quick response. It's actually a widget, but I ended up linking it into the plugins directory after hours of trial-and-error. I just re-checked that it's not showing up on either the plugins or widget admin pages, with the file in the child theme widgets directory.

    Where can I look, or what can I show you, to try to debug this?

    Posted 4 years ago #
  14. What I've already tried is echoing debug info before and after trying "include(ABSPATH . 'wp-content/themes/' . get_stylesheet() . '/widgets/' . $widgetFile);" in library/extensions/widgets.php

    That shows that the file gets included (and it also tries to include '.' and '..'), but I don't see the widget in the admin screens.

    When I link them in through the main plugins directory, they load and work properly, so it doesn't seem to be the widget code. (When I say "them" I don't mean I've got several widgets in one file. It's one per file.)

    Posted 4 years ago #
  15. Could you please mail the widget to chris (at) wupperpiraten (dot) de

    Chris

    Posted 4 years ago #
  16. Hi Drew,

    the working copy is on its way to you :)

    Chris

    Posted 4 years ago #
  17. Is this tested with the 2.8 widget class? I tried everythink I could think of but it doesn't work.

    It dose include the widget file correctly but I can't register it. I've tried

    function My_RSS_Widget() {
        register_widget('My_RSS_Widget');
    }
    
    add_action('widgets_init', 'My_RSS_Widget');

    and just

    register_widget('My_RSS_Widget');

    but the widget is still not registered.

    I only need a darn duplicate of the text widget with a different class but it just won't work... arrrhhhh...

    Posted 4 years ago #
  18. Hi Cristian,

    works here :)

    Create a widget_my_rss.php:

    <?php
    class My_RSS_Widget extends WP_Widget {
    
    	...
    }
    
    register_widget('My_RSS_Widget');
    
    ?>

    Place it into your child theme's 'widgets' directory .. that's it.

    Chris

    Posted 4 years ago #
  19. Hi Chris,

    I couldn't get it to work.

    It's really weird. If I include it directly inside the functions.php of the themlet it works.

    Also I know that it is getting registered, just doesn't appear in the widget area next to the other widgets. I know this because if I leave it inside childthemename/widgets/adswidget.php and also include it from the functions.php inside childthemename I get the error that I can't re declare the widgets class since it has the same name.

    Here's a link to my widget:
    http://cozmoslabs.com/projects/adswidget.txt

    I have no idea why this is at this point. Could be so weird Wordpress or Thematic bug...

    Also I haven't tried to recreate it on another fresh installation of WP and Thematic so it could be something localized. I'll look at this some more.

    UPDATE
    ------------------------------
    tried this on cozmoslabs.com and it's themelet and it still doesn't appear in the widget area. Two different installations and servers.
    ------------------------------

    Thank you.
    Cristian

    Posted 4 years ago #
  20. .. will test it this evening.

    Chris

    Posted 4 years ago #
  21. Hi Cristian,

    sorry for this mess. This is my fault.

    The widget 2.8 class won't work this way in 2.8.x and 2.9.x, it's working on my development blog already running 3.0.

    Need to find out why it's working with the latest development versions.

    Chris

    Posted 4 years ago #
  22. Hi Chris,

    No need to apologize! We found a bug! Whohoo :)

    It's a good thing we know this won't work. Maybe it will save some one time in the future.

    Cheers.

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.