• Dear Support,

    i try to add a text after the title in every couse in a Category list.

    <h3 class="course-title"><?php the_title(); ?> 
    <?php
    $course_id = get_the_ID();
    $tage = array("So. ", "Mo. ", "Di. ", "Mi. ", "Do. ", "Fr. ", "Sa. ");
    date_default_timezone_set("Europe/Berlin");
    $tag = date("w", strtotime(get_post_meta($course_id, "_lp_course_startdate")[0]));

    echo ( $tage[$tag] . date('d.m.Y', strtotime(get_post_meta($course_id, "_lp_course_startdate")[0])). " ab ". date('H:i', strtotime(get_post_meta($course_id, "_lp_course_startdate")[0])) );
    ?></h3>

    I have overwritten the wp-content\plugins\learnpress\templates\loop\course\title.php with wp-content\themes\generatepress_child\learnpress\loop\course\title.php

    And I Use the filter in the functions.php

    add_filter( 'learn-press/override-templates', function(){ return true; } ); 

    I have also tried to write in the wp-content\plugins\learnpress\templates\loop\course\title.php directly but the code will not be called.

    What can I do?

    Best regards

    Collie-IT

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support brianvu-tp

    (@briantp)

    Dear Collie-IT,

    Thank you for reaching out.

    Please try changing the override path in your child theme to include the version directory, learnpress-v4:

    • Current Path (likely incorrect):
      wp-content/themes/generatepress_child/learnpress/loop/course/title.php
    • Suggested New Path:
      wp-content/themes/generatepress_child/learnpress-v4/loop/course/title.php

    If the issue persists, could you please provide a screenshot of the exact area on the course list page where you want the custom date/time to appear? Seeing the context will help us identify the precise template file you need to override.

    Let us know the result of changing the template path!

    Best regards,
    Brianvu-tp

    Thread Starter Collie-IT, Anne K. Frey

    (@collieit)

    Dear Supprt,

    here is the image. Suddently it has no effect.

    Best regards

    Collie-IT

    Plugin Support brianvu-tp

    (@briantp)

    Hi Collie-IT,

    Thank you for your reply and for providing the screenshot.

    To modify that specific section, you can use the following hook:

    apply_filters( 'learn-press/layout/list-courses/item/section/bottom', '…' );

    This hook is located in:
    wp-content/plugins/learnpress/inc/TemplateHooks/Course/ListCoursesTemplate.php

    You can apply your custom code through this filter in your child theme to achieve the desired customization.

    Best regards,
    Brianvu-tp

    Thread Starter Collie-IT, Anne K. Frey

    (@collieit)

    Dear Support,

    unfurtunatly if I use

    apply_filters( 'learn-press/layout/list-courses/item/section/bottom', '…' );

    I don’t get the cursespecifc inputs. with paramaters are needed for the function?

    Best Regards

    Collie-IT

    Plugin Support brianvu-tp

    (@briantp)

    Dear Collie-IT,

    Thank you for the quick follow-up!

    Here is an example function you can place in your child theme’s functions.php file. This code display your course start date directly below the title in the course list:

    add_filter( 'learn-press/layout/list-courses/item/section/bottom', function( $components, $course, $settings ) {
    if ( ! is_array( $components ) || empty( $components['title'] ) ) {
    return $components;
    }

    // Get course ID
    $course_id = method_exists( $course, 'get_id' ) ? $course->get_id() : get_the_ID();

    // Build display string using LearnPress user item start_time, formatted like: "Mo. 01.01.2025 ab 10:00"
    $dateStr = ' - ';
    $user_id = get_current_user_id();
    if ( $user_id ) {
    $userCourseModel = \LearnPress\Models\UserItems\UserCourseModel::find( (int) $user_id, (int) $course_id, true );
    if ( $userCourseModel instanceof \LearnPress\Models\UserItems\UserCourseModel ) {
    $start_time = $userCourseModel->get_start_time();
    if ( ! empty( $start_time ) ) {
    try {
    $tage = array( 'So. ', 'Mo. ', 'Di. ', 'Mi. ', 'Do. ', 'Fr. ', 'Sa. ' );
    $tz = new \DateTimeZone( 'Europe/Berlin' );
    // start_time is stored in UTC format (string), convert to Europe/Berlin
    $dt = new \DateTime( $start_time, new \DateTimeZone( 'UTC' ) );
    $dt->setTimezone( $tz );
    $weekdayIndex = (int) $dt->format( 'w' );
    $prefix = isset( $tage[ $weekdayIndex ] ) ? $tage[ $weekdayIndex ] : '';
    $dateStr = $prefix . $dt->format( 'd.m.Y' ) . ' ab ' . $dt->format( 'H:i' );
    } catch ( \Exception $e ) {
    $dateStr = ' - ';
    }
    }
    }
    }

    // Insert before closing heading tag; fallback to append at the end
    $closing_tags = array( '</h1>', '</h2>', '</h3>', '</h4>', '</h5>', '</h6>' );
    $inserted = false;
    foreach ( $closing_tags as $closing ) {
    if ( strpos( $components['title'], $closing ) !== false ) {
    $components['title'] = str_replace(
    $closing,
    ' <span class="course-start">' . esc_html( $dateStr ) . '</span>' . $closing,
    $components['title']
    );
    $inserted = true;
    break;
    }
    }
    if ( ! $inserted ) {
    $components['title'] .= ' <span class="course-start">' . esc_html( $dateStr ) . '</span>';
    }

    return $components;
    }, 10, 3 );

    Let me know if this works!

    Best regards,
    Brianvu-tp

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Loop Template not called’ is closed to new replies.