Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author nicdark

    (@nicdark)

    Hi,

    can you post to me your domain please?

    Bye

    Hi There,

    We have this issue too.

    Your currency placeholder is after the currency in the single-course template which is not correct in the UK.

    Currently the template is like this…

    //metabox
    	    $nd_learning_meta_box_price = get_post_meta( get_the_ID(), 'nd_learning_meta_box_price', true );
    	    if ( $nd_learning_meta_box_price == 0 ) { 
    	        $nd_learning_meta_box_price = 'Free';
    	    } else { 
    	        $nd_learning_meta_box_price = $nd_learning_meta_box_price.' '.$nd_learning_currency; 
    	    }

    It needed to be prior to this.

     //metabox
    	    $nd_learning_meta_box_price = get_post_meta( get_the_ID(), 'nd_learning_meta_box_price', true );
    	    if ( $nd_learning_meta_box_price == 0 ) { 
    	        $nd_learning_meta_box_price = 'Free';
    	    } else { 
    	        $nd_learning_meta_box_price = $nd_learning_currency.' '.$nd_learning_meta_box_price; 
    	    }

    Rather than hacking the template in the plugin we wanted to copy it and add it in the child theme.

    To do this create a directory called templates in the child theme.
    Save courses-single.php in there and make your amends.

    However this does not work :o(

    For the developer.
    To be more consistent with WP calls. You could update your plugin include change dirname(__FILE__) to plugin_dir_path( __FILE__ ) perhaps.

    Example: change this in file… nd-learning.php around line 79

    function nd_learning_get_courses_template($nd_learning_single_course_template) {
         global $post;
    
         if ($post->post_type == 'courses') {
              $nd_learning_single_course_template = dirname( __FILE__ ) . '/templates/single-course.php';
         }
         return $nd_learning_single_course_template;
    }
    add_filter( 'single_template', 'nd_learning_get_courses_template' );

    To something like this…

    function nd_learning_get_courses_template($nd_learning_single_course_template) {
         global $post;
    
         if ($post->post_type == 'courses') {
              $nd_learning_single_course_template = plugin_dir_path( __FILE__ ) . '/templates/single-course.php';
         }
         return $nd_learning_single_course_template;
    }
    add_filter( 'single_template', 'nd_learning_get_courses_template' );

    Thanks

    Andi

    Further to that maybe incorporating this into this functions would work better.

    Ref — https://codex.www.ads-software.com/Plugin_API/Filter_Reference/single_template

    Add single-{post_type}-{slug}.php to Template Hierarchy
    This example loads the template file single-{post_type}-{slug}.php (i.e. single-event-wordcamp.php) only if the file exists, otherwise loads default template.
    
    <?php
    function add_posttype_slug_template( $single_template )
    {
    	$object = get_queried_object();
    	$single_postType_postName_template = locate_template("single-{$object->post_type}-{$object->post_name}.php");
    	if( file_exists( $single_postType_postName_template ) )
    	{
    		return $single_postType_postName_template;
    	} else {
    		return $single_template;
    	}
    }
    add_filter( 'single_template', 'add_posttype_slug_template', 10, 1 );
    ?>

    Applied to your function and does the job.

    
    function nd_learning_get_courses_template($nd_learning_single_course_template) {
         global $post;
        
         if ($post->post_type == 'courses') {
    
          $single_postType_postName_template = locate_template("single-course.php");
    
          if( file_exists( $single_postType_postName_template ) )  {
    
            $nd_learning_single_course_template = $single_postType_postName_template;
    
          } else {
    
            $nd_learning_single_course_template = dirname( __FILE__ ) . '/templates/single-course.php';
          }
          
         }
         return $nd_learning_single_course_template;
    }
    add_filter( 'single_template', 'nd_learning_get_courses_template' );
    
    

    You do not need a templates subdirectory just copy them and paste them into the sub theme, although you could alter the code to check in a nd-learning subdirectory/templates in the child theme first.

    This may keep it neater.

    Thanks

    Andi

    function nd_learning_get_courses_template($nd_learning_single_course_template) {
         global $post;
        
         if ($post->post_type == 'courses') {
    
          $single_postType_postName_template = locate_template("nd-learning/templates/single-course.php");
    
          if( file_exists( $single_postType_postName_template ) )  {
    
            $nd_learning_single_course_template = $single_postType_postName_template;
    
          } else {
    
            $nd_learning_single_course_template = dirname( __FILE__ ) . '/templates/single-course.php';
          }
    
         }
         return $nd_learning_single_course_template;
    }
    add_filter( 'single_template', 'nd_learning_get_courses_template' );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How do I edit the template/layout’ is closed to new replies.