is_main_query() ) :
return;
endif;
if ( isset( $_GET['ldauthor'] ) ) :
$ldauthor = $_GET['ldauthor'];
else :
$ldauthor = false;
endif;
if ( is_author() && ( 'true' == $ldauthor ) && ( true == $author_redirect_to_courses ) ) :
$query->set( 'post_type', array( 'sfwd-courses' ) );
endif;
}
endif;
/**
* LearnDash specific scripts & stylesheets.
*
* @return void
*
* @since 1.0.0
*/
if ( ! function_exists( 'upstudy_ld_scripts' ) ) :
function upstudy_ld_scripts() {
wp_enqueue_style( 'upstudy-ld-style', get_template_directory_uri() . '/assets/css/learndash.css', array(), UPSTUDY_THEME_VERSION );
if ( is_singular( 'sfwd-courses' ) ) :
wp_enqueue_style( 'jquery-fancybox' );
wp_enqueue_script( 'jquery-fancybox' );
endif;
}
endif;
add_action( 'wp_enqueue_scripts', 'upstudy_ld_scripts' );
/**
* post_class extends for learndash courses
*
* @since 1.0.0
*/
if ( ! function_exists( 'upstudy_ld_course_class' ) ) :
function upstudy_ld_course_class( $default = array() ) {
$terms = get_the_terms( get_the_ID(), 'ld_course_category' );
$terms_html = array();
if ( is_array( $terms ) ) :
foreach ( $terms as $term ) :
$terms_html[] = $term->slug;
endforeach;
endif;
$all_classes = array_merge( $terms_html, $default );
$classes = apply_filters( 'upstudy_ld_course_class', $all_classes );
post_class( $classes );
}
endif;
/**
* Content area class
*/
add_filter( 'upstudy_content_area_class', 'upstudy_ld_content_area_class' );
if ( ! function_exists( 'upstudy_ld_content_area_class' ) ) :
function upstudy_ld_content_area_class ( $class ) {
if ( is_post_type_archive( 'sfwd-courses' ) || is_tax( 'ld_course_category' ) || is_tax( 'ld_course_tag' ) ) :
$course_layout = 'full_width';
if ( 'right' === $course_layout ) :
$class = 'upstudy-col-lg-9';
elseif ( 'left' === $course_layout ) :
$class = 'upstudy-col-lg-9 upstudy-order-1';
elseif ( 'full_width' === $course_layout ) :
$class = 'upstudy-col-lg-12';
endif;
endif;
if ( is_singular( 'sfwd-courses' ) ) :
$single_course_layout = 'full_width';
if ( 'right' === $single_course_layout ) :
$class = 'upstudy-col-lg-9';
elseif ( 'left' === $single_course_layout ) :
$class = 'upstudy-col-lg-9 upstudy-order-1';
elseif ( 'full_width' === $single_course_layout ) :
$class = 'upstudy-col-lg-12';
endif;
endif;
return $class;
}
endif;
/**
* Content area class for Author( As Instructor ) Archive
*/
add_filter( 'upstudy_content_area_class', 'upstudy_ld_author_archive_content_area_class' );
if ( ! function_exists( 'upstudy_ld_author_archive_content_area_class' ) ) :
function upstudy_ld_author_archive_content_area_class ( $class ) {
$author_redirect_to_courses = apply_filters( 'upstudy_ld_author_redirect_to_course', false );
if ( isset( $_GET['ldauthor'] ) ) :
$ldauthor = $_GET['ldauthor'];
else :
$ldauthor = false;
endif;
if ( true == $author_redirect_to_courses && 'true' == $ldauthor ) :
$class = 'upstudy-col-lg-12';
endif;
return $class;
}
endif;
/**
* Archive & Single Sidebar Type
*/
add_filter( 'upstudy_archive_sidebar_layout', 'upstudy_archive_ld_sidebar_layout' );
add_filter( 'upstudy_single_sidebar_layout', 'upstudy_archive_ld_sidebar_layout' );
if ( ! function_exists( 'upstudy_archive_ld_sidebar_layout' ) ) :
function upstudy_archive_ld_sidebar_layout ( $class ) {
if ( is_post_type_archive( 'sfwd-courses' ) || is_tax( 'ld_course_category' ) || is_tax( 'ld_course_tag' ) || is_singular( 'sfwd-courses' ) ) :
$class = 'no-sidebar';
endif;
return $class;
}
endif;
/**
* Single Course Thumbnail
*/
if ( ! function_exists( 'upstudy_ld_single_course_thumbnail' ) ) :
function upstudy_ld_single_course_thumbnail(){
$thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full' );
if ( isset( $thumb_src ) && ! empty( $thumb_src ) ) :
$thumb_url = $thumb_src[0];
else :
$thumb_url = get_template_directory_uri() . '/assets/images/no-image-found.png';
endif;
echo '
';
}
endif;
/**
* Course Search Post Type
*/
add_filter( 'upstudy_course_search_post_type', 'upstudy_ld_course_search_post_type' );
if ( ! function_exists( 'upstudy_ld_course_search_post_type' ) ) :
function upstudy_ld_course_search_post_type() {
return 'sfwd-courses';
}
endif;
/**
* Header Course Category Slug
*/
add_filter( 'upstudy_header_course_lms_cat_slug', 'upstudy_header_course_ld_cat_slug' );
if ( ! function_exists( 'upstudy_header_course_ld_cat_slug' ) ) :
function upstudy_header_course_ld_cat_slug() {
return 'ld_course_category';
}
endif;
/**
* Count Course Data
*/
if ( ! function_exists( 'upstudy_ld_count_published_posts' ) ) :
function upstudy_ld_count_published_posts( $post_type ) {
$count_posts = wp_count_posts( $post_type );
if ( $count_posts->publish ) :
return $count_posts->publish;
else :
return 0;
endif;
}
endif;
/**
* Course Archive Search Filter
*/
add_filter( 'upstudy_ld_course_archive_args', 'upstudy_ld_course_search_filter_archive' );
if( ! function_exists( 'upstudy_ld_course_search_filter_archive' ) ) :
function upstudy_ld_course_search_filter_archive( $args ) {
if ( is_post_type_archive( 'sfwd-courses' ) ) :
if ( isset( $_REQUEST['tpc_ld_course_filter'] ) && 'ld_course_search' === $_REQUEST['tpc_ld_course_filter'] ) :
$args['s'] = sanitize_text_field( $_REQUEST['search_query'] );
endif;
endif;
return $args;
}
endif;
/**
* indexing result of courses
*/
if( ! function_exists( 'upstudy_ld_course_index_result' ) ) :
function upstudy_ld_course_index_result( $total ) {
if ( 0 === $total ) :
$result = __( 'There are no available courses!', 'upstudy' );
elseif ( 1 === $total ) :
$result = __( 'Showing only one result.', 'upstudy' );
else :
$courses_per_page = Upstudy::setting( 'ld_course_per_page' ) ? Upstudy::setting( 'ld_course_per_page' ) : 9;
$paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
$from = 1 + ( $paged - 1 ) * $courses_per_page;
$to = ( $paged * $courses_per_page > $total ) ? $total : $paged * $courses_per_page;
if ( $from == $to ) :
$result = sprintf( __( 'Showing Last Course Of %s Results', 'upstudy' ), $total );
else :
$result = sprintf( __( 'Showing %s-%s Of %s Results', 'upstudy' ), '' . $from, $to . '', '' . $total . '' );
endif;
endif;
echo wp_kses_post( $result );
}
endif;
/**
* Course archive search bar
*/
if( ! function_exists( 'upstudy_ld_course_archive_search_bar' ) ) :
function upstudy_ld_course_archive_search_bar() {
/*
* remove param action="' . esc_url( get_post_type_archive_link( 'sfwd-courses ) ) . '"
* if you don't want to redirect to course category archive
*/
echo '';
echo '';
echo '
';
}
endif;
/**
* Course archive top bar
*/
if( ! function_exists( 'upstudy_ld_course_header_top_bar' ) ) :
function upstudy_ld_course_header_top_bar( $query ) {
global $wp_query;
$top_bar = true;
$index = true;
$search_bar = true;
if ( true == $index && true == $search_bar ) :
$column = 'upstudy-col-md-6';
else :
$column = 'upstudy-col-md-12';
endif;
if ( ( true == $top_bar ) && ( true == $index || true == $search_bar ) ) :
echo '';
echo '
';
if ( true == $index ) :
echo '
';
echo '';
upstudy_ld_course_index_result( $query->found_posts );
echo '';
echo '
';
endif;
if ( true == $search_bar ) :
echo '
';
echo '
';
upstudy_ld_course_archive_search_bar();
echo '
';
echo '
';
endif;
echo '
';
echo '
';
endif;
}
endif;
/**
* LearnDash Course Rating Active
*
*/
if( ! function_exists( 'is_upstudy_ld_rating_enable' ) ) :
function is_upstudy_ld_rating_enable() {
$status = true;
return $status;
}
endif;
/**
* Get Woocommerce course price
*
* @since 1.0.0
*/
if ( ! function_exists( 'upstudy_get_wc_course_price' ) ) :
function upstudy_get_wc_course_price( $product_id = null ) {
if ( empty( $product_id ) ) :
return '';
endif;
$product = wc_get_product( $product_id );
if ( ! $product ) :
return '';
endif;
return $product->get_price_html();
}
endif;
/**
* Currency symbols
*
* @param string $currency currency code such as USD, EUR
* @param int $course_id course ID
* @return string currency symbol
*
* @since 1.0.0
*/
if ( ! function_exists( 'upstudy_ld_course_currency_symbols' ) ) :
function upstudy_ld_course_currency_symbols( $currency, $course_id = null ) {
$currency_symbols = apply_filters( 'upstudy_ld_course_currency_symbols', array(
'AED' => 'د.إ',
'AFN' => '؋',
'ALL' => 'L',
'AMD' => 'AMD',
'ANG' => 'ƒ',
'AOA' => 'Kz',
'ARS' => '$',
'AUD' => '$',
'AWG' => 'Afl.',
'AZN' => 'AZN',
'BAM' => 'KM',
'BBD' => '$',
'BDT' => '৳',
'BGN' => 'лв.',
'BHD' => '.د.ب',
'BIF' => 'Fr',
'BMD' => '$',
'BND' => '$',
'BOB' => 'Bs.',
'BRL' => 'R$',
'BSD' => '$',
'BTC' => '฿',
'BTN' => 'Nu.',
'BWP' => 'P',
'BYR' => 'Br',
'BYN' => 'Br',
'BZD' => '$',
'CAD' => '$',
'CDF' => 'Fr',
'CHF' => 'CHF',
'CLP' => '$',
'CNY' => '¥',
'COP' => '$',
'CRC' => '₡',
'CUC' => '$',
'CUP' => '$',
'CVE' => '$',
'CZK' => 'Kč',
'DJF' => 'Fr',
'DKK' => 'DKK',
'DOP' => 'RD$',
'DZD' => 'د.ج',
'EGP' => 'EGP',
'ERN' => 'Nfk',
'ETB' => 'Br',
'EUR' => '€',
'FJD' => '$',
'FKP' => '£',
'GBP' => '£',
'GEL' => '₾',
'GGP' => '£',
'GHS' => '₵',
'GIP' => '£',
'GMD' => 'D',
'GNF' => 'Fr',
'GTQ' => 'Q',
'GYD' => '$',
'HKD' => '$',
'HNL' => 'L',
'HRK' => 'kn',
'HTG' => 'G',
'HUF' => 'Ft',
'IDR' => 'Rp',
'ILS' => '₪',
'IMP' => '£',
'INR' => '₹',
'IQD' => 'ع.د',
'IRR' => '﷼',
'IRT' => 'تومان',
'ISK' => 'kr.',
'JEP' => '£',
'JMD' => '$',
'JOD' => 'د.ا',
'JPY' => '¥',
'KES' => 'KSh',
'KGS' => 'сом',
'KHR' => '៛',
'KMF' => 'Fr',
'KPW' => '₩',
'KRW' => '₩',
'KWD' => 'د.ك',
'KYD' => '$',
'KZT' => '₸',
'LAK' => '₭',
'LBP' => 'ل.ل',
'LKR' => 'රු',
'LRD' => '$',
'LSL' => 'L',
'LYD' => 'ل.د',
'MAD' => 'د.م.',
'MDL' => 'MDL',
'MGA' => 'Ar',
'MKD' => 'ден',
'MMK' => 'Ks',
'MNT' => '₮',
'MOP' => 'P',
'MRU' => 'UM',
'MUR' => '₨',
'MVR' => '.ރ',
'MWK' => 'MK',
'MXN' => '$',
'MYR' => 'RM',
'MZN' => 'MT',
'NAD' => 'N$',
'NGN' => '₦',
'NIO' => 'C$',
'NOK' => 'kr',
'NPR' => '₨',
'NZD' => '$',
'OMR' => 'ر.ع.',
'PAB' => 'B/.',
'PEN' => 'S/',
'PGK' => 'K',
'PHP' => '₱',
'PKR' => '₨',
'PLN' => 'zł',
'PRB' => 'р.',
'PYG' => '₲',
'QAR' => 'ر.ق',
'RMB' => '¥',
'RON' => 'lei',
'RSD' => 'рсд',
'RUB' => '₽',
'RWF' => 'Fr',
'SAR' => 'ر.س',
'SBD' => '$',
'SCR' => '₨',
'SDG' => 'ج.س.',
'SEK' => 'kr',
'SGD' => '$',
'SHP' => '£',
'SLL' => 'Le',
'SOS' => 'Sh',
'SRD' => '$',
'SSP' => '£',
'STN' => 'Db',
'SYP' => 'ل.س',
'SZL' => 'L',
'THB' => '฿',
'TJS' => 'ЅМ',
'TMT' => 'm',
'TND' => 'د.ت',
'TOP' => 'T$',
'TRY' => '₺',
'TTD' => '$',
'TWD' => 'NT$',
'TZS' => 'Sh',
'UAH' => '₴',
'UGX' => 'UGX',
'USD' => '$',
'UYU' => '$',
'UZS' => 'UZS',
'VEF' => 'Bs F',
'VES' => 'Bs.S',
'VND' => '₫',
'VUV' => 'Vt',
'WST' => 'T',
'XAF' => 'CFA',
'XCD' => '$',
'XOF' => 'CFA',
'XPF' => 'Fr',
'YER' => '﷼',
'ZAR' => 'R',
'ZMW' => 'ZK'
) );
return isset( $currency_symbols[ $currency ] ) ? $currency_symbols[ $currency ] : $currency;
}
endif;
function upstudy_learndash_get_courses( $args = array() ) {
$args = wp_parse_args( $args, array(
'author' => '',
'fields' => ''
) );
extract($args);
$query_args = array(
'post_type' => 'sfwd-courses',
'post_status' => 'publish'
);
if ( ! empty( $author ) ) :
$query_args['author'] = $author;
endif;
if ( ! empty( $fields ) ) :
$query_args['fields'] = $fields;
endif;
$loop = new WP_Query($query_args);
$posts = array();
if ( ! empty( $loop->posts ) ) :
$posts = $loop->posts;
endif;
return $posts;
}
/**
* LearnDash compatibility
*
* @package Upstudy
*/
// add_body_classes_for_ld_lms
// upstudy_ld_course_info
// upstudy_ld_course_category
// upstudy_ld_related_course_content
// upstudy_ld_related_course_sidebar
// upstudy_ld_course_page_title_section_03
// upstudy_ld_course_page_title_section_04
// upstudy_ld_course_page_title_section_05
// upstudy_ld_course_page_title_section_06
//** ==== LearnDash add body class ** ====
function add_body_classes_for_ld_lms( $classes ) {
$prefix = '_upstudy_';
$post_id = upstudy_get_id();
$ld_single_page_layout = Upstudy::setting( 'ld_single_page_layout' );
$final_ld_single_page_layout = '';
if ( $ld_single_page_layout == '5' ) :
$final_ld_single_page_layout = Upstudy::setting( 'ld_single_page_layout' );
elseif ( $ld_single_page_layout == '4' ) :
$final_ld_single_page_layout = Upstudy::setting( 'ld_single_page_layout' );
elseif ( $ld_single_page_layout == '3' ) :
$final_ld_single_page_layout = Upstudy::setting( 'ld_single_page_layout' );
elseif ( $ld_single_page_layout == '2' ) :
$final_ld_single_page_layout = Upstudy::setting( 'ld_single_page_layout' );
elseif ( $ld_single_page_layout == '1' ) :
$final_ld_single_page_layout = Upstudy::setting( 'ld_single_page_layout' );
endif; //End single page layout
// Get body class for learndash lms profile page
if ( class_exists('SFWD_LMS') && $final_ld_single_page_layout && is_singular( 'sfwd-courses' )) {
$classes[] = 'single-course-layout-0'.$final_ld_single_page_layout.'';
}
// Get body class for ld lms course excerpt
global $post; $post_id = $post->ID;
$course_id = $post_id;
$user_id = get_current_user_id();
$current_id = $post->ID;
$prefix = '_upstudy_';
$ld_cg_short_description = get_post_meta( $post_id, '_learndash_course_grid_short_description', true );
$mb_short_description = get_post_meta( $post_id, '_upstudy_ld_excerpt', true );
$short_description = ($ld_cg_short_description) ? $ld_cg_short_description : $mb_short_description;
if ( class_exists('SFWD_LMS') && $short_description && is_singular( 'sfwd-courses' )) {
$classes[] = 'has__excerpt';
}
// Get body class for ld lms course meta
$has_meta = ( Upstudy::setting( 'ld_instructor_single' ) ) ? true : false;
if ( class_exists('SFWD_LMS') && $has_meta && is_singular( 'sfwd-courses' )) {
$classes[] = 'has__meta';
}
// Finally $classes return
return $classes;
}
add_filter( 'body_class', 'add_body_classes_for_ld_lms' );
// ==== Display Course info / upstudy_ld_course_info =====
if ( ! function_exists( 'upstudy_ld_course_info' ) ) {
function upstudy_ld_course_info() {
$ld_single_page_layout = Upstudy::setting( 'ld_single_page_layout' );
$ld_intro_video_position = Upstudy::setting( 'ld_intro_video_position' );
$ld_instructor_single = Upstudy::setting( 'ld_instructor_single' );
$ld_instructor_single_text = Upstudy::setting( 'ld_instructor_single_text' );
$ld_single_duration = Upstudy::setting( 'ld_single_duration' );
$ld_single_duration_text = Upstudy::setting( 'ld_single_duration_text' );
$ld_lesson_single = Upstudy::setting( 'ld_lesson_single' );
$ld_lesson_single_text = Upstudy::setting( 'ld_lesson_single_text' );
$ld_enrolled_single = Upstudy::setting( 'ld_enrolled_single' );
$ld_enrolled_single_text = Upstudy::setting( 'ld_enrolled_single_text' );
$ld_single_topic = Upstudy::setting( 'ld_single_topic' );
$ld_single_topic_text = Upstudy::setting( 'ld_single_topic_text' );
$ld_single_cat = Upstudy::setting( 'ld_single_cat' );
$ld_single_cat_text = Upstudy::setting( 'ld_single_cat_text' );
$ld_single_language = Upstudy::setting( 'ld_single_language' );
$ld_single_language_text = Upstudy::setting( 'ld_single_language_text' );
$ld_single_info_heading = Upstudy::setting( 'ld_single_info_heading');
$ld_custom_features_position = Upstudy::setting( 'ld_custom_features_position' );
$ld_single_certificate = Upstudy::setting( 'ld_single_certificate' );
if ( !in_array( $ld_single_page_layout, array('5')) ) {
get_template_part( 'learndash/tpl-part/single/single', 'media' );
}
echo '';
if ($ld_single_info_heading) {
echo '
' . esc_html($ld_single_info_heading) . '
';
}
echo '
';
if ($ld_custom_features_position == 'top') {
get_template_part( 'learndash/tpl-part/single/meta', 'custom' );
}
if ($ld_instructor_single) {
echo '- ';
if ($ld_instructor_single_text) {
echo '' . esc_html($ld_instructor_single_text) . '';
} else {
echo '' . esc_html__('Created by :', 'upstudy') . '';
}
echo '' . get_the_author() . '';
echo '
';
}
$duration = get_post_meta( get_the_ID(), '_learndash_course_grid_duration', true );
$duration_h = is_numeric( $duration ) ? floor( $duration / HOUR_IN_SECONDS ) : null;
$duration_m = is_numeric( $duration ) ? floor( ( $duration % HOUR_IN_SECONDS ) / MINUTE_IN_SECONDS ) : null;
if (!empty($ld_single_duration) && !empty($duration_h) && !empty($duration_m)) {
echo '- ';
if ($ld_single_duration_text) {
echo '' . esc_html($ld_single_duration_text) . '';
} else {
echo '' . esc_html__('Duration :', 'upstudy') . '';
}
echo '';
$tf_duration_h_text = esc_html__('h ', 'upstudy');
$tf_duration_m_text = esc_html__('m ', 'upstudy');
if ($duration_h) {
echo esc_attr($duration_h) . esc_html($tf_duration_h_text);
}
if ($duration_m) {
echo esc_attr($duration_m) . esc_html($tf_duration_m_text);
}
echo '';
echo '
';
}
$lesson = learndash_get_course_steps(get_the_ID(), array('sfwd-lessons'));
$lesson = $lesson ? count($lesson) : 0;
$lesson_text = ($lesson == '1') ? esc_html__(' Lesson', 'upstudy') : esc_html__(' Lessons', 'upstudy');
if ( $ld_lesson_single ) {
echo '- ';
echo '' . esc_html__('Lessons :', 'upstudy') . '';
echo '';
echo wp_kses_post( $lesson );
echo wp_kses_post( $lesson_text );
echo '';
echo '
';
}
$topic = learndash_get_course_steps(get_the_ID(), array('sfwd-topic'));
$topic = $topic ? count($topic) : 0;
$topic_text = ($topic == '1') ? esc_html__(' Topic', 'upstudy') : esc_html__(' Topics', 'upstudy');
if ( $ld_single_topic ) {
echo '- ';
echo '' . esc_html__('Topic :', 'upstudy') . '';
echo '';
echo wp_kses_post( $topic );
echo wp_kses_post( $topic_text );
echo '';
echo '
';
}
$course_options = get_post_meta( get_the_ID(), '_sfwd-courses', true );
$price_type = isset( $course_options['sfwd-courses_course_price_type'] ) ? strtoupper( $course_options['sfwd-courses_course_price_type'] ) : 'free';
$enrolled_base = upstudy_get_ld_course_meta( 'enrolled' );
$enrolled = upstudy_get_ld_course_student_count( get_the_ID(), $enrolled_base );
if ( $ld_enrolled_single) {
if ( 'OPEN' !== $price_type || $enrolled_base > 0 ) {
echo '- ';
if ($ld_enrolled_single_text) {
echo '' . esc_html($ld_enrolled_single_text) . '';
} else {
echo '' . esc_html__('Enrolled :', 'upstudy') . '';
}
echo '';
printf( _n( '%s Student', '%s Students', $enrolled, 'upstudy' ), $enrolled );
echo '';
echo '
';
}
}
if ($ld_single_cat) {
echo '- ';
if ($ld_single_cat_text) {
echo '' . esc_html($ld_single_cat_text) . '';
} else {
echo '' . esc_html__('Category :', 'upstudy') . '';
}
echo '';
if (!get_the_terms(get_the_ID(), 'ld_course_category')) {
esc_html_e('Uncategorized', 'upstudy');
} else {
echo get_the_term_list(get_the_ID(), 'ld_course_category', '');
}
echo '';
echo '
';
}
if ($ld_single_language && !empty(get_the_terms(get_the_ID(), 'ld_course_language'))) {
echo '- ';
if ($ld_single_language_text) {
echo '' . esc_html($ld_single_language_text) . '';
} else {
echo '' . esc_html__('Language :', 'upstudy') . '';
}
echo '';
echo get_the_term_list(get_the_ID(), 'ld_course_language', '');
echo '';
echo '
';
}
$ld_certificate_show = get_post_meta( get_the_ID(), '_upstudy_ld_certificate_show', true );
$get_certificate = 'yes' === $ld_certificate_show ? __( 'Yes', 'upstudy' ) : __( 'No', 'upstudy' );
if ( $ld_single_certificate == 'yes' ) {
echo '- ';
echo '' . esc_html__('Certificate :', 'upstudy') . '';
echo '';
echo esc_html($get_certificate);
echo '';
echo '
';
}
if ($ld_custom_features_position == 'bottom') {
get_template_part( 'learndash/tpl-part/single/meta', 'custom' );
}
echo '
';
echo '
';
}
}
// ===== Display Course Category / upstudy_ld_course_category =====
if ( ! function_exists( 'upstudy_ld_course_category' ) ) {
function upstudy_ld_course_category() {
global $post;
$post_id = $post->ID;
echo '';
}
}
/**
* Display related courses Content
*/
if ( ! function_exists( 'upstudy_ld_related_course_content' ) ) {
function upstudy_ld_related_course_content( $postType = 'sfwd-courses', $postID = null, $totalPosts = null, $relatedBy = null) {
$ld_related_course_title = Upstudy::setting( 'ld_related_course_title' );
$ld_related_course_items = Upstudy::setting( 'ld_related_course_items' );
$ld_related_course_by = Upstudy::setting( 'ld_related_course_by' );
$ld_related_course_columns = Upstudy::setting( 'ld_related_course_columns' );
$args = array(
'style' => $style = Upstudy::setting( 'ld_course_archive_style' )
);
global $post, $related_posts_custom_query_args;
if (null === $postID) $postID = $post->ID;
if (null === $totalPosts) $totalPosts = $ld_related_course_items;
if (null === $relatedBy) $relatedBy = $ld_related_course_by;
if (null === $postType) $postType = 'sfwd-courses';
// Build our basic custom query arguments
if ($relatedBy === 'category') {
$categories = get_the_category( $post->ID );
$catidlist = '';
foreach( $categories as $category) {
$catidlist .= $category->cat_ID . ",";
}
// Build our category based custom query arguments
$related_posts_custom_query_args = array(
'post_type' => $postType,
'posts_per_page' => $totalPosts, // Number of related posts to display
'post__not_in' => array($postID), // Ensure that the current post is not displayed
'orderby' => 'rand', // Randomize the results
'cat' => $catidlist, // Select posts in the same categories as the current post
);
}
if ($relatedBy === 'tags') {
// Get the tags for the current post
$tags = wp_get_post_tags($postID);
// If the post has tags, run the related post tag query
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
// Build our tag related custom query arguments
$related_posts_custom_query_args = array(
'post_type' => $postType,
'tag__in' => $tag_ids, // Select posts with related tags
'posts_per_page' => $totalPosts, // Number of related posts to display
'post__not_in' => array($postID), // Ensure that the current post is not displayed
'orderby' => 'rand', // Randomize the results
);
} else {
// If the post does not have tags, run the standard related posts query
$related_posts_custom_query_args = array(
'post_type' => $postType,
'posts_per_page' => $totalPosts, // Number of related posts to display
'post__not_in' => array($postID), // Ensure that the current post is not displayed
'orderby' => 'rand', // Randomize the results
);
}
}
// Initiate the custom query
$custom_query = new WP_Query( $related_posts_custom_query_args );
// Run the loop and output data for the results
if ( $custom_query->have_posts() ) :
echo '';
echo '
' . esc_html( $ld_related_course_title ) . '
';
echo '';
echo '';
while ( $custom_query->have_posts() ) : $custom_query->the_post();
echo '
';
get_template_part( 'learndash/tpl-part/course/th-layouts', '', $args );
echo '
';
endwhile;
echo '
';
endif;
// Reset postdata
wp_reset_postdata();
}
}
/**
* Display related courses sidebar
*/
if ( ! function_exists( 'upstudy_ld_related_course_sidebar' ) ) {
function upstudy_ld_related_course_sidebar( $postType = 'sfwd-courses', $postID = null, $totalPosts = null, $relatedBy = null) {
$ld_related_course_title = Upstudy::setting( 'ld_related_course_title' );
$ld_related_course_items = Upstudy::setting( 'ld_related_course_items' );
$ld_related_course_by = Upstudy::setting( 'ld_related_course_by' );
$ld_related_course_style = Upstudy::setting( 'ld_related_course_style' );
$final_ld_related_course_style = ($ld_related_course_style == 'square') ? 'square' : 'round';
global $post, $related_posts_custom_query_args;
if (null === $postID) $postID = $post->ID;
if (null === $totalPosts) $totalPosts = $ld_related_course_items;
if (null === $relatedBy) $relatedBy = $ld_related_course_by;
if (null === $postType) $postType = 'sfwd-courses';
// Build our basic custom query arguments
if ($relatedBy === 'category') {
$categories = get_the_category( $post->ID );
$catidlist = '';
foreach( $categories as $category) {
$catidlist .= $category->cat_ID . ",";
}
// Build our category based custom query arguments
$related_posts_custom_query_args = array(
'post_type' => $postType,
'posts_per_page' => $totalPosts, // Number of related posts to display
'post__not_in' => array($postID), // Ensure that the current post is not displayed
'orderby' => 'rand', // Randomize the results
'cat' => $catidlist, // Select posts in the same categories as the current post
);
}
if ($relatedBy === 'tags') {
// Get the tags for the current post
$tags = wp_get_post_tags($postID);
// If the post has tags, run the related post tag query
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
// Build our tag related custom query arguments
$related_posts_custom_query_args = array(
'post_type' => $postType,
'tag__in' => $tag_ids, // Select posts with related tags
'posts_per_page' => $totalPosts, // Number of related posts to display
'post__not_in' => array($postID), // Ensure that the current post is not displayed
'orderby' => 'rand', // Randomize the results
);
} else {
// If the post does not have tags, run the standard related posts query
$related_posts_custom_query_args = array(
'post_type' => $postType,
'posts_per_page' => $totalPosts, // Number of related posts to display
'post__not_in' => array($postID), // Ensure that the current post is not displayed
'orderby' => 'rand', // Randomize the results
);
}
}
// Initiate the custom query
$custom_query = new WP_Query( $related_posts_custom_query_args );
// Run the loop and output data for the results
if ( $custom_query->have_posts() ) :
echo '';
echo '';
echo '';
echo '';
endif;
// Reset postdata
wp_reset_postdata();
}
}
/**
* Filter search redirect to sfwd-courses-search.php
*/
function upstudy_ld_archive_search_template($template) {
global $wp_query;
$post_type = get_query_var('post_type');
if( isset($_GET['s']) && $post_type == 'sfwd-courses' )
{
return locate_template('sfwd-courses-search.php'); // redirect to sfwd-courses-search.php
}
return $template;
}
add_filter('template_include', 'upstudy_ld_archive_search_template');
/**
* LearnDash course archive page post_per_page
*/
function upstudy_ld_archive_course_post_per_page( $query ) {
$ld_course_per_page = Upstudy::setting( 'ld_course_per_page' );
if ( ! is_admin() && $query->is_main_query() && is_post_type_archive( 'sfwd-courses' ) ) {
$query->set( 'posts_per_page', $ld_course_per_page );
}
return;
}
add_action( 'pre_get_posts', 'upstudy_ld_archive_course_post_per_page', 15 );
// ===== upstudy_ld_course_page_title_section_03
if ( ! function_exists( 'upstudy_ld_course_page_title_section_03' ) ) :
function upstudy_ld_course_page_title_section_03( $title = null, $has_bg_image = null, $extra_style = null ) {
global $post; $post_id = $post->ID;
$course_id = $post_id;
$user_id = get_current_user_id();
$current_id = $post->ID;
$prefix = '_upstudy_';
$ld_cg_short_description = get_post_meta( $post_id, '_learndash_course_grid_short_description', true );
$mb_short_description = get_post_meta( $post_id, '_upstudy_ld_excerpt', true );
$short_description = ($ld_cg_short_description) ? $ld_cg_short_description : $mb_short_description;
$ld_single_excerpt = Upstudy::setting( 'ld_single_excerpt' );
$ld_single_breadcrumb = Upstudy::setting( 'ld_single_breadcrumb' );
$ld_single_page_layout = Upstudy::setting( 'ld_single_page_layout' );
$ld_header_color = ( $ld_single_page_layout == '4' ) ? 'light' : 'dark' ;
$custom_page_header_img = get_post_meta( get_the_ID(), '_upstudy_header_img', 1 );
//$page_title_image_sourse = ( !empty( $custom_page_header_img )) ? $custom_page_header_img : get_header_image() ;
if (!empty($custom_page_header_img)) {
echo '