Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor ModDish

    (@moddish)

    Thread Starter kozaria

    (@kozaria)

    Thanks!

    You also need to add this into functions.php located at the theme folder in order the drop-down menu to appear for product post type:

    /**
    * Hooks the WP cpt_post_types filter
    *
    * @param array $post_types An array of post type names that the templates be used by
    * @return array The array of post type names that the templates be used by
    **/
    function my_cpt_post_types( $post_types ) {

    $post_types[] = ‘grid_products’;
    return $post_types;
    }
    add_filter( ‘cpt_post_types’, ‘my_cpt_post_types’ );

    Is there anyway to do this without an additional plugin? Can I edit the grid-products.php file?

    Thanks, Pete

    Plugin Contributor ModDish

    (@moddish)

    you could edit the single template, then have a if else statement something like :

    if (get_post_type( $post->ID ) == ‘grid_products’ ){
    include ‘producttemplate.php’;
    }else {
    rest of single file
    }

    Thanks! It helped me a lot!!!

    deezlee

    (@deezlee)

    thanks y’all (i had the same question),

    I would like to use this code :

    function my_cpt_post_types( $post_types ) {

    $post_types[] = ‘grid_products’;
    return $post_types;
    }
    add_filter( ‘cpt_post_types’, ‘my_cpt_post_types’ );

    but i want to use it in my child theme functions.php file.

    would i need to use more code so that it works with the existing functions.php file?

    any chance somebody knows what to add?
    thanks again

    esmi

    (@esmi)

    @deezlee: If you require assistance then, as per the Forum Welcome, please post your own topic.

    deezlee

    (@deezlee)

    Figured it out:

    In order for the Custom-Post-Template plugin to create a Product Post Type drop-down menu on the new/edit product page you need to add Kozaria’s code to your theme’s function.php page.

    In order to use that code on a child-theme’s functions.php file you’ll need to add some code. Here’s Kozaria’s code wrapped in the other code needed.

    if ( ! function_exists( 'my_cpt_post_types' ) ) {
    function my_cpt_post_types( $post_types ) {
    
    $post_types[] = 'grid_products';
    return $post_types;
    }
    add_filter( 'cpt_post_types', 'my_cpt_post_types' );
    }

    I just copied my single.php template and renamed it to single-grid_products.php . There I can edit the way the product is shown in detail. Is that what was asked for? I just didn’t figuered out yet, how to display the price there.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom template for product?’ is closed to new replies.