002houston Magazine
Pinkalicious
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).
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:
- Copied page_blog.php from the genesis directory, which only contains genesis() function call.
- Then added the following function.
[php]
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' );
}
[/php]
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.
How to Get All Users of a Specific Role
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.
[php]
function wps_get_users_of_role( $role ) {
$wp_user_search = new WP_User_Query( array( 'role' => $role ) );
return $wp_user_search->get_results();
}
[/php]
This will give you an array that contains the following in an object:
[php]<pre>stdClass Object
(
[ID] => 1
[user_login] => username
[user_pass] => serialized PASSWORD
[user_nicename] => mynicename
[user_email] => [email protected]
[user_url] => http://mydomain.com
[user_registered] => GMT Time Stamp
[user_activation_key] => Something funky!
[user_status] => 0
[display_name] => My Display Name
)</pre>
[/php]
You can even set a predefined array and get only necessary information.
[php]
$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();
[/php]
Here's the result:
[php]<pre>stdClass Object
(
[user_login] => wpsmith
[user_nicename] => wpsmith
[user_email] => [email protected]
[user_url] =>
)</pre>
[/php]
- « Previous Page
- 1
- …
- 23
- 24
- 25
- 26
- 27
- …
- 60
- Next Page »