Error creating custom post type template

I am trying to insert my short codes into the custom post template file (single-definitions.php
Select theme to edit:
named after rewrite slug) but I get

Parse error: syntax error, unexpected '<' in /home/content/02/8916902/html/fiveyr/wp-content/themes/canvas/single-definitions.php on line 31

Here is the template code:

<?php
/**
 * Single Post Template
 *
 * This template is the default page template. It is used to display content when someone is viewing a
 * singular view of a post ('post' post_type).
 * @link http://codex.wordpress.org/Post_Types#Post
 *
 * @package WooFramework
 * @subpackage Template
 */

get_header();
?>

    <!-- #content Starts -->
	<?php woo_content_before(); ?>
    <div id="content" class="col-full">

    	<div id="main-sidebar-container">    

            <!-- #main Starts -->
            <?php woo_main_before(); ?>
            <section id="main">
<?php
	woo_loop_before();

	if (have_posts()) { $count = 0;
		while (have_posts()) { the_post(); $count++;
<strong><?php echo do_shortcode('[ct id="_ct_text_5260ae8773dea" property="title"]'); ?>
          </strong>: <?php echo do_shortcode('[ct id="_ct_text_5260ae8773dea" property="value"]'); ?>
<strong><?php echo do_shortcode('[ct id="_ct_textarea_5260aed010ff0" property="title"]'); ?> </strong>:  <?php echo do_shortcode('[ct id="_ct_textarea_5260aed010ff0" property="value"]'); ?> </strong>
<strong><?php echo do_shortcode('[ct id="ct_Reference_text_5ee9" property="title"]'); ?> </strong>: <?php echo do_shortcode('[ct id="ct_Reference_text_5ee9" property="value"]'); ?>
			woo_get_template_part( 'content', get_post_type() ); // Get the post content template file, contextually.
		}
	}

	woo_loop_after();
?>
            </section><!-- /#main -->
            <?php woo_main_after(); ?>

            <?php get_sidebar(); ?>

		</div><!-- /#main-sidebar-container -->         

		<?php get_sidebar('alt'); ?>

    </div><!-- /#content -->
	<?php woo_content_after(); ?>

<?php get_footer(); ?>
  • Alexander

    Hi @Shahram,

    As the error suggests, take a look at line 31

    if (have_posts()) { $count = 0;
            while (have_posts()) { the_post(); $count++;
    <strong><?php echo do_shortcode('[ct id="_ct_text_5260ae8773dea" property="title"]'); ?>

    The tag is still happening inside PHP, then PHP is reopened again.

    You can easily fix this by closing PHP first by adding ?> after count++;

    while (have_posts()) { the_post(); $count++; ?>

    Let me know how it goes!
    Best regards,

  • Patrick

    Hi @Shahram

    As @Alexander Rohmann mentioned, you need to close php like he has shown:
    while (have_posts()) { the_post(); $count++; ?>

    But then you must open it again here:
    <?php woo_get_template_part( 'content', get_post_type() ); // Get the post content template file, contextually.

    Here is your template code, modified. It should work:

    <?php
    /**
     * Single Post Template
     *
     * This template is the default page template. It is used to display content when someone is viewing a
     * singular view of a post ('post' post_type).
     * @link http://codex.wordpress.org/Post_Types#Post
     *
     * @package WooFramework
     * @subpackage Template
     */
    
    get_header();
    ?>
    
        <!-- #content Starts -->
    	<?php woo_content_before(); ?>
        <div id="content" class="col-full">
    
        	<div id="main-sidebar-container">    
    
                <!-- #main Starts -->
                <?php woo_main_before(); ?>
                <section id="main">
    <?php
    	woo_loop_before();
    
    	if (have_posts()) { $count = 0;
    		while (have_posts()) { the_post(); $count++; ?>
    <strong><?php echo do_shortcode('[ct id="_ct_text_5260ae8773dea" property="title"]'); ?>
              </strong>: <?php echo do_shortcode('[ct id="_ct_text_5260ae8773dea" property="value"]'); ?>
    <strong><?php echo do_shortcode('[ct id="_ct_textarea_5260aed010ff0" property="title"]'); ?> </strong>:  <?php echo do_shortcode('[ct id="_ct_textarea_5260aed010ff0" property="value"]'); ?> </strong>
    <strong><?php echo do_shortcode('[ct id="ct_Reference_text_5ee9" property="title"]'); ?> </strong>: <?php echo do_shortcode('[ct id="ct_Reference_text_5ee9" property="value"]'); ?>
    		<?php woo_get_template_part( 'content', get_post_type() ); // Get the post content template file, contextually.
    		}
    	}
    
    	woo_loop_after();
    ?>
                </section><!-- /#main -->
                <?php woo_main_after(); ?>
    
                <?php get_sidebar(); ?>
    
    		</div><!-- /#main-sidebar-container -->         
    
    		<?php get_sidebar('alt'); ?>
    
        </div><!-- /#content -->
    	<?php woo_content_after(); ?>
    
    <?php get_footer(); ?>
  • Patrick

    @Shahram

    Ah, I think I see what the problem is here.

    You are using a child-theme of the Canvas theme, and have tried creating a custom template using the default page template. But I think in Canvas you need to use the content templates.

    I've just downloaded and installed Canvas on a test site, and will try to figure out how to get it done. I'll post back when I do. :slight_smile: Hang on...

  • Patrick

    @Shahram

    Yep, that was the issue.

    First, delete the page template you made. Then copy the content.php template from Canvas to your child-theme, and rename it content-yourposttype.php. For example, I have a custom post type called "mytype", so my template is content-mytype.php.

    That is the template your theme will use to display your custom post type in all single and archive views. Easy-peasy. :slight_smile:

    You can add your custom field shortcodes inside section class="entry" like this:

    <section class="entry">
        <?php
        	the_content();
        	wp_link_pages( $page_link_args );
        ?>
    	 <strong>Custom field: </strong><?php echo do_shortcode('[ct id="_ct_text_52627b7fde53f" property="value"]'); ?>
    </section><!-- /.entry -->

    To get your custom post types to display on your homepage and in archives along with your regular posts, add the following to your child-theme's functions.php. Change mytype to the actual name of your post type.

    // Show custom post types on home page and archives
    add_action( 'pre_get_posts', 'add_custom_post_types_to_home_and_archives' );
    
    function add_custom_post_types_to_home_and_archives( $query ) {
    	if ( is_home() || is_archive() && $query->is_main_query() )
    		$query->set( 'post_type', array( 'post', 'mytype' ) );
    	return $query;
    }

    To get the custom post type titles to display like your regular post titles in archives, you may also want to add a bit of custom CSS in Canvas Theme Options under General Settings > Display Options. Change the color to whatever color you have set for your post titles in the theme options.

    .mytype .title a:link, .mytype .title a:visited {color:#222222; }

    One more thing: if you are using custom taxonomies for your post type, you may want to make another change so they appear in the post meta and, when clicked, go to a taxonomy archive page. I was just in the middle of testing some things out for that when my host's servers went down. So I'll have to get back to you on that, sorry.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.