About Travis Smith

As a WordPress Enthusiast, Travis writes about his journey in WordPress trying to help other WordPress travelers and enthusiasts with tutorials, explanations, & demonstrations of the things he learns.

post

Realty Resource 24×7 (coming soon…)

post

Riverstone Organizational Advisors (coming soon…)

post

Uncornered Market (coming soon…)

post

002houston Magazine

post

Pinkalicious

post

How to Hide the Featured Image of a Specific Category on the Blog Page in Genesis

So, in case you forgot, in Genesis Featured Images can be added to the blog page by selecting the checkbox “Include the Featured Image?” in Genesis > Theme Settings > Content Archives (admin url: http://domain.com/wp-admin/admin.php?page=genesis#genesis-theme-settings-posts).

Genesis Content Archives

Click for Larger Image

So what if you wanted to remove the featured images of a specific category (say category ID 126 [to get the category ID, use a plugin called Simply Show IDs--makes it quite easy!])?

Here is what I did:

  1. Copied page_blog.php from the genesis directory, which only contains genesis() function call.
  2. Then added the following function.
add_action( 'genesis_before_post' , 'wps_no_feature_image' );
add_action( 'genesis_after_post_content' , 'wps_no_feature_image' );
/*
 * Remove Featured Image from Small Group Show category on blog page
 * @author Travis Smith
 *
 */
function wps_no_feature_image() {
	global $post;

	if ( has_category( 126 , $post ) && 'genesis_before_post' == current_filter() )
		remove_action( 'genesis_post_content', 'genesis_do_post_image' );
	elseif ( has_category( 126 , $post ) && 'genesis_after_post_content' == current_filter() )
		add_action( 'genesis_before_post_content', 'genesis_do_post_image' );
}

First and foremost, we cannot simply remove the action and keep going because then it will be unhooked for all categories on that page after. So what’s happening here?

Now, the Genesis Featured Image appears on the genesis_post_content hook. So I need to call my function before that hook (or earlier in priority) to remove that action. So I call the function on genesis_before_post which occurs before genesis_post_content. Then after I pass genesis_post_content hook, I need to add the action back for the next post.

So, if I am illustrating this, it’s as though I am walking down the hallway approaching a hook with a hat that I was going to put on my head. Before I get to the hook, my brother takes the hat, and after I pass the hook, my brother puts the hat back on the hook for the next person.

post

How to Get All Users of a Specific Role

WordPress Users
Recently, I needed to get all users of a certain role to modify a Comments Widget to remove those. Since WordPress 3.1, WordPress has made this quite easy to do now.

function wps_get_users_of_role( $role ) {
	$wp_user_search = new WP_User_Query( array( 'role' => $role ) );
	return $wp_user_search->get_results();
}

This will give you an array that contains the following in an object:

<pre>stdClass Object
        (
            [ID] => 1
            [user_login] => username
            [user_pass] => serialized PASSWORD
            [user_nicename] => mynicename
            [user_email] => my@email.com
            [user_url] => http://mydomain.com
            [user_registered] => GMT Time Stamp
            [user_activation_key] => Something funky!
            [user_status] => 0
            [display_name] => My Display Name
        )</pre>

You can even set a predefined array and get only necessary information.

$args = array();
$args[0] = 'user_login';
$args[1] = 'user_nicename';
$args[2] = 'user_email';
$args[3] = 'user_url';
$wp_user_search = new WP_User_Query( array( 'role' => 'editor', 'fields' => $args ) );
$editors = $wp_user_search->get_results();

Here’s the result:

<pre>stdClass Object
        (
            [user_login] => wpsmith
            [user_nicename] => wpsmith
            [user_email] => travis@wpsmith.net
            [user_url] =>
         )</pre>