Skip to content

Commit

Permalink
Merge pull request #2439 from actuallyakash/issues/2434
Browse files Browse the repository at this point in the history
Showing number of lessons in Course Catalog and My Courses.
  • Loading branch information
eri-trabiccolo authored Oct 26, 2023
2 parents 195e336 + 04746fe commit 4a114e7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changelogs/issues_2434.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
significance: minor
type: added
links:
- "#2434"
entry: Added a paragraph to show Number of lessons in a course at Course Catalog
and My Courses.
20 changes: 18 additions & 2 deletions includes/functions/llms.functions.templates.loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package LifterLMS/Functions
*
* @since 1.0.0
* @version 7.3.0
* @version [version]
*/

defined( 'ABSPATH' ) || exit;
Expand Down Expand Up @@ -37,7 +37,7 @@ function lifterlms_archive_description() {
* Adjusted filter `llms_archive_description` to always run instead of only running if content exists to display,
* this allows developers to filter the content even when an empty string is returned.
* @since 7.3.0 Fixed PHP Warning when no course/membership catalog page was set or if the
* selected page doesn't exist anymore.
* selected page doesn't exist anymore.
*
* @return string
*/
Expand Down Expand Up @@ -348,6 +348,22 @@ function lifterlms_template_loop_difficulty() {
}
}

/**
* Count of total lessons in a course.
*
* @since [version]
*
* @return void.
*/
if ( ! function_exists( 'lifterlms_template_loop_lesson_count' ) ) {

function lifterlms_template_loop_lesson_count() {
if ( 'course' === get_post_type( get_the_ID() ) ) {
llms_get_template( 'course/lesson-count.php' );
}
}
}

/**
* Show enrollment date meta
* used on Dashboard only
Expand Down
3 changes: 2 additions & 1 deletion includes/llms.template.hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @package LifterLMS/Hooks
*
* @since 1.0.0
* @version 6.0.0
* @version [version]
*/

defined( 'ABSPATH' ) || exit;
Expand Down Expand Up @@ -79,6 +79,7 @@
add_action( 'lifterlms_after_loop_item_title', 'lifterlms_template_loop_author', 10 );
add_action( 'lifterlms_after_loop_item_title', 'lifterlms_template_loop_length', 15 );
add_action( 'lifterlms_after_loop_item_title', 'lifterlms_template_loop_difficulty', 20 );
add_action( 'lifterlms_after_loop_item_title', 'lifterlms_template_loop_lesson_count', 22 );

add_action( 'lifterlms_after_loop_item', 'lifterlms_loop_link_end', 5 );

Expand Down
1 change: 0 additions & 1 deletion templates/course/length.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
<div class="llms-meta llms-course-length">
<p><?php printf( __( 'Estimated Time: <span class="length">%s</span>', 'lifterlms' ), $course->get( 'length' ) ); ?></p>
</div>

26 changes: 26 additions & 0 deletions templates/course/lesson-count.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Template: Lessons count in a Course.
*
* @package LifterLMS/Templates/Course
*
* @since [version]
* @version [version]
*/

defined( 'ABSPATH' ) || exit;

global $post;

$course = new LLMS_Course( $post );
$lessons_count = $course->get_lessons_count();
?>

<div class="llms-meta llms-lessons-count">
<p>
<?php
// Translators: %1$s = Lessons Count.
printf( esc_html__( 'Number of lessons: %1$s', 'lifterlms' ), '<span class="lessons-count">' . $lessons_count . '</span>' );
?>
</p>
</div>
7 changes: 4 additions & 3 deletions templates/loop/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* The Template for displaying all single courses.
*
* @package LifterLMS/Templates
* @package LifterLMS/Templates
*
* @since 1.0.0
* @version 3.14.0
* @since 1.0.0
* @version 3.14.0
*/

defined( 'ABSPATH' ) || exit;
Expand Down Expand Up @@ -43,6 +43,7 @@
* @hooked lifterlms_template_loop_author - 10
* @hooked lifterlms_template_loop_length - 15
* @hooked lifterlms_template_loop_difficulty - 20
* @hooked lifterlms_template_loop_lesson_count - 22
*
* On Student Dashboard & "Mine" Courses Shortcode
* @hooked lifterlms_template_loop_enroll_status - 25
Expand Down

0 comments on commit 4a114e7

Please sign in to comment.