Below, you’ll find a detailed guide on how to add the News Announcement Scroll Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the News Announcement Scroll Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the News Announcement Scroll Plugin and the shortcodes it provides:
"News Announcement Scroll is a dynamic WordPress plugin designed to display updates or news in an appealing scrolling format. Ideal for site-wide announcements, posts, and latest news."
- [news-announcement]
News Announcement Scroll [news-announcement] Shortcode
The News-Announcement-Scroll shortcode allows you to create a news announcement on your website. It fetches data from the WP_G_NEWS_ANNOUNCEMENT table, where the status of the news is set to ‘Yes’ and the news date is either current or not set. The shortcode also provides customization options for the announcement like font, font size, color, alignment, and slide direction. If there’s a redirect link provided, it wraps the news text with it.
Shortcode: [news-announcement]
Examples and Usage
Basic example – Displaying news announcement without any group parameter.
[news-announcement /]
Advanced examples
Displaying news announcement with a specific group parameter. This will only display news announcements from the specified group.
[news-announcement group="general" /]
Displaying news announcement with multiple group parameters. This will display news announcements from all the specified groups.
[news-announcement group="general,sports,technology" /]
Displaying news announcement with a specific group and order. This will display news announcements from the specified group and in the specified order.
[news-announcement group="general" order="desc" /]
Displaying news announcement with a specific group, order, and limit. This will display a certain number of news announcements from the specified group and in the specified order.
[news-announcement group="general" order="desc" limit="5" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [news-announcement]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'news-announcement', 'news_shortcode' );
Shortcode PHP function:
function news_shortcode( $atts ) {
global $wpdb;
wp_register_script( 'nas_gannounce', NAS_URL . 'gAnnounce/gAnnounce.js', array( 'jquery' ) );
wp_enqueue_script( 'nas_gannounce' );
$nas = '';
$Ann = '';
if ( ! is_array( $atts ) ) {
return '';
}
$gNewsAnnouncementtype = ! empty( $atts['group'] ) ? esc_sql( $atts['group'] ) : '';
$gNewsAnnouncementorder = get_option( 'gNewsAnnouncementorder' );
$sSql = $wpdb->prepare(
"SELECT * FROM " . WP_G_NEWS_ANNOUNCEMENT . "
WHERE gNews_status = %s
AND (`gNews_date` <= NOW() OR `gNews_date` = %s)
AND (`gNews_expiration` >= NOW() OR `gNews_expiration` = %s)
" . ($gNewsAnnouncementtype ? "AND `gNews_type` = '{$gNewsAnnouncementtype}'" : '') . "
ORDER BY " . ('1' == $gNewsAnnouncementorder ? 'RAND()' : 'gNews_order'),
'Yes',
'0000-00-00',
'0000-00-00'
);
$data = $wpdb->get_results($sSql);
$nas = $nas . '<script language="JavaScript" type="text/javascript">';
$nas = $nas . 'v_font="' . get_option( 'gNewsAnnouncementfont' ) . '"; ';
$nas = $nas . 'v_fontSize="' . get_option( 'gNewsAnnouncementfontsize' ) . '"; ';
$nas = $nas . 'v_fontSizeNS4="' . get_option( 'gNewsAnnouncementfontsize' ) . '"; ';
$nas = $nas . 'v_fontWeight="' . get_option( 'gNewsAnnouncementfontweight' ) . '"; ';
$nas = $nas . 'v_fontColor="' . get_option( 'gNewsAnnouncementfontcolor' ) . '"; ';
$nas = $nas . 'v_textDecoration="none"; ';
$nas = $nas . 'v_fontColorHover="#FFFFFF"; ';
$nas = $nas . 'v_textDecorationHover="none"; ';
$nas = $nas . 'v_top=0;';
$nas = $nas . 'v_left=0;';
$nas = $nas . 'v_width=' . get_option( 'gNewsAnnouncementwidth' ) . '; ';
$nas = $nas . 'v_height=' . get_option( 'gNewsAnnouncementheight' ) . '; ';
$nas = $nas . 'v_paddingTop=0; ';
$nas = $nas . 'v_paddingLeft=0; ';
$nas = $nas . 'v_position="relative"; ';
$nas = $nas . 'v_timeout=' . get_option( 'gNewsAnnouncementslidetimeout' ) . '; ';
$nas = $nas . 'v_slideSpeed=1;';
$nas = $nas . 'v_slideDirection=' . get_option( 'gNewsAnnouncementslidedirection' ) . '; ';
$nas = $nas . 'v_pauseOnMouseOver=true; ';
$nas = $nas . 'v_slideStep=1; ';
$nas = $nas . 'v_textAlign="' . get_option( 'gNewsAnnouncementtextalign' ) . '"; ';
$nas = $nas . 'v_textVAlign="' . get_option( 'gNewsAnnouncementtextvalign' ) . '"; ';
$nas = $nas . 'v_bgColor="transparent"; ';
$nas = $nas . '</script>';
if ( ! empty( $data ) ) {
foreach ( $data as $data ) {
if ( ! empty( $data->gnews_redirect_link ) ) {
$data->gNews_text = '<a href="' . $data->gnews_redirect_link . '" style="color:inherit;text-decoration:underline;font-weight:inherit" target="_blank">' . $data->gNews_text . '</a>';
}
$Ann = $Ann . "['','" . $data->gNews_text . "',''],";
}
$Ann = substr( $Ann, 0, ( strlen( $Ann ) - 1 ) );
$nas = $nas . '<div id="display_news" style="padding-bottom:5px;padding-top:5px;">';
$nas = $nas . '<script language="JavaScript" type="text/javascript">';
$nas = $nas . 'v_content=[' . $Ann . ']';
$nas = $nas . '</script>';
$nas = $nas . '</div>';
} else {
?>
<div id="display_news">
<script language="JavaScript" type="text/javascript">
v_content=[['','<?php echo get_option( 'gNewsAnnouncementnoannouncement' ); ?>',''],['','<?php echo get_option( 'gNewsAnnouncementnoannouncement' ); ?>','']]
</script>
</div>
<?php
}
return $nas;
}
Code file location:
news-announcement-scroll/news-announcement-scroll/news-announcement-scroll.php
Conclusion
Now that you’ve learned how to embed the News Announcement Scroll Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply