Created
August 17, 2012 20:23
-
-
Save norcross/3382312 to your computer and use it in GitHub Desktop.
MailChimp Campaign List
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
function mc_campaign_content($cid) { | |
$apikey = 'APIKEY'; | |
$method = 'campaignContent'; | |
$archive = 'true'; | |
$request = new WP_Http; | |
$url = 'http://<dc>.api.mailchimp.com/1.3/?method='.$method.'&apikey='.$apikey.'&cid='.$cid.'&for_archive='.$archive.'&output=json'; | |
$response = wp_remote_get ( $url ); | |
if( is_wp_error( $response ) ) { | |
$error = '<p>Sorry, there was an error with your request.</p>'; | |
return $error; | |
} else { | |
$return = $response['body']; | |
$camp_data = json_decode($return); | |
} | |
return $camp_data; | |
} | |
$apikey = 'APIKEY'; | |
$method = 'campaigns'; | |
$limit = '5'; | |
$request = new WP_Http; | |
$url = 'http://<dc>.api.mailchimp.com/1.3/?method='.$method.'&apikey='.$apikey.'&limit='.$limit.'&output=json'; | |
$response = wp_remote_get ( $url ); | |
// check for bad response | |
if( is_wp_error( $response ) ) { | |
$error = '<p>Sorry, there was an error with your request.</p>'; | |
return $error; | |
} else { | |
$return = $response['body']; | |
$mail_data = json_decode($return); | |
} | |
$mail_read = $mail_data->data; | |
foreach ($mail_read as $mail) { | |
$title = $mail->subject; | |
$link = $mail->archive_url; | |
echo '<p><a href="'.$link.'" title="'.$title.'" target="_blank">'.$title.'</a></p>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment