Use the following code in functions.php
[ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]
add_action( 'add_meta_boxes', 'meta_box_digg' );
function meta_box_digg()
{
add_meta_box( 'digg-meta-box-id', 'Social Networking Effect ShortCode', 'wpt_digg_effect', 'page', 'side', 'default' );
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
}
function wpt_digg_effect() {
global $post;
// Noncename needed to verify where the data originated
echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
// Get the location data if its already been entered
$diggeffect = get_post_meta($post->ID, '_diggeffect', true);
// Echo out the field
echo '<input type="checkbox"' . (!empty($diggeffect) ? ' checked="checked" ' : null) . 'value="'.$post->post_name.'" name="_diggeffect" /> Publish social networking icons</label>';
echo "";
echo "Tick on checkbox if you want social networking widget on this page. ";
echo '<span style="color:#BC2C2C;font-weight:bold;"></font>';
}
// Save the Metabox Data
function wpt_save_events_meta($post_id, $post) {
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( !wp_verify_nonce( $_POST['eventmeta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
// Is the user allowed to edit the post or page?
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
// OK, we're authenticated: we need to find and save the data
// We'll put it into an array to make it easier to loop though.
$diggeffected=stripslashes($_POST['_diggeffect']);
$events_meta['_diggeffect'] = $diggeffected;
// Add values of $events_meta as custom fields
foreach ($events_meta as $key => $value) { // Cycle through the $events_meta array!
if( $post->post_type == 'revision' ) return; // Don't store custom data twice
$value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
update_post_meta($post->ID, $key, $value);
} else { // If the custom field doesn't have a value
add_post_meta($post->ID, $key, $value);
}
if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
}
}
add_action('save_post', 'wpt_save_events_meta', 1, 2); // save the custom fields
function my_include_digg_digg() {
global $post;
$select_digg="SELECT * FROM <code>wp_postmeta</code> WHERE meta_key = '_diggeffect'";
$digg_query=mysql_query($select_digg);
$digg_num=mysql_num_rows($digg_query);
if($digg_num>0){
while($digg_execu=mysql_fetch_array($digg_query))
{
$pageslug_digg[]=$digg_execu['meta_value'];
$array_count=count($pageslug_digg);
}
foreach( $pageslug_digg as $key => $value){
if($post->post_name==$value) {
if(is_page($value)){
add_filter('the_excerpt', 'dd_hook_wp_content');
add_filter('the_content', 'dd_hook_wp_content');
}
}
else{
remove_filter('the_excerpt', 'dd_hook_wp_content');
remove_filter('the_content', 'dd_hook_wp_content');
}
}
}
}
add_action('template_redirect', 'my_include_digg_digg');