Skip to content

Instantly share code, notes, and snippets.

@BruceMcKinnon
Created March 25, 2021 03:46
Show Gist options
  • Select an option

  • Save BruceMcKinnon/2c01c2139944b27fef28a5a3969c9535 to your computer and use it in GitHub Desktop.

Select an option

Save BruceMcKinnon/2c01c2139944b27fef28a5a3969c9535 to your computer and use it in GitHub Desktop.
Customise a SimpleLinks list and return as a table
//
// Hook the SimpleLinks plugin output.
// Puts the list into a table to match the site, which includes the post_date and a the 'Source' custom field
//
// Example shortcode call:
//
// [simple-links category="In the Press" fields="pub_date,source" orderby="date" order="DESC" count=5]
//
add_filter('simple_links__output', 'bl_link_out',10,3);
function bl_link_out($output, $links, $args ) {
if ($args['type'] == 'shortcode') {
if ( ( in_array('pub_date',$args['fields']) ) && ( in_array('source',$args['fields']) ) ) {
$new_out = '<table class="simple-links-list"><tbody>';
foreach( $links as $link) {
$link_meta = $link->meta;
$url = $link_meta['web_address'][0];
$target = $link_meta['target'][0];
$source = 'not found';
$custom_fields = unserialize($link_meta['link_additional_value'][0]);
if (array_key_exists('Source',$custom_fields)) {
$source = $custom_fields['Source'];
}
$new_out .= '<tr class="simple-links-item"><td>'.date('j F Y',strtotime($link->post_date)).'</td><td>'.$source.'</td><td><a href="'.$url.'" target="'.$target.'">'.$link->post_title.'</a></td></tr>';
}
$new_out .= '</tbody></table>';
$output = $new_out;
}
}
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment