From e56098c4165a7b3a3a20a3f157ea74dda3a4f5f6 Mon Sep 17 00:00:00 2001 From: Nikolai Kristiansen Date: Sun, 20 Nov 2011 01:28:33 +0100 Subject: [PATCH] Adds image display in admin interface --- .gitignore | 1 + neuf-societies-admin.php | 21 ++++++++++++++------- neuf-societies-post-type.php | 8 ++++---- 3 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/neuf-societies-admin.php b/neuf-societies-admin.php index 28ced27..a7f95e7 100644 --- a/neuf-societies-admin.php +++ b/neuf-societies-admin.php @@ -3,15 +3,14 @@ function neuf_societies_change_columns( $cols ) { $custom_cols = array( 'cb' => '', + 'title' => __( 'Forening', 'trans' ), + 'image' => __( 'Bilde', 'trans' ), 'homepage' => __( 'Hjemmeside', 'trans' ), /*'author' => __( 'Forfatter', 'trans' ), 'date' => __( 'Publiseringsdato', 'trans' ), - 'type' => __( 'Type', 'trans' ), - 'starttime' => __( 'Dato og klokkeslett', 'trans' ), - 'endtime' => __( 'Sluttdato og -klokkeslett', 'trans' ), - 'venue' => __( 'Sted', 'trans' )*/ + 'type' => __( 'Type', 'trans' ),*/ ); - return array_merge($cols, $custom_cols); + return $custom_cols; } add_filter( "manage_society_posts_columns", "neuf_societies_change_columns" ); @@ -19,7 +18,15 @@ add_filter( "manage_society_posts_columns", "neuf_societies_change_columns" ); function neuf_societies_custom_columns( $column, $post_id ) { switch ( $column ) { case "homepage": - echo get_post_meta( $post_id, '_neuf_societies_homepage', true); + $homepage = get_post_meta( $post_id, '_neuf_societies_homepage', true ); + // default to permalink if not set + $homepage = $homepage ? $homepage : get_permalink( $post_id ); + echo ''.$homepage.''; + break; + case "image": + $thumb = get_the_post_thumbnail( $post_id, array(100, 50) ); + $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'large' ); + echo ''.$thumb.''; break; } } @@ -53,7 +60,7 @@ function add_societies_metaboxes() { function neuf_societies_div(){ global $post; - $society_homepage = get_post_meta($post->ID, '_neuf_societies_homepage', true); + $society_homepage = get_post_meta( $post->ID, '_neuf_societies_homepage', true ); ?>
diff --git a/neuf-societies-post-type.php b/neuf-societies-post-type.php index 829206d..44edd45 100644 --- a/neuf-societies-post-type.php +++ b/neuf-societies-post-type.php @@ -63,14 +63,14 @@ function neuf_societies_save_postdata( $post_id ) { if ( !current_user_can( 'edit_post', $post_id ) ) return; } + // OK, we're authenticated. - // OK, we're authenticated: we need to find and save the data - - $mydata = $_POST['_neuf_societies_homepage']; + // prefix with protocol if not present + $mydata = esc_url( $_POST['_neuf_societies_homepage'] ); // Do something with $mydata // probably using add_post_meta(), update_post_meta(), or // a custom table (see Further Reading section below) - add_post_meta($post_id, '_neuf_societies_homepage', $mydata, true); + update_post_meta($post_id, '_neuf_societies_homepage', $mydata); } ?>