I’m currently working on a Thesis project where I need to work with custom metaboxes. WPAlchemy jumped out as a pretty good solution, so I went ahead and downloaded/install it as instructed – but it didn’t work. Well when I say it didn’t work, what I mean is that the fields and styles for the fields within the metabox wouldn’t show up. I found a fix for it. Here it is.
By default, this is what WPAlchemy’s
/metaboxes/setup.php looks like:
<?php include_once WP_CONTENT_DIR . '/wpalchemy/MetaBox.php'; // global styles for the meta boxes if (is_admin()) wp_enqueue_style('wpalchemy-metabox', get_stylesheet_directory_uri() . '/metaboxes/meta.css'); /* eof */
Now the issue here is that
http://yourdomain.com/wp-content/themes/yourtheme (Function Reference/get stylesheet directory uri).
As we know, when working with Thesis, all your custom Thesis files reside in the
/custom/ directory, and therein lies the problem. Changing the code to the following worked for me:
<?php include_once WP_CONTENT_DIR . '/wpalchemy/MetaBox.php'; // global styles for the meta boxes if (is_admin()) wp_enqueue_style('wpalchemy-metabox', get_stylesheet_directory_uri() . '/custom/metaboxes/meta.css'); /* eof */
Notice the inclusion of the custom directory in the code. It now loads the stylesheet to format the metaboxes elements. Win.
But there’s one more issue – the same code is used to call the content of your metabox. The same principle needs to be applied here, but with a slightly different change. If you open up
metaboxes/simple-spec.php, then you’ll see this as the default code:
<?php $custom_metabox = $simple_mb = new WPAlchemy_MetaBox(array ( 'id' => '_custom_meta', 'title' => 'My Custom Meta', 'template' => get_stylesheet_directory() . '/metaboxes/simple-meta.php', )); /* eof */
/custom/ is missing. The function
get_stylesheet_directory() returns something like so:
/var/www/html/myblog/wp-content/themes/my_theme (Function Reference/get stylesheet directory)
So simply amending the function like so to include the
/custom/ directory like so makes it work:
<?php $custom_metabox = $simple_mb = new WPAlchemy_MetaBox(array ( 'id' => '_custom_meta', 'title' => 'My Custom Meta', 'template' => get_stylesheet_directory() . '/custom/metaboxes/simple-meta.php', )); /* eof */
And there you have it, WPAlchemy should now be working with Thesis for you.
On a final note, I’m only using the
simple-spec.php file here. If your using any of the other metaboxes files, i.e. one of these:
include_once 'metaboxes/full-spec.php'; include_once 'metaboxes/checkbox-spec.php'; include_once 'metaboxes/radio-spec.php'; include_once 'metaboxes/select-spec.php';
then your going to need to repeat the process of appending the custom directory to the array as shown above.
Yes, I know you could just put the
/metaboxes/ folder in your thesis folder, but I prefer to put any files that I work with in the
/custom directory as that’s where you normally place any custom code & files.