Forked from germanny/fn-post-custom-fields-infographic.php
Created
December 6, 2012 14:40
-
-
Save ericrasch/4224881 to your computer and use it in GitHub Desktop.
Infographic standard form
This file contains 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
<?php | |
$ig_post_custom_fields = array ( | |
"infographic" => array( | |
"name" => "is_infographic", | |
"std" => "", | |
"title" => "Is this an infographic post?", | |
"description" => "If you check this box, we'll add a Pin It share option.", | |
"type" => "checkbox"), | |
"image_url" => array( | |
"name" => "image_url", | |
"std" => "", | |
"title" => "Image url", | |
"description" => "Image for infographic posts.", | |
"type" => "input"), | |
"link_text" => array( | |
"name" => "link_text", | |
"std" => "", | |
"title" => "Link text", | |
"description" => "Optional! Enter the name of the site as you wish it to appear after the From:. If you enter nothing, we'll use the name of the blog from the General Settings tab.", | |
"type" => "input"), | |
"content_placement" => array( | |
"name" => "content_placement", | |
"std" => "", | |
"options" => array("Above Everything", "Below Infographic", "Below Everything"), | |
"title" => "Content Placement", | |
"description" => "Do you want the content to be above the infographic, below the infographic but above the embed code, or below everything?", | |
"type" => "radio"), | |
); | |
function ig_post_custom_fields() { | |
echo '<p style="margin-bottom:10px;"><b>Don\'t put your infographic code in the box above. Instead, complete this form and we\'ll put it together for you.</b></p><hr>'; | |
global $post, $ig_post_custom_fields; | |
foreach($ig_post_custom_fields as $ig) { | |
$ig_value = stripslashes(get_post_meta($post->ID, $ig['name'], true)); | |
if($ig_value == "") | |
$ig_value = $ig['std']; | |
echo '<p style="margin-bottom:10px;">'; | |
echo '<input type="hidden" name="'.$ig['name'].'_box" id="'.$ig['name'].'_box" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />'; | |
switch ( $ig[ 'type' ] ) { | |
case "checkbox": | |
if ( esc_attr($ig_value) === "true" ){ | |
$checked = "checked=\"checked\""; | |
} else { | |
$checked = ""; | |
} | |
echo'<label for="'.$ig['name'].'"><input type="'.$ig['type'].'" name="'.$ig['name'].'" id="'.$ig['name'].'" class="checkbox" value="true" '.$checked.'> <strong>'.$ig['title'].'</strong> <small><em>'.$ig['description'].'</em></small></label><br />'; | |
break; | |
case "radio": | |
echo '<p><strong>'.$ig['title'].'</strong> <small><em>'.$ig['description'].'</em></small><br>'; | |
$radio_options = $ig['options']; | |
foreach ($radio_options as $radio_option) { | |
$radio_option_combined = strtolower(str_replace(' ', '-', $radio_option)); | |
if ( esc_attr($ig_value) === $radio_option_combined ){ | |
$checked = "checked=\"checked\""; | |
} else { | |
$checked = ""; | |
} | |
echo'<label for="'.$radio_option_combined.'"><input type="'.$ig['type'].'" name="'.$ig['name'].'" id="'.$radio_option_combined.'" class="radio" value="'.$radio_option_combined.'" '.$checked.'> <strong>'.$radio_option.'</strong></label> '; | |
} | |
echo '</p>'; | |
break; | |
case "input": | |
echo'<label for="'.$ig['name'].'"><strong>'.$ig['title'].'</strong> <small><em>'.$ig['description'].'</em></small></label><br><input type="'.$ig['type'].'" name="'.$ig['name'].'" id="'.$ig['name'].'" value="'.esc_attr($ig_value).'" style="width:98%;"><br>'; | |
break; | |
} | |
echo '</p>'; | |
} | |
} | |
function create_post_meta_box() { | |
global $theme_name; | |
if ( function_exists('add_meta_box') ) { | |
add_meta_box( 'new-meta-boxes', 'Infographic Image', 'ig_post_custom_fields', 'post', 'normal', 'high' ); | |
} | |
} | |
function save_postdata( $post_id ) { | |
global $post, $ig_post_custom_fields; | |
foreach($ig_post_custom_fields as $ig) { | |
// Verify | |
if(isset($_POST[$ig['name'].'_box'])) { | |
if ( !wp_verify_nonce( $_POST[$ig['name'].'_box'], plugin_basename(__FILE__) )) { | |
return $post_id; | |
} | |
if ( 'page' == $_POST['post_type'] ) { | |
if ( !current_user_can( 'edit_page', $post_id )) | |
return $post_id; | |
} else { | |
if ( !current_user_can( 'edit_post', $post_id )) | |
return $post_id; | |
} | |
} | |
if(isset($_POST[$ig['name']])) { | |
$data = $_POST[$ig['name']]; | |
if(get_post_meta($post_id, $ig['name']) == "") | |
add_post_meta($post_id, $ig['name'], $data, true); | |
elseif($data != get_post_meta($post_id, $ig['name'], true)) | |
update_post_meta($post_id, $ig['name'], $data); | |
} else { | |
delete_post_meta($post_id, $ig['name'], get_post_meta($post_id, $ig['name'], true)); | |
} | |
} | |
} | |
add_action('admin_menu', 'create_post_meta_box'); | |
add_action('save_post', 'save_postdata'); | |
?> |
This file contains 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
<?php | |
/* POST CUSTOM FIELDS UI | |
********************************************************************************************************************************/ | |
include_once('functions/fn-post-custom-fields-infographic.php'); | |
?> |
This file contains 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
Here's what the backend looks like: | |
http://cloud.jen.gs/LNqx | |
This works if there is an Infographics category, or if the user checks the Is this an infographic? box (in case the user doesn't want to have a special category for it). |
This file contains 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
<?php | |
/** | |
* The Template for displaying Infographic posts. | |
*/ | |
get_header(); | |
?> | |
... Your stuff here. | |
<?php | |
$image_url = get_post_meta($post->ID, 'image_url', TRUE); | |
$link_text = get_post_meta($post->ID, 'link_text', TRUE); | |
$content_placement = get_post_meta($post->ID, 'content_placement', TRUE); | |
if( $content_placement == 'above-everything' || $content_placement == '' ) { the_content(); } | |
?> | |
<p><a href="<?php the_permalink(); ?>"> <img alt="" border="0" src="<?php echo $image_url; ?>"></a></p> | |
<?php if( $content_placement == 'below-infographic' ) { the_content(); } ?> | |
<h3>Embed the image above on your site</h3> | |
<p><textarea><a href="<?php the_permalink(); ?>"><img src="<?php echo $image_url; ?>" alt="<?php the_title(); ?>" width="500" border="0" /></a><br />Presented By: <a href="<?php the_permalink(); ?>">Please Include Attribution to <?php if($link_text) { echo $link_text; } else { echo get_option('blogname'); }; ?> With This Graphic</a></textarea></p> | |
<?php if( $content_placement == 'below-everything' ) { the_content(); } ?> | |
... Finish up your stuff | |
<?php get_footer(); ?> |
This file contains 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
<?php | |
/** | |
* The Template for displaying all single posts. | |
*/ | |
if(get_post_meta($post->ID, 'is_infographic', TRUE) || in_category('infographic')) { | |
include('single-infographic.php'); | |
} else { | |
get_header(); | |
?> | |
... Your Stuff here | |
<?php get_footer(); } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment