Skip to content

Instantly share code, notes, and snippets.

@norcross
Created August 17, 2012 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norcross/3382312 to your computer and use it in GitHub Desktop.
Save norcross/3382312 to your computer and use it in GitHub Desktop.
MailChimp Campaign List
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