I need to show all moodle courses in menu listing. Can anyone suggest me that how can I get all courses using php code or moodle inbuilt functions.
Thanks
The block title shows as "My courses" and allows one-click access to a course's home page. There is a also the option to list All courses... available within the Moodle site. This will display a list of course types and a click on one of the types will reveal all the courses in that category.
There are several reasons why your course might not be showing in Moodle. Your instructor has not set the course to 'Visible' yet. All courses are hidden by default.
To access an archived course, click on the link within the Kiosk. To view all courses, click "Show all X courses" where X is the number of hidden courses. Any gray links indicate courses that are hidden from student view.
Assuming you are writing code to be run within Moodle, you can use the get_courses()
function defined within lib/datalib.php
. For example:
<?php
require_once(PATH_TO_MOODLE_ROOT . '/config.php');
$courses = get_courses();
print_r($courses);
will print out a data-dump of the returned array, showing details of all the courses in your Moodle site. This example is obviously not appropriate to use on a production site!
If you check the function definition in lib/datalib.php
you will see the options available for restricting the result set to particular fields or controlling the sort order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With