About WordPress Post Thumbnail

This is a complement to our previous post The Ultimative Guide For the_post_thumbnail In WordPress 2.9. In WordPress Version 2.9 probably the most discussed feature is the post thumbnail. Important for this function, it is only working when it is explicitly enabled in the theme. This can be done with the following little snippet in the functions.php of the theme: add_theme_support('post-thumbnails');.

But even with this feature you should check for the existence of the function and offer an alternative. Only then you can leave the user the freedom to choose which WordPress version he wants to use. The functions of extensions, plugins and themes should be checked for their existence, then the functionality of the theme is secured, even if a function is not available. Similarly should it be handled with post thumbnail.

I would like to show two suggestions for alternatives below, and I refer to the detailed article about the topic images in Easier And Better Solutions To Get Pictures On Your Posts.

Continue reading …

Display Private Posts to Logged in Users

WordPress-Christmas-15Sometimes I use the function of private posting in WordPress. These contributions can only see the user who has created the post, or the administrator. To show all these article to users who are logged into the system, you can go different ways. But I'd like to highlight just two different ways.

With custom fields

With the help of custom fields you create a private field; if you can see private posts, this field has true in the field. This field, we then query in the loop on output in the frontend.

if ( have_posts() ) :
	while ( have_posts() ) : the_post();
	// the loop
	$private = get_post_custom_values('private'); // read custom field
	if ( isset($private[0]) && $private == 'true' ) {
		if ( is_user_logged_in() ) {
			// display private post, only logged users
	} else {
		// display public post, for every visitors


With capabilities

Another method is, to assign via function capabilities to the appropriate role. You can do this with the help of a Plugin, for example Members, or just with a code snippet in functions.php of the theme. You have to call the snippet just once, after that you can delete it, since the capability is saved in the data base.

Ad capabilities to read private posts read_private_posts to the role of the author.

function fb_add_cap2role() {
	global $wp_roles;
	$wp_roles->add_cap('author', 'read_private_posts');
add_action( 'init', 'fb_add_cap2role' );

Also you can also remove the rights again. This is possible with the following solution:

function fb_remove_cap2role() {
	global $wp_roles;
	$wp_roles->remove_cap('author', 'read_private_posts');
add_action( 'init', 'fb_remove_cap2role' );

Display The Total Number Of Registered Users

WordPress-Christmas-09Anyone who operates a community using WordPress, and would like to display the total number of registered users, can easily and quickly use the following small code snippet.

It reads via SQL the content of the table "users", and the numbers of IDs getting counted. This value simply gets wrapped around a text.

$myusers = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");
echo sprintf( __('We have %s registered user.', 'myTextDomain') , $myusers );