Test event
January 21, 2015 @ 8:00 am - 5:00 pm
<?php require(‘simple_html_dom.php‘); |
|
|
|
function generate_newsletter_archives($atts, $content = null) { |
|
|
|
// setup the beginning of our data table for archives |
|
$out = ‘<table cellpadding=”0″ cellspacing=”0″ id=”newsletter-archives”><tr><th>Resource</th><th>Date</th></tr><tbody>‘; |
|
|
|
// fetch the page which contains all of the newsletter issues that have been archived |
|
$archive_page = str_get_html(wp_remote_retrieve_body(wp_remote_get(‘http://archive.constantcontact.com/fs127/1103640951068/archive/1111407854121.html‘))); |
|
|
|
// fetch third table on page which contains the archives |
|
$archive_table = $archive_page->find(‘table‘, 2); |
|
|
|
// the nested search is required because some list elements contain data other than what we want |
|
foreach($archive_table->find(‘li‘) as $archived_item) { |
|
|
|
// extract the URL and title of each archived issue |
|
foreach($archived_item->find(‘a‘) as $archived_link) { |
|
$issue_link = $archived_link->href . “\n\n“; |
|
$issue_name = $archived_link->innertext . “\n\n“; |
|
} |
|
|
|
// extract the date for each archived issue |
|
foreach($archived_item->find(‘span‘) as $archived_item_date) { |
|
$issue_date = str_replace(‘(‘, ‘‘, $archived_item_date->innertext); |
|
$issue_date = str_replace(‘)‘, ‘‘, $issue_date) . “\n\n“; |
|
|
|
// build the string for each table row – one issue per row |
|
$out .= ‘<tr><td><a href=”‘.trim($issue_link).‘” target=”_blank”>‘.trim($issue_name).‘</a></td><td>‘.trim($issue_date).‘</td></tr>‘; |
|
} |
|
|
|
} |
|
|
|
// append the end of the table |
|
$out .= ‘<tr><td colspan=”2″></td></tr></tbody></table>‘; |
|
|
|
return $out; |
|
} |
|
add_shortcode(‘newsletter_archives‘, ‘generate_newsletter_archives‘); |
|
|
|
?> |