Last active
December 13, 2017 15:55
-
-
Save paullacey78/5da90649002f4fba89466ba6023a2727 to your computer and use it in GitHub Desktop.
Notices shortcode (SMITF)
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
// 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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment