• Resolved John

    (@artoftech)


    As a final bit of functionality for the course archive I need to add the tag I’m now sorting on (See https://ww.wp.xz.cn/support/topic/add-to-archive-sorting/) in the top section as well as a custom field. Here is how I accomplished it straight in the code of wp-content/plugins/learnpress/inc/TemplateHooks/Course/ListCoursesTemplate.php:

    $html_categories = $singleCourseTemplate->html_categories( $course );
    >>$html_tags = $singleCourseTemplate->html_tags( $course );
    if ( ! empty( $html_categories) && ! empty( $html_tags ) ) {
    $html_categories = sprintf(
    '<div>%s %s %s</div>',
    $html_categories,
    >>'<span class="course-tags">- </span>',
    >>$html_tags
    );
    }
    >>$custom_field = get_post_meta( $course->get_id(), 'lp_alt_title', true);
    >>if($custom_field != '') {
    >> $alt_title = sprintf(
    >> '<div class="all-courses-alt-title">%s%s%s</div>',
    >> "(",
    >> $custom_field,
    >> ")"
    >> );
    >>}

    $section_bottom = apply_filters(
    'learn-press/layout/list-courses/item/section/bottom',
    [
    'wrapper' => '<div class="course-content">',
    'title' => sprintf(
    '<a class="course-permalink" href="%s">%s</a>',
    $course->get_permalink(),
    $singleCourseTemplate->html_title( $course )
    ),
    >>'alt_title' => $alt_title,
    'wrapper_instructor_cate' => '<div class="course-instructor-category">',
    'instructor' => sprintf(
    '<div>%s %s</div>',
    sprintf( '<label>%s</label>', __( 'by', 'learnpress' ) ),
    $singleCourseTemplate->html_instructor( $course )
    ),
    'category' => $html_categories,
    'wrapper_instructor_cate_end' => '</div>',
    'meta' => $html_meta_data,
    'info' => Template::combine_components( $section_bottom_end ),
    'wrapper_end' => '</div>',
    ],
    $course,
    $settings
    );

    where >> indicates my changes. I know this should be done with a filter hook, but this has no effect:

    add_filter('learn-press/layout/list-courses/section/bottom', function($section_bottom, $courses, $settings) {
    $singleCourseTemplate = LearnPress\TemplateHooks\Course\ListCoursesTemplate::instance();
    $html_categories = $singleCourseTemplate->html_categories( $course );
    $html_tags = $singleCourseTemplate->html_tags( $course );
    if ( ! empty( $html_tags ) ) {
    $html_categories = sprintf(
    '<div>%s %s %s</div>',
    $html_categories,
    '<span class="course-tags">- </span>',
    $html_tags
    );
    }
    $custom_field = get_post_meta( $course->get_id(), 'lp_alt_title', true);
    if($custom_field != '') {
    $alt_title = sprintf(
    '<div class="all-courses-alt-title">%s%s%s</div>',
    "(",
    $custom_field,
    ")"
    );
    }
    $section_bottom['alt_title'] = $alt_title;
    $section_bottom['html_categories'] = $html_categories;
    return $section_bottom;
    }, 10, 3);

    So that it doesn’t get overwritten, how would I implement these additions using the add filter?
    I hope that makes sense…

    Thank you very much in advance,

    John

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter John

    (@artoftech)

    Hi, I corrected a few things and got this to work:

    add_filter('learn-press/layout/list-courses/item/section/bottom', function($section_bottom, $course, $settings) {
    $html_tags = $course->tags[0]->name; //since we only have one tag don't need to loop the array
    if ( ! empty( $html_tags ) ) {
    $html_tags = sprintf(
    '<div>%s</div>',
    $html_tags
    );
    }
    $custom_field = get_post_meta( $course->get_id(), 'lp_alt_title', true);
    if($custom_field != '') {
    $alt_title = sprintf(
    '<div class="all-courses-alt-title">%s%s%s</div>',
    "(",
    $custom_field,
    ")"
    );
    }
    array_splice($section_bottom, 2, 0, $alt_title);
    array_splice($section_bottom, 6, 0, $html_tags);
    return $section_bottom;
    }, 10, 3);
    Plugin Support brianvu-tp

    (@briantp)

    Hi John,

    Thank you for sharing your solution and for your effort in refining it! We’re glad to hear that you’ve got it working.

    If you have any further questions or need additional support, feel free to reach out. We’re happy to assist!

    Best regards,
    Brianvu-tp

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

The topic ‘Course Archive – section top mods’ is closed to new replies.