News
How to: Limiting the posts in you archive widget
I have show you how to create a custom widget in a previous post. But how about adding and additional “Archives” widget that won’t list the last 3 years (if you’ve been around that long) in month form stretching down your whole sidebar?
Well, lets take a look at the original code found in the widgets.php
file in the ./wp-includes/
folder.
<?php /** * Display archives widget. * * @since 2.2.0 * * @param array $args Widget arguments. */ function wp_widget_archives($args) { extract($args); $options = get_option('widget_archives'); $c = $options['count'] ? '1' : '0'; $d = $options['dropdown'] ? '1' : '0'; $title = empty($options['title']) ? __('Archives') : apply_filters('widget_title', $options['title']); echo $before_widget; echo $before_title . $title . $after_title; if($d) { ?> <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Month')); ?></option> <?php wp_get_archives("type=monthly&format=option&show_post_count=$c"); ?> </select> <?php } else { ?> <ul> <?php wp_get_archives("type=monthly&show_post_count=$c"); ?> </ul> <?php } echo $after_widget; } /** * Display and process archives widget options form. * * @since 2.2.0 */ function wp_widget_archives_control() { $options = $newoptions = get_option('widget_archives'); if ( isset($_POST["archives-submit"]) ) { $newoptions['count'] = isset($_POST['archives-count']); $newoptions['dropdown'] = isset($_POST['archives-dropdown']); $newoptions['title'] = strip_tags(stripslashes($_POST["archives-title"])); } if ( $options != $newoptions ) { $options = $newoptions; update_option('widget_archives', $options); } $count = $options['count'] ? 'checked="checked"' : ''; $dropdown = $options['dropdown'] ? 'checked="checked"' : ''; $title = attribute_escape($options['title']); ?> <p><label for="archives-title"><?php _e('Title:'); ?> <input class="widefat" id="archives-title" name="archives-title" type="text" value="<?php echo $title; ?>" /></label></p> <p> <label for="archives-count"><input class="checkbox" type="checkbox" <?php echo $count; ?> id="archives-count" name="archives-count" /> <?php _e('Show post counts'); ?></label> <br /> <label for="archives-dropdown"><input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="archives-dropdown" name="archives-dropdown" /> <?php _e('Display as a drop down'); ?></label> </p> <input type="hidden" id="archives-submit" name="archives-submit" value="1" /> <?php } ?>
Simple enough? Or not..
Anyway lets just add on and change a few things. Then will add the final code to your functions.php
file.
Okay, starting with the first function: wp_widget_archive
and rename to widget_archive_limit
Should look like this now:
function widget_archives_limit($args) {
Then under the this line:
$title = empty($options['title']) ? __('Archives') : apply_filters('widget_title', $options['title']);
Add:
$limit = empty($options['limit']) ? __('Limit') : apply_filters('widget_limit', $options['limit']);
At this line:
<?php wp_get_archives("type=monthly&format=option&show_post_count=$c&limit=$limit"); ?>
We have added in &limit=$limit
. The same goes for the second wp_get_archives
:
<?php wp_get_archives("type=monthly&show_post_count=$c&limit=$limit"); ?>
At the end of this code add:
wp_register_sidebar_widget('archives limit', __('Archives Limit'), 'widget_archives_limit', $widget_ops);
The whole code should look like this:
function widget_archives_limit($args) { extract($args); $options = get_option('widget_archives'); $c = $options['count'] ? '1' : '0'; $d = $options['dropdown'] ? '1' : '0'; $title = empty($options['title']) ? __('Archives') : apply_filters('widget_title', $options['title']); $limit = empty($options['limit']) ? __('Limit') : apply_filters('widget_limit', $options['limit']); echo $before_widget; echo $before_title . $title . $after_title; if($d) { ?> <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Month')); ?></option> <?php wp_get_archives("type=monthly&format=option&show_post_count=$c&limit=$limit"); ?> </select> <?php } else { ?> <ul> <?php wp_get_archives("type=monthly&show_post_count=$c&limit=$limit"); ?> </ul> <?php } echo $after_widget; } wp_register_sidebar_widget('archives limit', __('Archives Limit'), 'widget_archives_limit', $widget_ops);
That takes care of the widget its self, now we need to create the controls. Once again find the second function and change wp_widget_archive_control
to widget_archives_limit_control
Find this line:
$newoptions['title'] = strip_tags(stripslashes($_POST["archives-title"]));
and add this line below:
$newoptions['limit'] = strip_tags(stripslashes($_POST["archives-limit"]));
Then find this line:
$title = attribute_escape($options['title']);
and add this line below:
$limit = attribute_escape($options['limit']);
Finally look for this line:
<label for="archives-dropdown"><input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="archives-dropdown" name="archives-dropdown" /> <?php _e('Display as a drop down'); ?></label> </p>
and add this line below:
<p><label for="archives-limit"><?php _e('Limit (enter a number):'); ?> <input class="widefat" id="archives-limit" name="archives-limit" type="text" value="<?php echo $limit; ?>" /></label></p>
then register the widget controls:
wp_register_widget_control('archives limit', __('Archives Limit'), 'widget_archives_limit_control' );
The code should look like this:
function widget_archives_limit_control() { $options = $newoptions = get_option('widget_archives'); if ( isset($_POST["archives-submit"]) ) { $newoptions['count'] = isset($_POST['archives-count']); $newoptions['dropdown'] = isset($_POST['archives-dropdown']); $newoptions['title'] = strip_tags(stripslashes($_POST["archives-title"])); $newoptions['limit'] = strip_tags(stripslashes($_POST["archives-limit"])); } if ( $options != $newoptions ) { $options = $newoptions; update_option('widget_archives', $options); } $count = $options['count'] ? 'checked="checked"' : ''; $dropdown = $options['dropdown'] ? 'checked="checked"' : ''; $title = attribute_escape($options['title']); $limit = attribute_escape($options['limit']); ?> <p><label for="archives-title"><?php _e('Title:'); ?> <input class="widefat" id="archives-title" name="archives-title" type="text" value="<?php echo $title; ?>" /></label></p> <p> <label for="archives-count"><input class="checkbox" type="checkbox" <?php echo $count; ?> id="archives-count" name="archives-count" /> <?php _e('Show post counts'); ?></label> <br /> <label for="archives-dropdown"><input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="archives-dropdown" name="archives-dropdown" /> <?php _e('Display as a drop down'); ?></label> </p> <p><label for="archives-limit"><?php _e('Limit (enter a number):'); ?> <input class="widefat" id="archives-limit" name="archives-limit" type="text" value="<?php echo $limit; ?>" /></label></p> <input type="hidden" id="archives-submit" name="archives-submit" value="1" /> <?php } wp_register_widget_control('archives limit', __('Archives Limit'), 'widget_archives_limit_control' );
The final code:
/** * Display archives widget. * * @since 2.2.0 * * @param array $args Widget arguments. */ function widget_archives_limit($args) { extract($args); $options = get_option('widget_archives'); $c = $options['count'] ? '1' : '0'; $d = $options['dropdown'] ? '1' : '0'; $title = empty($options['title']) ? __('Archives') : apply_filters('widget_title', $options['title']); $limit = empty($options['limit']) ? __('Limit') : apply_filters('widget_limit', $options['limit']); echo $before_widget; echo $before_title . $title . $after_title; if($d) { ?> <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Month')); ?></option> <?php wp_get_archives("type=monthly&format=option&show_post_count=$c&limit=$limit"); ?> </select> <?php } else { ?> <ul> <?php wp_get_archives("type=monthly&show_post_count=$c&limit=$limit"); ?> </ul> <?php } echo $after_widget; } wp_register_sidebar_widget('archives limit', __('Archives Limit'), 'widget_archives_limit', $widget_ops); /** * Display and process archives widget options form. * * @since 2.2.0 */ function widget_archives_limit_control() { $options = $newoptions = get_option('widget_archives'); if ( isset($_POST["archives-submit"]) ) { $newoptions['count'] = isset($_POST['archives-count']); $newoptions['dropdown'] = isset($_POST['archives-dropdown']); $newoptions['title'] = strip_tags(stripslashes($_POST["archives-title"])); $newoptions['limit'] = strip_tags(stripslashes($_POST["archives-limit"])); } if ( $options != $newoptions ) { $options = $newoptions; update_option('widget_archives', $options); } $count = $options['count'] ? 'checked="checked"' : ''; $dropdown = $options['dropdown'] ? 'checked="checked"' : ''; $title = attribute_escape($options['title']); $limit = attribute_escape($options['limit']); ?> <p><label for="archives-title"><?php _e('Title:'); ?> <input class="widefat" id="archives-title" name="archives-title" type="text" value="<?php echo $title; ?>" /></label></p> <p> <label for="archives-count"><input class="checkbox" type="checkbox" <?php echo $count; ?> id="archives-count" name="archives-count" /> <?php _e('Show post counts'); ?></label> <br /> <label for="archives-dropdown"><input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="archives-dropdown" name="archives-dropdown" /> <?php _e('Display as a drop down'); ?></label> </p> <p><label for="archives-limit"><?php _e('Limit (enter a number):'); ?> <input class="widefat" id="archives-limit" name="archives-limit" type="text" value="<?php echo $limit; ?>" /></label></p> <input type="hidden" id="archives-submit" name="archives-submit" value="1" /> <?php } wp_register_widget_control('archives limit', __('Archives Limit'), 'widget_archives_limit_control' );
News
The release of Galleria, a gallery child theme of Hybrid
As the WordPress community grows, so does the amount of available themes. Galleria is a gallery-style child theme for WordPress built on the Hybird theme framework. Originally, this theme was created by Chirs Wallace for the Thematic theme framework and released at Smashing Magazine.
So I am excited to announce another theme release from WPCult and Frosty Web Designs. A few days back, I came across this post at Smashing Magazine.
Just recently we asked you to let us know what theme you would like us to release next. Among numerous comments we found many request for a gallery-theme that could be particularly useful for portfolios and showcases. At the very same time Christopher Wallace has been designing an advanced gallery-WordPress-theme for the design community and Smashing Magazine’s audience. And today finally we are proud to release it – for free, of course.
Well, I liked this theme, and while I am a big fan of the Thematic theme, I know there are many out there who love Hybrid. Hybrid is Justin Tadlocks theme framework, which can be downloaded for free at http://themehybrid.com/themes/hybrid.
Just an FYI, this site is running hybrid as a parent theme. 🙂
So…
I contacted Chris and told him of this theme port I would be doing. After a few days of modifications, bug fixes, and styling, the theme is ready for public release.
While Galleria shares a few qualities with his sibling, the differences are notable in the style, color, and layout throughout the theme, including the theme options.
More info
For more info and documentation, refer to the readme.html file included in the download or visit the Galleria theme page.
Some features
- dynamic image re-size on a single page.
- WordPress 2.7 compatible
- Built on the Hybrid framework
- jQuery hover effects
- jQuery scrolling effects.
- ‘Save to Delicious’ link
- ‘Tweet This’ link
- Flexible footer widget area
Download [download#5#format=2]
News
The new design in progress
Okay, so by now you may notice something. You may be thinking “the site looks a lot different”, and you are correct. Over the past few weeks I’ve decided that the site needed a different flare and feel. While many and most site’s these days are popping up with featured posts, and jQuery sliders, I wanted to steer away from that and go old school. While I had some trouble’s activating the theme today which didn’t allow me to fully finish the theme, 99% of it is done.
The site is still build on the powerful Hybrid theme framework. Enjoy.
News
Bar Camp Los Angles 7
Hello from BarCampLA in beautiful Culver City. It’s a bit early and presentation’s don’t start till after lunch. While I hadn’t planned on making a presentation, I got an email from Shen asking if I’d do a collaboration presentation, and I guess i agreed.
So at this time Shen, myself and possibly Michael Dorausch. will be doing a panel presntation at 6:00pm in track 3 of the BarCamp room here in the OTX facility.
Links
- Austin Passy
- Twitter: @TheFrosty
Personal Blog: TheFrosty.com - Shen Deshayne
- Twitter: @shennyg
Site: Shen Deshayne - Michael Dorausch
- Twitter: @Chiropractic
Site: Michael Dorausch
-
Tips & Tricks4 months ago
WordPress Security Hacks
-
Pages2 months ago
Write For Us – Guest Post
-
Showcase2 months ago
StylizedWeb.com
-
News1 month ago
How to: Show/Hide any div box with jQuery in WordPress
-
Tips & Tricks3 months ago
How to: show/hide a widget in WordPress with jQuery
-
Tips & Tricks3 weeks ago
Remove the title attribute using jQuery
-
Plugins3 months ago
Top Membership plugins
-
Tips & Tricks2 months ago
Limit the characters that display on the_title
Jeana
January 31, 2009 at 5:06 pm
I might want that, put it on my site??
Jeana´s last blog post..::Paris Hilton and Her BFF::