Created
May 2, 2012 13:27
-
-
Save markwearing/2576510 to your computer and use it in GitHub Desktop.
Wordpress functions.php addition: Columns to display custom fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * This will add an additional columns called 'Students, Background, Outcome'to the custom post type of 'casestudies'. | |
| * These new columns display the specified custom fields of a post. | |
| */ | |
| add_action("manage_posts_custom_column", "casestudies_custom_columns"); | |
| add_filter("manage_edit-casestudies_columns", "setup_casestudies_admin_columns"); | |
| function setup_casestudies_admin_columns($columns) | |
| { | |
| $columns = array( | |
| "cb" => "<input type=\"checkbox\" />", | |
| "title" => "Title", | |
| "students" => "Students", | |
| "background" => "Background", | |
| "outcome" => "Outcome", | |
| 'date' => 'Published' | |
| ); | |
| return $columns; | |
| } | |
| function casestudies_custom_columns($column) | |
| { | |
| global $post; | |
| switch( $column ): | |
| case "ID": | |
| echo $post->ID; | |
| break; | |
| case "title": | |
| echo $post->post_title; | |
| break; | |
| case "students": | |
| echo get_post_meta( $post->ID, "students", TRUE ); | |
| break; | |
| case "background": | |
| echo get_post_meta( $post->ID, "background", TRUE ); | |
| break; | |
| case "outcome": | |
| echo get_post_meta( $post->ID, "outcome", TRUE ); | |
| break; | |
| endswitch; | |
| } | |
| /** | |
| * This will add an additional column called 'Image'to the custom post type of 'photogallery'. | |
| * This column will display the featured image of a post. | |
| */ | |
| add_action("manage_posts_custom_column", "photogallery_custom_columns"); | |
| add_filter("manage_edit-photo-gallery_columns", "setup_photogallery_admin_columns"); | |
| function setup_photogallery_admin_columns($columns) | |
| { | |
| $columns = array( | |
| "cb" => "<input type=\"checkbox\" />", | |
| "title" => "Title", | |
| "image" => "Image", | |
| 'date' => 'Published' | |
| ); | |
| return $columns; | |
| } | |
| function photogallery_custom_columns($column) | |
| { | |
| global $post; | |
| switch( $column ): | |
| case "ID": | |
| echo $post->ID; | |
| break; | |
| case "title": | |
| echo $post->post_title; | |
| break; | |
| case "image": | |
| echo the_post_thumbnail(array(75,75)); | |
| break; | |
| endswitch; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment