How to reference Smarty variables inside {php} tags

I gotta’ be honest, I’ve never used the Smarty Template Engine before in my life. I’m currently working on a project to integrate WordPress and JobberBase so they use the same WordPress theme. JobberBase uses Smarty, so I’m getting a crash course.

You can use PHP in the template (.tpl) files and reference the values of the assigned Smarty template variables like this:

  $html_title = $this->_tpl_vars['html_title'];
  $echo $html_title;

I’m sure Smarty users cringe at this sort of thing, being that it adds business logic to the template files. But, this is just the functionality I need to hack the JobberBase templates without mucking around in core JobberBase code.

I found this solution in the Smarty FAQ after hours of Googling.

Global page navigation accross WordPress MU blogs

Here’s the scenario. You have a WordPress MU site with multiple blogs, but for whatever reason, you want every blog to have the same main navigation and pages. Your main site/blog hosts all of your pages. So how do you go about creating a WordPress MU Theme that will use the navigation and pages from your main site/blog accross all of your blogs? Well, I’m here to tell you how I did it.

The WordPress Codex has a function called ‘wp_list_pages.’ What I wanted to do is create a new function called ‘wp_list_main_pages.’ So I simply searched my WordPress install and copied the ‘get_pages’ and ‘wp_list_pages’ functions and pasted them into my theme’s ‘functions.php’ file. From here I made a few edits to these functions. To start with, I renamed them ‘wp_list_main_pages’ and ‘get_main_pages.’

Below is the final code I’m using to display the main navigation accross blogs. I made notes in bold to help. Hope this is helpful to you Googling coders. 🙂

// You can use this function instead of 'wp_list_pages' in your theme
function wp_list_main_pages($args = '') {
	$defaults = array(
		'depth' => 0, 'show_date' => '',
		'date_format' => get_option('date_format'),
		'child_of' => 0, 'exclude' => '',
		'title_li' => __('Pages'), 'echo' => 1,
		'authors' => '', 'sort_column' => 'menu_order, post_title'

	$r = wp_parse_args( $args, $defaults );
	extract( $r, EXTR_SKIP );

	$output = '';
	$current_page = 0;

	// sanitize, mostly to keep spaces out
	$r['exclude'] = preg_replace('[^0-9,]', '', $r['exclude']);

	// Allow plugins to filter an array of excluded pages
	$r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));

	// Query pages.
	$r['hierarchical'] = 0;
	// Right here we call our new 'get_main_pages' function
	$pages = get_main_pages($r);

	if ( !empty($pages) ) {
		if ( $r['title_li'] )
			$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';

		global $wp_query;
		if ( is_page() || $wp_query->is_posts_page )
			$current_page = $wp_query->get_queried_object_id();
		$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);

		if ( $r['title_li'] )
			$output .= '</ul></li>';

	$output = apply_filters('wp_list_pages', $output);

	// This line is sloppy and needs improvement.
	// You have to remove the name of the blog your currently on from you global navigation.
	// I'm doing this the simplest but least scalable way here.
	$output = str_replace("pressroom/", "", $output);

	if ( $r['echo'] )
		echo $output;
		return $output;

// This is essentially a private function
function &get_main_pages($args = '') {
	global $wpdb;

	// This is the magic line.
	// Now when the SQL runs to pull your navigation pages, it'll use your main blogs ID.

	// Notice here I call the original get_pages function and return the results
	$pages = get_pages($args);
	return $pages;

You can haz Austin Tech Events Widget without WordPress!

Not too long ago I posted about the Austin Tech Events Plugin for WordPress. Several folks asked me how to install it sans WordPress or in a older version of WordPress that doesn’t support widgets. Well I’ll tell ya’.

Step 1. Download the latest version of the Austin Tech Events widget and upload it to a subdirectory on your site.

Step 2. Go get yourself a Google GDATA API key here.

Step 3. Add the following code to the head section of your site. Note the sections in red. You need to add your Google API Key and be sure to change the paths below to reflect where you uploaded the Austin Tech Events widget folder.

<script type="text/javascript" src=" GOOGLE API KEY GOES HERE"></script>
<script type="text/javascript">
	var calendarURL = '';
	var pageMaxResults = 15;
	var parseWiki = true;
	var showNav = true;
	var weeks = null;
	var widgetListSize = null;
<link type="text/css" rel="stylesheet" href="" />
<link type="text/css" rel="stylesheet" href="" />
<script type="text/javascript">
	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
			if (oldonload) {
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>

Step 4. Add the following code to body of you page. Place it wherever you want the widget to show up.

	<li id="austin-tech-events" class="widget widgetWPNGCalendar">
		<h2 class="widgettitle"><a href="">Austin Tech Events</a></h2>
			<div id="wpng-cal-widget-events" style="display:none;"></div>
			<div id="wpng-cal-load-widget" class="wpng-cal-loading">
				<img class="wpng-cal-image" alt="loading..." src="/wp-content/plugins/austin-tech-events-calendar/images/loading_large.gif"/>
			<script type="text/javascript" defer="defer">
				widgetListSize = 5;

That’s all there is to it. Check out the example I created of the Austin Tech Events Plugin installed on WordPress 1.5.2. Proof it can be done! 😉 The biggest disadvantage to this approach is that you won’t be notified of code updates like you would on a proper WordPress 2.5 widget install.

Let me know if you have any questions!

Austin Tech Events Calendar WordPress Plugin

Want to promote the tech community in Austin? This is your WordPress plugin! You can see an example of the plugin on my blog’s sidebar.

The Austin Tech Events Calendar plugin is a “branch” of the wpng-calendar, a WordPress plugin for integrating a Google calendar into your WordPress blog. I’ve customized it to best display events from the events calendar.

To install this plugin:

  1. Download it from here
  2. Upload the plugin to the “wp-content/plugins” directory in your WordPress installation
  3. Activate the plugin in your WordPress admin panel
  4. Go get yourself a Google GDATA API key here
  5. In your WordPress admin panel, goto “Options -> Austin Tech Events” then enter your Google GDATA API key. If you’re running WordPress 2.5, look under “Settings -> Austin Tech Events.”
  6. Under “Presentation -> Widgets” add the widget to your side bar, alter the options if you like

That’s it!

For more information about this plugin checkout the documentation from the the wpng-calendar site.

Drop me some comments if you have questions or feedback! 🙂

PS. This plugin uses Javascript to interface the Google API. I’d love to rebuild this plugin using PHP so that the links inside of the event descriptions would help each organization’s page rank in Google search. If anyone wants to take a stab at converting this from Javascript to PHP, I’d love you forever!

Have an old version of WordPress that doesn’t support widgets? Not using WordPress at all? Check out this post: Austin Tech Events Widget for those without widgets or WordPress.

Convert from Blogger to WordPress

I recently converted this blog from Blogger (published via FTP) to WordPress. It actually turned out to be a whole lot easier than I anticipated. I’ll lay out the steps I took for you below.

Also, I should note, it was very important to me that all of my old Blogger links do a proper 301 permanent redirect to their new home on my WordPress blog. I cover this below. However, I do not cover how to convert your Blogger template to a WordPress template. I took the transition as an opportunity to create a new look for my blog. So I skipped that process.

Step 1

First! I installed WordPress on my NearlyFreeSpeech.NET hosting account. (Fact: NearlyFreeSpeech.NET is the best web host on the planet.)

Step 2

In Blogger (under Settings -> Publishing) I switched from “publish via FTP” to “publish on”

Step 3

Then I used WordPress’s awesome Blogger Import feature! (Found under Manage -> Import) You’ll notice that you can not import blogger posts hosted via FTP. This is why I temporarily switched to

Step 4

After the successful Import, I installed the “Maintain Blogger Permalinks” plugin. This plugin makes your new WordPress permalinks match your old Blogger permalinks. You only need to run this plugin once, then you can uninstall it.

Step 5

Now that my imported posts had their old permalinks, I took it a step further. I no longer wanted the archive folders (ie: /2006/03/) in my permalinks. Nor did I want my permalinks to end with the HTML file extension (ie: .html). So I added the following to the top of my .htaccess file.

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteRule ^([0-9]{4})/([0-9]{1,2})/([^/]+)\.html$ $3/ [QSA,R=301,L]

Step 6

To preserve links to your old Blogger archives add the following to the top of your .htaccess file.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^archives/([0-9]{4})_([0-9]{1,2})_([0-9]{1,2})_archive.html$ $1/$2/ [QSA,R=301,L]

Optional Step 7

During your Blogger import into WordPress, all of your Blogger “labels” are converted into WordPress “categories.” So if you want to maintain any old links to your old labels, add the following to the top of your .htaccess file.

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteRule ^(labels)/([^/]+)\.html$ category/$2/ [QSA,R=301,L]

I say this is optional because after I got my posts into WordPress, I immediately started changing all my categories and tags. So the precaution I took above turned out to be not very helpful. Oh well.

The End!

That about sums it up. It was a pretty easy transition. Of course I’ve spent hours setting up and tweaking my new template, and I’ve spent countless more hours playing with all the cool community created plugins. I just can’t help myself.

Drop me a comment if this was helpful to you! 🙂