Namaste! LMS provides handy shortcodes for displaying current course’s lessons and modules, and module’s lessons. You can even pass course or module ID to the shortcodes to display the modules or lessons that belong to another course / module. So far, so good, but how do you display this in the sidebar?
Installing the Widget Context Plugin
There is an excellent free plugin called Widget Context that takes care to display widgets only on selected post types. Install it and activate it. You’ll most likely want to display different widgets on the different types of pages. Also, you’ll probably not want to display these widgets on your regular non-LMS pages (contact & about pages, blog posts, etc).
Normally what you’ll want to display on a course page is the list of lessons in the course and/or (if you use modules) a list of modules in it. This can’t be easier:
- Create a text widget and place it in the sidebar.
- Insert the shortcode
- Select that this widget will be shown only on “Courses” pages (or maybe you want to use the same widget on your modules & lessons page – no problem, Namaste! LMS shortcodes are smart enough to figure out the lessons related to the course regardless if you are on the course page itself, or a module / lesson belonging to that course).
- Here’s an example:
You can see how this works in our demo.
On module pages you’ll probably want to show lessons in this module and modules in this course. Similar to the above:
- For “lessons in this module” use
- For “modules in this course” use
It’s probably not wise to include all lessons in the course but if you want to do it, just enable the widget from the previous example on “Module” pages as well.
On lesson pages you may want to show all lessons in this course, or if you use modules also the modules in this course, the lessons in this module.
- In our first example displaying all lessons in this course is already done and the same widget is enabled for “Lessons” posts. If you want to use different widget (or don’t show lessons on course pages) just use the shortcode
- To show modules in this course use
- To show lessons in the same module use
That’s it, quite simple. If you think other existing shortcode should have course / lesson / module relevant behavior let us know.
Do not use any of the shortcodes without ID attribute on archives or search results pages because the system won’t know which is the current post they relate to. Using the shortcodes without ID makes sense only on pages that show a single course, lesson or module.