ID, 'aptmicrodata_microdata_type');
if($microDataType[0] != '' || $microDataType[0] != 'none') {
$box = '';
wp_enqueue_script('aptmicrodata_style', '/wp-content/plugins/APTRichSnippets/style.css');
if($microDataType[0] == 'review') {
$box = aptmicrodata_build_review_box();
} elseif($microDataType[0] == 'event') {
$box = aptmicrodata_build_event_box();
} elseif($microDataType[0] == 'music') {
$box = aptmicrodata_build_music_box();
}
$content = $content.$box;
}
return $content;
}
function aptmicrodata_build_review_box() {
global $post, $aptmicrodata_box_top, $aptmicrodata_box_bottom;
$itemReviewed = get_post_meta($post->ID, 'aptmicrodata_review_itemreviewed');
$itemSummary = get_post_meta($post->ID, 'aptmicrodata_review_summary');
$rating = get_post_meta($post->ID, 'aptmicrodata_review_rating');
$author = get_the_author($post->ID);
$dateReviewed = get_the_date('', $post->ID);
$dateReviewedFormated = get_the_date('Y-m-d', $post->ID);
$box = $aptmicrodata_box_top.'
'.$dateReviewedFormated.'
'.$itemReviewed[0].'
Reviewed by
'.$author.' on
.
'.$itemSummary[0].'
Star rating:
'.$rating[0].'';
$numberStars = (int) $rating[0];
for($x=1; $x <= $numberStars; $x++) {
$box .= '
';
}
if(strpos($rating[0], '.')) {
$box .= '
';
}
$box .= '
';
if(current_user_can( 'manage_options' )) {
$box .= '
Test rich snippet';
}
$box .= "
$aptmicrodata_box_bottom";
return $box;
}
function aptmicrodata_build_event_box() {
global $post, $aptmicrodata_box_top, $aptmicrodata_box_bottom;
$eventSummary = get_post_meta($post->ID, 'aptmicrodata_event_summary');
$eventLocation = get_post_meta($post->ID, 'aptmicrodata_event_location');
$eventStartDate = get_post_meta($post->ID, 'aptmicrodata_event_start_date');
$eventEndDate = get_post_meta($post->ID, 'aptmicrodata_event_end_date');
$eventType = get_post_meta($post->ID, 'aptmicrodata_event_type');
$dateReviewed = get_the_date('', $post->ID);
$dateReviewedFormated = get_the_date('Y-m-d', $post->ID);
$box = $aptmicrodata_box_top.'
'.$dateReviewedFormated.'
'.$eventSummary[0].' ';
if( $eventStartDate[0] != $eventEndDate[0]) {
$box .= '
—
';
} else {
$box .= '
';
}
$box .= '
'.$eventLocation[0].'
Category:
'.$eventType[0].'
';
if(current_user_can( 'manage_options' )) {
$box .= '
Test rich snippet';
}
$box .= "
$aptmicrodata_box_bottom";
return $box;
}
function aptmicrodata_build_music_box() {
global $post, $aptmicrodata_box_top, $aptmicrodata_box_bottom;
$musicName = get_post_meta($post->ID, 'aptmicrodata_music_name');
$musicSummary = get_post_meta($post->ID, 'aptmicrodata_music_summary');
$album = get_post_meta($post->ID, 'aptmicrodata_music_album');
//Tracks
$track1Name = get_post_meta($post->ID, 'aptmicrodata_music_track_1_name');
$track1Link = get_post_meta($post->ID, 'aptmicrodata_music_track_1');
$track1Duration = get_post_meta($post->ID, 'aptmicrodata_music_duration_1');
$track2Name = get_post_meta($post->ID, 'aptmicrodata_music_track_2_name');
$track2Link = get_post_meta($post->ID, 'aptmicrodata_music_track_2');
$track2Duration = get_post_meta($post->ID, 'aptmicrodata_music_duration_2');
$track3Name = get_post_meta($post->ID, 'aptmicrodata_music_track_3_name');
$track3Link = get_post_meta($post->ID, 'aptmicrodata_music_track_3');
$track3Duration = get_post_meta($post->ID, 'aptmicrodata_music_duration_3');
$track4Name = get_post_meta($post->ID, 'aptmicrodata_music_track_4_name');
$track4Link = get_post_meta($post->ID, 'aptmicrodata_music_track_4');
$track4Duration = get_post_meta($post->ID, 'aptmicrodata_music_duration_4');
$track5Name = get_post_meta($post->ID, 'aptmicrodata_music_track_5_name');
$track5Link = get_post_meta($post->ID, 'aptmicrodata_music_track_5');
$track5Duration = get_post_meta($post->ID, 'aptmicrodata_music_duration_5');
$track6Name = get_post_meta($post->ID, 'aptmicrodata_music_track_6_name');
$track6Link = get_post_meta($post->ID, 'aptmicrodata_music_track_6');
$track6Duration = get_post_meta($post->ID, 'aptmicrodata_music_duration_6');
$track7Name = get_post_meta($post->ID, 'aptmicrodata_music_track_7_name');
$track7Link = get_post_meta($post->ID, 'aptmicrodata_music_track_7');
$track7Duration = get_post_meta($post->ID, 'aptmicrodata_music_duration_7');
$track8Name = get_post_meta($post->ID, 'aptmicrodata_music_track_8_name');
$track8Link = get_post_meta($post->ID, 'aptmicrodata_music_track_8');
$track8Duration = get_post_meta($post->ID, 'aptmicrodata_music_duration_8');
$track9Name = get_post_meta($post->ID, 'aptmicrodata_music_track_9_name');
$track9Link = get_post_meta($post->ID, 'aptmicrodata_music_track_9');
$track9Duration = get_post_meta($post->ID, 'aptmicrodata_music_duration_9');
$track10Name = get_post_meta($post->ID, 'aptmicrodata_music_track_10_name');
$track10Link = get_post_meta($post->ID, 'aptmicrodata_music_track_10');
$track10Duration = get_post_meta($post->ID, 'aptmicrodata_music_duration_10');
$track11Name = get_post_meta($post->ID, 'aptmicrodata_music_track_11_name');
$track11Link = get_post_meta($post->ID, 'aptmicrodata_music_track_11');
$track11Duration = get_post_meta($post->ID, 'aptmicrodata_music_duration_11');
$track12Name = get_post_meta($post->ID, 'aptmicrodata_music_track_12_name');
$track12Link = get_post_meta($post->ID, 'aptmicrodata_music_track_12');
$track12Duration = get_post_meta($post->ID, 'aptmicrodata_music_duration_12');
$dateReviewed = get_the_date('', $post->ID);
$dateReviewedFormated = get_the_date('Y-m-d', $post->ID);
$box = $aptmicrodata_box_top.'
'.$musicName[0].' ';
if(!empty($track1Name) && !empty($track1Link)) {
$box .= '
';
$box .= 'Track name:
'.$track1Name[0].'';
$box .= 'Album:
'.$album.'';
$box .= 'Duration:
'.$track1Duration.'';
$box .= '
'.get_permalink($post->ID).'';
$box .= '
Play';
$box .= '
';
}
if(!empty($track2Name) && !empty($track2Link)) {
$box .= '
';
$box .= 'Track name:
'.$track2Name[0].'';
$box .= 'Album:
'.$album.'';
$box .= 'Duration:
'.$track2Duration.'';
$box .= '
'.get_permalink($post->ID).'';
$box .= '
Play';
$box .= '
';
}
if(!empty($track3Name) && !empty($track3Link)) {
$box .= '
';
$box .= 'Track name:
'.$track3Name[0].'';
$box .= 'Album:
'.$album.'';
$box .= 'Duration:
'.$track3Duration.'';
$box .= '
'.get_permalink($post->ID).'';
$box .= '
Play';
$box .= '
';
}
if(!empty($track4Name) && !empty($track4Link)) {
$box .= '
';
$box .= 'Track name:
'.$track4Name[0].'';
$box .= 'Album:
'.$album.'';
$box .= 'Duration:
'.$track4Duration.'';
$box .= '
'.get_permalink($post->ID).'';
$box .= '
Play';
$box .= '
';
}
if(!empty($track5Name) && !empty($track5Link)) {
$box .= '
';
$box .= 'Track name:
'.$track5Name[0].'';
$box .= 'Album:
'.$album.'';
$box .= 'Duration:
'.$track5Duration.'';
$box .= '
'.get_permalink($post->ID).'';
$box .= '
Play';
$box .= '
';
}
if(!empty($track6Name) && !empty($track6Link)) {
$box .= '
';
$box .= 'Track name:
'.$track6Name[0].'';
$box .= 'Album:
'.$album.'';
$box .= 'Duration:
'.$track6Duration.'';
$box .= '
'.get_permalink($post->ID).'';
$box .= '
Play';
$box .= '
';
}
if(!empty($track7Name) && !empty($track7Link)) {
$box .= '
';
$box .= 'Track name:
'.$track7Name[0].'';
$box .= 'Album:
'.$album.'';
$box .= 'Duration:
'.$track7Duration.'';
$box .= '
'.get_permalink($post->ID).'';
$box .= '
Play';
$box .= '
';
}
if(!empty($track8Name) && !empty($track8Link)) {
$box .= '
';
$box .= 'Track name:
'.$track8Name[0].'';
$box .= 'Album:
'.$album.'';
$box .= 'Duration:
'.$track8Duration.'';
$box .= '
'.get_permalink($post->ID).'';
$box .= '
Play';
$box .= '
';
}
if(!empty($track9Name) && !empty($track9Link)) {
$box .= '
';
$box .= 'Track name:
'.$track9Name[0].'';
$box .= 'Album:
'.$album.'';
$box .= 'Duration:
'.$track9Duration.'';
$box .= '
'.get_permalink($post->ID).'';
$box .= '
Play';
$box .= '
';
}
if(!empty($track10Name) && !empty($track10Link)) {
$box .= '
';
$box .= 'Track name:
'.$track10Name[0].'';
$box .= 'Album:
'.$album.'';
$box .= 'Duration:
'.$track10Duration.'';
$box .= '
'.get_permalink($post->ID).'';
$box .= '
Play';
$box .= '
';
}
if(!empty($track11Name) && !empty($track11Link)) {
$box .= '
';
$box .= 'Track name:
'.$track11Name[0].'';
$box .= 'Album:
'.$album.'';
$box .= 'Duration:
'.$track11Duration.'';
$box .= '
'.get_permalink($post->ID).'';
$box .= '
Play';
$box .= '
';
}
if(!empty($track12Name) && !empty($track12Link)) {
$box .= '
';
$box .= 'Track name:
'.$track12Name[0].'';
$box .= 'Album:
'.$album.'';
$box .= 'Duration:
'.$track12Duration.'';
$box .= '
'.get_permalink($post->ID).'';
$box .= '
Play';
$box .= '
';
}
if(current_user_can( 'manage_options' )) {
$box .= '
Test rich snippet';
}
$box .= "
$aptmicrodata_box_bottom";
return $box;
}
function aptmicrodata_style()
{
echo "";
}
add_action("wp_head", "aptmicrodata_style");
?>