Category: Tutorials
September 8th, 2010
This is a really useful little snippet I found in the WordPress Codex. It allows us to check whether a page is within a specified tree, e.g. whether a page is a certain ID or if it is a subpage of that ID.
Here's the function:
function is_tree($pid)
{
global $post; // load details about this page
$anc = get_post_ancestors( $post->ID );
foreach($anc as $ancestor) {
if(is_page() && $ancestor == $pid)
{
return true;
}
}
if(is_page()&&(is_page($pid)))
...
Tags: tutorial, Wordpress, wp tricks
Posted in Tutorials, Wordpress | No Comments »
August 26th, 2010
If you wish to set a minimum word count for your posts (this can be useful for a variety of things, including maintaining a clean layout), simply add the following snippet to your functions.php file and set the number to whatever you wish.
function minWord($content)
{
global $post;
$content = $post->post_content;
if (str_word_count($content) < 100 ) //set this to the minimum number of words
wp_die( __('Error: your post is below the minimum word count.') );
}
add_action('publish_post', 'minWord');
If an author tries to publish a post with fewer ...
Tags: functions, Wordpress, wp tricks
Posted in Tutorials, Wordpress | No Comments »
July 8th, 2010
WordPress puts a lot of really useful utilities in the plugin developer's toolbox. I'm going to go through a few of them here.
These are especially useful if you're just beginning WordPress plugin development.
Define your WordPress plugin
This bit is placed at the top of your main plugin file: my_plugin.php:
/*
Plugin Name: My WordPress plugin
Plugin URI: http://my-plugin-site.com/my-plugin
Description: A description that describes my plugin and is shown on the WordPress plugin page
Version: 1.0
Author: Your Name
Author URI: http://my-plugin-site.com
License: Can people distribute this?
*/
Activate CSS and jQuery ...
Tags: plugin, Wordpress
Posted in Tutorials, Wordpress, plugins | No Comments »
June 21st, 2010
Intro and Prerequisites
Wordpress 3.0 has introduced a lot of very powerful new features into the theme developer's toolbox. The most exciting of these is probably the addition of custom post / meta types.
We are going to use these features to create a custom "portfolio" post type and add additional options to it using custom metas that will correspond to things like "project URL", "Client name", etc.
To define a custom post type, use
register_post_type();
in your functions.php and then customize the ...
Tags: custom meta, custom post types, Portfolio, tutorial, wordpress 3.0, wp tricks
Posted in Tutorials, Wordpress, php | No Comments »
May 19th, 2010
As in the first two posts of this series, Wordpress CMS Tips and Wordpress CMS Tips – Part 2, I will be covering a variety of tips and tricks for transforming a regular Wordpress installation into a full-blown content management system.
We will also be using some features only available to Wordpress 3.0.
The following tricks will be geared towards theme developers and require at least a basic knowledge of coding, at least enough to manipulate a theme file.
Multiple Widgetized Sidebars
If you ...
Tags: cms, custom post types, php, tutorial, Wordpress, wordpress 3.0, wp tricks
Posted in Tutorials, Wordpress, php | 2 Comments »