• Resolved aquanat

    (@aquanat)


    Hello,

    I’m writing a plugin which use custom post type (post).
    I’m working with Twenty Twelve theme.

    Two problems:

    1. If i create a new page (with default template) i can’t see it: when i click on “view page” i get only a blank page.
    2. When i activate my plugin i get this error:

    The plugin generated 2 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.

    I saw on some post that can be that my plugin files there’s some space before or after php tag (<?php and ?>) but that’s not my case.

    Thanks a lot!

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

    (@aquanat)

    N°2 resolved: one php file had:

    <?php someinstruction; ?>
    <?php someinstruction; ?>

    now is:

    <?php someinstruction;
     someinstruction; ?>

    About nr 1 my code is:

    <?php
    add_filter( 'template_include', 'custom_post_type_restaurant_view', 1 );
    function custom_post_type_restaurant_view()
    {
    	 if ( get_post_type() == 'restaurant' ) {
            if ( is_single() ) {
                // checks if the file exists in the theme first,
                // otherwise serve the file from the plugin
                if ( $theme_file = locate_template( array ( 'single-restaurant.php' ) ) )
    			{
                    $template_path = $theme_file;
                }
    			else
    			{
                    $template_path = plugin_dir_path( __FILE__ ) . 'single-restaurant.php';
                }
            }
    		return $template_path;
        }
    	elseif ( get_post_type() == 'menu' ) {
            if ( is_single() ) {
                // checks if the file exists in the theme first,
                // otherwise serve the file from the plugin
                if ( $theme_file = locate_template( array ( 'single-menu.php' ) ) )
    			{
                    $template_path = $theme_file;
                }
    			else
    			{
                    $template_path = plugin_dir_path( __FILE__ ) . 'single-menu.php';
                }
            }
    		return $template_path;
        }
    
    }?>

    Thanks

    Thread Starter aquanat

    (@aquanat)

    Ok resolved myself as explained here:

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

    with this code:

    <?php
    function get_custom_post_type_template($single_template) {
         global $post;
    
         if ($post->post_type == 'my_post_type') {
              $single_template = dirname( __FILE__ ) . '/post-type-template.php';
         }
         return $single_template;
    }
    
    add_filter( "single_template", "get_custom_post_type_template" ) ;
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can't see page with default template’ is closed to new replies.