Notices shortcode (SMITF)
// Notices Shortcode
// Example usage using a page ID containing the repeater field (could be changed to get the current page ID): [notices id="77"]
function notices_shortcode($atts)
{
// Attributes
$atts = shortcode_atts(array(
'id' => '0',
) , $atts);
$notices_page = $atts['id'];
$notices_url = get_permalink($atts['id']);
// check for notices
if (have_rows('notices', $notices_page)):
// loop through the notices
while (have_rows('notices', $notices_page)):
the_row();
// vars
$notice_title = get_sub_field('notice_title');
$notice_excerpt = get_sub_field('notice_excerpt');
$notices_output.= ('<h5>' . $notice_title . '</h5>');
$notices_output.= ('<p>' . $notice_excerpt . ' <a href="' . $notices_url . '">More ></a></p>');
endwhile;
$notices_output.= '<p><a href="' . $notices_url . '">All News & Notices ></a></p>';
return $notices_output;
else:
// no days
endif;
}
add_shortcode('notices', 'notices_shortcode');