diff --git a/mod/forum/lib.php b/mod/forum/lib.php index fe088133ac1..ed16ec9aa14 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -3078,6 +3078,9 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa // String cache static $str; + // As we should only have one element with the id of unread we keep track of whether this post is the first + // unread post. + static $firstunread = true; $modcontext = context_module::instance($cm->id); @@ -3293,7 +3296,11 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa $forumpostclass = ' read'; } else { $forumpostclass = ' unread'; - $output .= html_writer::tag('a', '', array('name'=>'unread')); + // If this is the first unread post then give it an anchor and id of unread. + if ($firstunread) { + $output .= html_writer::tag('a', '', array('id' => 'unread')); + $firstunread = false; + } } } else { // ignore trackign status if not tracked or tracked param missing