Title: Scrolling notifications
Last modified: August 22, 2016

---

# Scrolling notifications

 *  [padsle](https://wordpress.org/support/users/padsle/)
 * (@padsle)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/scrolling-notifications/)
 * Hi, this is a nice plugin. I saw you were considering adding in the ability to
   scroll through notifications (the discussions are from about a year ago). Is 
   there a way of doing this now? If I add several notifications per day to my site
   I don’t want each one to be replaced when I write a new one – I’d like users 
   to be able to see all the recent notifications, or maybe even just the notifications
   that have occurred since they last logged in.
    Thanks,
 * [https://wordpress.org/plugins/notifications/](https://wordpress.org/plugins/notifications/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Chris Reynolds](https://wordpress.org/support/users/jazzs3quence/)
 * (@jazzs3quence)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/scrolling-notifications/#post-5606801)
 * You can definitely do this now. However, where it gets tricky is how you handle“
   pagination”. If the notification is still showing 1 at a time (e.g. `'posts_per_page'
   => 1`), then the pagination could conflict with the main loop’s pagination (e.
   g. if it was on a blog index). Alternately, you could sort of fake the pagination
   and pre-load _x_ number of posts and then have some other way to navigate through
   them (maybe there’s some javascript scroll thing, or maybe there’s a button that
   you can click to see the next notification).
 * Instead of using the template tag in your code, what you’d need to do is run 
   through a custom loop of notification posts (however many you would like to display),
   and then deal with the “paginiation” (going from one notification to the next)
   however you want to handle that.
    Your loop might be something like this:
 *     ```
       $notifications = new WP_Query( array(
            'post_type' => 'notf_notifications',
            'posts_per_page' => 5, // assuming you have some way of navigating to the next post, change this to however many posts you want to display
            'post_status' => 'publish'
       ) );
   
       if ( $notifications->have_posts() ) : while ( $notifications->have_posts() ) : $notifications->the_post(); ?>
   
            <div class="notification your-style"><?php echo notf_message(); ?></div>
   
       <?php endwhile; endif; ?>
       ```
   
 *  Thread Starter [padsle](https://wordpress.org/support/users/padsle/)
 * (@padsle)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/scrolling-notifications/#post-5606867)
 * Thanks for the suggestion. I’m new to coding – should I be in the notifications/
   notifications.php and should I replace the section below with the code you’ve
   noted above, or should I add the new code, keeping the below?
 * Thanks,
 *     ```
       /**
        * Notification message
        * @since 1.0
        * @uses get_posts
        * @author Chris Reynolds
        * returns the most recent notification
        */
       function notf_message() {
       	$args = array(
       		'post_type' => 'notf_notifications',
       		'posts_per_page' => 1,
       		);
       	$notifications = get_posts( $args );
       	foreach ( $notifications as $notification ) {
       		$notf_id = $notification->ID;
       		$message = get_the_title( $notf_id );
       	}
       	if ( $notifications ) {
       		return $message;
       	}
       }
       ```
   
 *  Plugin Author [Chris Reynolds](https://wordpress.org/support/users/jazzs3quence/)
 * (@jazzs3quence)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/scrolling-notifications/#post-5606868)
 * No, you absolutely _never_ modify the code in the plugin. If you do, and I release
   an update, and you update to the latest version, your custom code is gone and
   can’t be recovered.
 * Besides which, presentational code should not be in plugins _anyway_, that is
   the territory of _themes_. So in your custom theme or child theme, you might 
   create a function that uses the code I posted above or, if you really needed 
   to, you could put that code in your header.php or wherever the notification was
   going to display (putting it in a function is better practice, though, as template
   files should mostly be for the markup that displays the content on the page with
   very little actual code in them, other than template tags).
 * Keep in mind, though, that the code I posted is untested and just a suggestion
   for displaying multiple notifications on a single page (and I noticed an error
   in my code snippet — you wouldn’t use `notf_message` because that would just 
   return a single notification — you would want to use `the_title()`). My suggestion
   doesn’t take care of the scrolling functionality — that would need to be added
   separately.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Scrolling notifications’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/notifications_ffffff.svg)
 * [Notifications](https://wordpress.org/plugins/notifications/)
 * [Support Threads](https://wordpress.org/support/plugin/notifications/)
 * [Active Topics](https://wordpress.org/support/plugin/notifications/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/notifications/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/notifications/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Chris Reynolds](https://wordpress.org/support/users/jazzs3quence/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/scrolling-notifications/#post-5606868)
 * Status: not resolved