public function tagged_courses($tagid, $exclusivemode = true, $ctx = 0, $rec = true, $displayoptions = null) {
        global $CFG;
        if (empty($displayoptions)) {
            $displayoptions = array();
        }
        $showcategories = !core_course_category::is_simple_site();
        $displayoptions += array('limit' => $CFG->coursesperpage, 'offset' => 0);
        $chelper = new coursecat_helper();
        $searchcriteria = array('tagid' => $tagid, 'ctx' => $ctx, 'rec' => $rec);
        $chelper->set_show_courses($showcategories ? self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT :
                    self::COURSECAT_SHOW_COURSES_EXPANDED)->
                set_search_criteria($searchcriteria)->
                set_courses_display_options($displayoptions)->
                set_attributes(array('class' => 'course-search-result course-search-result-tagid'));
                // (we set the same css class as in search results by tagid)
        if ($totalcount = core_course_category::search_courses_count($searchcriteria)) {
            $courses = core_course_category::search_courses($searchcriteria, $chelper->get_courses_display_options());
            if ($exclusivemode) {
                return $this->coursecat_courses($chelper, $courses, $totalcount);
            } else {
                $tagfeed = new core_tag\output\tagfeed();
                $img = $this->output->pix_icon('i/course', '');
                foreach ($courses as $course) {
                    $url = course_get_url($course);
                    $imgwithlink = html_writer::link($url, $img);
                    $coursename = html_writer::link($url, $course->get_formatted_name());
                    $details = '';
                    if ($showcategories && ($cat = core_course_category::get($course->category, IGNORE_MISSING))) {
                        $details = get_string('category').': '.
                                html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)),
                                        $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed'));
                    }
                    $tagfeed->add($imgwithlink, $coursename, $details);
                }
                return $this->output->render_from_template('core_tag/tagfeed', $tagfeed->export_for_template($this->output));
            }
        }
        return '';
    }