Posted on Thursday, December 3rd, 2009 by
Dan Imbrogno
I’ve been using the WPML plugin on a few sites recently to turn Wordpress into a very powerful multilingual CMS, with great success. I really have to applaud these guys for building a very useful plugin. On the to-do list is integrating their plug-in with Wordpress’ built-in widgets. A few people have mentioned getting stuck when trying to use the Links feature of Wordpress, which does not currently work with WPML.
To fix this issue, I’ve thrown together a quick widget that acts as a wrapper for Wordpress’ built-in widget, but lets you set a different link category for each language you have setup using WPML. I hope you find this useful.
To install, copy and paste this into your theme’s function.php file or insert code into a file in the plugins directory.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
| add_action('widgets_init', array('LinkTranslationWidget','register_widget'));
class LinkTranslationWidget extends WP_Widget
{
function LinkTranslationWidget() {
/* Widget settings. */
$widget_ops = array( 'classname' => 'LinkTranslationWidget', 'description' => __('This widget allows you to set different link categories to display based on a language setting.', $this->plugin_name) );
/* Widget control settings. */
/* Create the widget. */
$this->WP_Widget( 'LinkTranslationWidget', __('WPML Links'), $widget_ops );
}
function register_widget()
{
register_widget('LinkTranslationWidget');
}
function widget( $args, $instance ) {
global $sitepress;
if(class_exists('WP_Widget_Links')) {
$link_widget = new WP_Widget_Links();
if(isset($sitepress))
{
$lang = $sitepress->get_current_language();
$instance['category'] = $instance[$lang.'_category'];
$link_widget->widget($args, $instance);
}
}
}
function update($new_instance, $old_instance) {
$new_instance = (array) $new_instance;
$instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0);
foreach ( $instance as $field => $val ) {
if ( isset($new_instance[$field]) )
$instance[$field] = 1;
}
$langs = $this->GetLangs();
foreach($langs as $lang=>$lang_id)
{
$instance[$lang.'_category'] = intval($new_instance[$lang.'_category']);
}
return $instance;
}
function form($instance) {
$settings = $this->GetSettings();
$langs = $this->GetLangs();
$instance = wp_parse_args( (array) $instance, $settings );
$link_cats = get_terms( 'link_category');
foreach($langs as $lang=>$lang_id)
{
echo '<p><label for="'. $this->get_field_id($lang.'_category').'">'. __('Select Link Category') . ' (' .$lang.'): </label>';
echo '<select id="'. $this->get_field_id($lang.'_category').'" name="'. $this->get_field_name($lang.'_category').'">';
foreach ( $link_cats as $link_cat ) {
echo '<option value="' . intval($link_cat->term_id) . '"'
. ( $link_cat->term_id == $instance[$lang.'_category'] ? ' selected="selected"' : '' )
. '>' . $link_cat->name . "</option>\n";
}
echo '</select></p>';
}
?>
<p>
<input class="checkbox" type="checkbox" <?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" />
<label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
<input class="checkbox" type="checkbox" <?php checked($instance['name'], true) ?> id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" />
<label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />
<input class="checkbox" type="checkbox" <?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" />
<label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />
<input class="checkbox" type="checkbox" <?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" />
<label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
</p>
<?php
}
function GetLangs()
{
global $sitepress_settings;
$langs = $sitepress_settings['default_categories'];
return $langs;
}
function GetSettings()
{
$settings = array();
$settings['images'] = true;
$settings['name'] = true;
$settings['description'] = false;
$settings['rating'] = false;
$langs = $this->GetLangs();
foreach($langs as $lang=>$lang_id)
{
$settings[$lang.'_category'] = '';
}
return $settings;
}
} |
Posted on Saturday, November 7th, 2009 by
Dan Imbrogno
Okay, so when you try to include the tinyMCE code using wordpress’ built in wp_enqueue_script() function, it does absolutely nothing. If you try to manually include the script, you’ll end up with all sorts of javascript errors, and missing language translations. However, if you simply call wp_tiny_mce(); in the template_redirect or wp_head function, all the javascript for tiny_mce is loaded properly. Then all you need to do, is run your tinymce.init script to setup your text editor. For example:
Posted on Friday, August 21st, 2009 by
Dan Imbrogno
This was a big head banger.
If you are are using query_posts multiple times on a page, and are trying to paginate the second loop on the page, the following
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
will always return 1, Unless you place wp_reset_query() below the previous loop.
rewind_posts();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(
array(
'cat'=>‘5′,
‘orderby’=>’date’,
‘order’=>’DESC’
)
);
if(have_posts())
{
?>
// Post template goes here.
}
wp_reset_query();
?>
Pagination should now work for the next loop.
Posted on Friday, April 17th, 2009 by
Dan Imbrogno
It seems like only yesterday, I set out to build my first ever Wordpress Plug-in. Bright eyed and bushy tailed, I poured over the Wordpress Codex, putting together the pieces of the process until I finally got the big picture. The Wordpress Codex is an amazing resource for anyone looking to get into Wordpress development; I strongly recommend any new developer read through the “Writing a Plugin” section.
While learning, I had a difficult time finding a straightforward template I could use as a base for my plug-ins. I wanted something that was clean and well-organized but also provided examples of more complex behaviours, such as: Internationalization, Widgets and Front and Back-End Ajax. I wanted to ensure my plug-in functionality was encapsulated inside a class structure so my functions and variables wouldn’t conflict with the Wordpress Core, or other plug-ins.
I’ve finally gotten around to writing this template plug-in, and I thought I would share it with the community to get your feedback and improvements, and hopefully save new developers some time. If you are interested in learning how to build a plug-in, and have a strong programming background, you can look through my sample code, read the comments and pretty much piece together how everything works. If you want a more thorough description of what is going on, read through this article.
You can download the plug-in from the Wordpress Plugin directory.
Getting Familiar With the Brolly Template Plug-in
- Download the template plug-in.
- Place the files in the plug-ins directory of your development installation of Wordpress.
- Come up with a unique name for your plug-in, such as MyPlugin. Check the Wordpress Plug-in directory to ensure this name hasn’t been used.
- Rename the plug-in folder from B2Template to your plug-in name (i.e. MyPlugin). Do not use spaces or special characters.
- Rename the file B2Template.php to MyPlugin.php
- Rename the file B2Template.class.php to MyPlugin.class.php
- Rename the class inside MyPlugin.class.php from B2Template to MyPlugin
- Rename the constructor function inside MyPlugin.class.php from B2Template() to MyPlugin()
- Activate the plugin from the Wordpress Plugin Administration Panel
- Add the Template widget to your sidebar from the Wordpress Appearance Administration Panel
- View your site, and interact with the widget to observe it’s behaviour
- From the Wordpress Administration page, click on Settings, and select MyPlugin.
- Interact with the plugin from this page, to view its behaviour.
How to Write a Plugin Using the Brolly Template Plug-in
Note: Substitute B2Template in the instructions below, to whatever you named your plugin (i.e. MyPlugin).
There are two main files in the Brolly Wordpress Plug-in Template. The first, B2Template.php, is used to initialize the plugin and route various Wordpress actions and filters to class methods in the second file, B2Template.class.php. Keeping all our plug-in functions inside a class gives us greater flexibility to reuse the code we write for the plugin. It also prevents naming conflicts from occuring when multiple plug-ins use the same function or variable names.
Continue reading.. ›
Posted on Thursday, March 26th, 2009 by
Dan Imbrogno
We’ve just rolled out a new project, here at Brolly. Our client is, the Mayfair Theatre, a local independently run movie theatre in Ottawa, Ontario. The theatre recently closed down for renovations and is now under new ownership. Their web site was in serious need of an update, so we took the opportunity to do some really new and exciting things. We have been very excited about this project – it gave us great freedom to further develop our experience in social media and focus on providing meaningful interaction between our client and their customers.

Like many of our other projects, the website is built upon the WordPress platform. We built a custom plugin for them to manage their upcoming movie listings. This plugin has some great features:
IMDB Integration
The Wordpress plugin allows the Mayfair Theatre to manage their upcoming movies and showtimes. Instead of forcing the administrator to enter in details for each movie that’s playing, we interfaced with a very neat movie database api, called The Movie Database, to allow them to import upcoming movie information, YouTube trailers and high quality artwork. This feature will saves huge amounts of time.
Twitter Integration
We set up the theatre with a twitter account, @mayfairtheatre, and used the Twitter API to automatically broadcast what movies are playing on a daily basis. We are encouraging users to follow the theatre’s Twitter account with a series of giveaways including: movie passes, free concession coupons and movie posters. We believe that keeping people informed of show times on a daily basis will greatly improve attendance.
Google Calendar
Another way we are keeping users up-to-date on the movie schedule is by integrating show times with Google Calendar using the Google API. This calendar stays synchronized with the online schedule and allows users to add the calendar to their computer and mobile devices.
By leveraging existing APIs we were able to build a lot of great functionality into the site, within a limited budget and short development cycle. It seems like every day we are finding new and exciting ways to expand WordPress to accommodate the diversity of our clients. Look for more exciting plugins and services coming soon!
Posted on Sunday, January 18th, 2009 by
Dan Imbrogno
In response to the current state of the American economy many companies are looking for innovative methods of reducing costs. A business looking to develop or overhaul their corporate web presence should consider shedding their expensive content management system for a lower cost alternative. Companies have heard a great deal in the last few years about the benefits of open-source. The recent culture of belt-tightening that has spread through all major industries provides companies with an excellent opportunity to explore these technologies.
Here at Brolly, we have just launched a new corporate website for Aurora Importing and Distributing, a medium sized Canadian food importing business, built entirely on the WordPress platform.

Continue reading.. ›
Posted on Tuesday, January 6th, 2009 by
John Wiseman
I’m putting together my first WordPress theme which requires three dynamic sidebars (don’t ask!!). For some reason I can’t figure out how to add the other two dynamic sidebars.. Could you help me please?
Adding in multiple sidebars is fairly straightforward and you can create as many as you need.
Locate your functions.php file in your theme and add the following code:
1
2
3
4
5
6
7
8
9
10
| <?php
if(function_exists('register_sidebar'))
register_sidebar(array(
'name' => 'Sidebar One', // The sidebar name to register
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
?> |
Continue reading.. ›
Posted on Wednesday, December 31st, 2008 by
John Wiseman
We completed our series on practical tips for writing a successful blog.
The entries from start to finish are linked below:
Posted on Friday, December 26th, 2008 by
John Wiseman
You may be surprised at some rewarding benefits of blogging that you may experience:
- Research that you do from blogging on different topics will be well archived for later retrieval.
- Making your business more transparent, open and honest improves client relations.
- Future clients can assess your expertise by consulting the blog in which you have articulated your approach and complex ideas clearly and effectively.
- Feedback from readers will give you valuable information with which to improve your business approach.
- Participation in a community of professional peers will give you valuable business resources.
All this and more can result from a blog that works for you. So, to summarize, some of our most important recommendations for developing a successful business blog:
1. Cultivate a writing style that is characterized by an honest and authentic perspective that demonstrates your passion and expertise. Potential clients reading the blog will be drawn to authenticity above all else - they are not interested in reading promotional writing from the cold voice of a seemingly large business. They would like to support businesses run by people who love what they do and who are able to express their knowledge effectively.
2. Commit to regular posting to encourage loyal readers. Readers subscribe to blogs that are active with regular posts - the frequency of posting will reflect on the activity and vigour of the business itself.
3. Write posts that are on topic and of reasonable length (500 words is a good number to aim for).
4. Link abundantly to helpful resources for your readers and the posts of other blogs. If you make your site rich with resources in your industry, it will help to establish your business’ reputation and attract new clients and like-minded thinkers to help your business grow.
Continue reading.. ›
Posted on Thursday, December 18th, 2008 by
John Wiseman
Monitoring Blogging Success
Once blogging on a regular basis and beginning to build new relationships, it can be helpful to keep track of the progress of your blog. Statistics are easy to review for ongoing measurable information about the readers of your blog.
Recommended tools for monitoring statistics are:
- A Google Analytics account that will give you detailed information on who is visiting your site.
- A Feedburner account that will keep track of the number of subscribers.
You can also visit major blog search engines to find link citations to your site made by other bloggers. A few popular blog search engines are: Technorati, Feedster, Blogpulse and Bloglines.
In measuring your overall ROI and blog success, there are several metrics it can be helpful to review:
Continue reading.. ›