How to have more than one template for custom post types in CustomPress?

So, I am working on a genealogical society website and I have three custom post types: townships, cemeteries and churches. I have created a page http://acgs.selfip.org/townships that holds an image map I created using Gyn's Imagemap Selector plugin. Clicking on a labeled section of the imagemap brings up a modal window (lightbox plus colorbox plugin) that displays the township information with the cemeteries for that township listed using the shortcodes ultimate plugin to display the cemetery posts. Clicking on the link above and selecting "Caribou" on the image map will show my current setup. Eventually, churches will be displayed on the township page in the same way.

In order to get the posts to display the way I wanted them to, I've had to hack their templates considerably. This means that clicking on an individual township or cemetery link will bring up a page without the proper header and footer. I plan on removing the link code from the cemetery titles, but I would like to be able to have townships display as a separate single post as well as in the modal window.

Is there a way I can designate one template for the modal window and a different template to display a township as a standard single post? Thanks!

  • Tyler Postle

    Hey Heather, hope you're doing well today!

    So you're wanting the post to have a different template depending on whether it is displayed on a normal post or if it's pulled into the lightbox?

    That would require further development, you might want to consider hiring one from our jobs board: https://premium.wpmudev.org/wordpress-development/

    Another option would be to use CSS to change the look of the pop up :slight_smile: you could target styles specific to the popup so the changes don't affect any other areas of your site.

    What all did you want removed from the post in the Popup? Perhaps we could help with some CSS. Just header and footer area?

    Perhaps we can still help :slight_smile:

  • Anang

    Hi @HeatherFeuer

    Thanks for contacting us :slight_smile:

    I don't think one custom post type can have multiple page template. But what if for Modal dialogue we add extra parameter in URL. And we check if there's extra URL variable , we disable header and footer. What do you think about that ?

    If you can share your page template code, I can help you with the conditioning code :slight_smile:

    Let me know what do you think :slight_smile:

    Best Regards

  • HeatherFeuer

    Anang, your suggestion is brilliant! I think that would work beautifully. Here is the code for the township and cemetery single post templates (they are identical):

    <?php
    /**
     * The template for displaying township posts.
     *
     * @package ACGS
     */
    
    wp_head();
    //get_header(); ?>
    
    	<div id="primary" class="content-area-township">
    		<main id="main" class="site-main" role="main">
    
    		<?php while ( have_posts() ) : the_post(); ?>
    <br />
    <?php //the_post_navigation(); ?>
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    	<header class="entry-header">
    		<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
    	</header><!-- .entry-header -->
    
    	<div class="entry-content">
    		<?php the_content(); ?>
    		<?php
    			wp_link_pages( array(
    				'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'acgs' ),
    				'after'  => '</div>',
    			) );
    		?>
    	</div><!-- .entry-content -->
    
    	<footer class="entry-footer">
    		<?php acgs_entry_footer(); ?>
    	</footer><!-- .entry-footer -->
    </article><!-- #post-## -->
    
    			<?php //the_post_navigation(); ?>
    
    		<?php endwhile; // End of the loop. ?>
    
    		</main><!-- #main -->
    	</div><!-- #primary -->
    
    <?php //get_sidebar(); ?>
    <?php //get_footer(); ?>
    <?php wp_footer(); ?>

    As you can see, I don't want to display the header and footer in the modal window -- just the post title/content. Here is the basic link code for each segment of the area map:
    [imagemap map="imgmap_css_container_imgmap2015722155142" direct=1 id="imgmap2015722155142" img="http://acgs.selfip.org/wp-content/uploads/2015/07/aroostook-grid-map.png?1437594773456"][area shape=rect alt="Weston" title="Weston" url="/townships/weston" class="lbpmodal"]798,913,833,957[/area]

    For reference, the single post template is here:

    <?php
    /**
     * The template for displaying all single posts.
     *
     * @package ACGS
     */
    
    get_header(); ?>
    
    	<div id="primary" class="content-area">
    		<main id="main" class="site-main" role="main">
    
    		<?php while ( have_posts() ) : the_post(); ?>
    
    			<?php get_template_part( 'template-parts/content', 'single' ); ?>
    
    			<?php the_post_navigation(); ?>
    
    			<?php
    				// If comments are open or we have at least one comment, load up the comment template.
    				if ( comments_open() || get_comments_number() ) :
    					comments_template();
    				endif;
    			?>
    
    		<?php endwhile; // End of the loop. ?>
    
    		</main><!-- #main -->
    	</div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    The theme was created by Underscores.... Don't you just love that site??? Thanks!!!!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.