Template parts as widgets

On a project this morning, I had a need to pull in some formatted content into a sidebar. My first inclination was to A) Use a plugin like Query Posts to pull it in or B) Write up a custom widget we could use. I opted for neither.

The thing is, we’ve already got the content formatted into a template part file and the effort involved to roll it into a widget really wouldn’t be worth the effort. This isn’t a client project, so it doesn’t necessarily have to be pretty on the back-end … it just has to work. So I opted for using get_template_part().

The nice thing about using get_template_part() to include WordPress templates is that you can call them from anywhere in your theme. And with a bit of help from something like Otto’s PHP Code Widget plugin, you can even include them in sidebars! Some people might see it as a bit of a janky way to accomplish it, but it got the job done.

It’s pretty straightforward:

  1. Install PHP Code Widget
  2. Create a template part in your theme/child theme directory
  3. Add an instance of the PHP Code idget to a sidebar via Appearance > Widgets
  4. Insert a get_template_part() call to include your template part

New local-to-live deployment plugin falls a bit short

A new local-to-live deployment plugin called WP Live Server Deploy was brought to my attention last week by a post over at WP Force.

The plugin boasts an automated set of features to handle the menial tasks of MySQL dumps + find & replace, plus handling your file transfers. Out of the box it seemed pretty promising. I’d say the biggest disappointment out of the box is a complete lack of SFTP/SSH support for the transfer. You can only do so much over FTP alone and the plugin failed miserably to handle the MySQL part of the equation.

Along that vein, there’s a so-called “Manual” option for handling the MySQL dumps. This would be fine, except that it doesn’t work — it nets an empty SQL file. I’d say @sagetarian has some work to do yet, but I’m looking forward to seeing another iteration. You can download the plugin via the WP.org repo and/or follow development on Github.