• Hi all,
    I’m customizing TwentySeventeen thru a child theme to make a simple one-page site.
    To make easier for the editors to insert/edit the contact data input, I created a custom page template named template-kontakt.php which is retrieving and displaying values of some custom fields (ACF plugin).

    
    <?php
    /*
     * Template Name: Kontakt
     */
    
    get_header(); ?>
    
    <div class="wrap">
    	<div id="primary" class="content-area">
    		<main id="main" class="site-main" role="main">
    			<?php while ( have_posts() ) : the_post(); ?>
    				
    			    <div id="contact_wrapper">
    		                <div id="contact_1">
        		                    <div>
            		                <i class="fas fa-map-marker-alt"></i>
                		            </div>
    	            	            <div>
        	            	                <?php echo the_field('kontakt-strasse'); ?>
            	        	    </div>
                	    	            <div>
                    		        <?php echo the_field('kontakt-plz-ort'); ?>
    	                	    </div>
        	        	        </div>
    		                <div id="contact_2">
     		            	    <div>
        		                        <i class="fas fa-clock"></i>
      		            	    </div>
      		            	    <div>  
       		                	<?php echo the_field('kontakt-oeffnungstages'); ?>
      		            	    </div>
                    		    <div>
                    	    	        <?php echo the_field('kontakt-oeffnungszeit'); ?>
                    		    </div>
                		        </div>
                		        <div id="contact_3">
                			    <div>
                			        <i class="fas fa-comment-alt"></i>
                			    </div>
                			    <div>
                    			<i class="fas fa-phone"></i> <?php echo the_field('kontakt-telefon'); ?>
                			    </div>
                			    <div>
                    			<i class="far fa-envelope"></i> <?php echo the_field('kontakt-email'); ?>
                			    </div>
                		        </div>
            		    </div>
    
    			<?php endwhile; // End of the loop. ?>
    		</main><!-- #main -->
    	</div><!-- #primary -->
    </div><!-- .wrap -->
    
    <?php get_footer();

    Although the “Kontakt” page is displaying content correctly, the homepage panel is displaying the page title only.
    Is there any other file to edit in order to get the page content visible in the corresponding homepage panel?

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter claudiosinopoli

    (@claudiosinopoli)

    Hi all,
    I partially solved the issue adding the following code

    if($post->ID == 10){
    	load_template( get_stylesheet_directory() . '/template-kontakt.php' );
    }

    to /twentyseventeen-child/template-parts/page/content-front-page-panels.php

    <?php
    /**
     * Template part for displaying pages on front page
     *
     * @package WordPress
     * @subpackage Twenty_Seventeen
     * @since 1.0
     * @version 1.0
     */
    
    global $twentyseventeencounter;
    
    ?>
    
    <article id="panel<?php echo $twentyseventeencounter; ?>" <?php post_class( 'twentyseventeen-panel ' ); ?> >
    
    	<?php if ( has_post_thumbnail() ) :
    		$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'twentyseventeen-featured-image' );
    
    		// Calculate aspect ratio: h / w * 100%.
    		$ratio = $thumbnail[2] / $thumbnail[1] * 100;
    		?>
    
    		<div class="panel-image" style="background-image: url(<?php echo esc_url( $thumbnail[0] ); ?>);">
    			<div class="panel-image-prop" style="padding-top: <?php echo esc_attr( $ratio ); ?>%"></div>
    		</div><!-- .panel-image -->
    
    	<?php endif; ?>
    
    	<div class="panel-content">
    		<div class="wrap">
    			<header class="entry-header">
    				<?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
    
    				<?php twentyseventeen_edit_link( get_the_ID() ); ?>
    
    			</header><!-- .entry-header -->
    
    			<div class="entry-content">
    				<?php
    					/* translators: %s: Name of current post */
    					the_content();
    				if($post->ID == 10)
    				{
    				
    				load_template( get_stylesheet_directory() . '/template-kontakt.php' );
    
    				 } ?>
    			</div><!-- .entry-content -->
    
    			<?php
    			// Show recent blog posts if is blog posts page (Note that get_option returns a string, so we're casting the result as an int).
    			if ( get_the_ID() === (int) get_option( 'page_for_posts' )  ) : ?>
    
    				<?php // Show four most recent posts.
    				$recent_posts = new WP_Query( array(
    					'posts_per_page'      => 3,
    					'post_status'         => 'publish',
    					'ignore_sticky_posts' => true,
    					'no_found_rows'       => true,
    				) );
    				?>
    
    		 		<?php if ( $recent_posts->have_posts() ) : ?>
    
    					<div class="recent-posts">
    
    						<?php
    						while ( $recent_posts->have_posts() ) : $recent_posts->the_post();
    							get_template_part( 'template-parts/post/content', 'excerpt' );
    						endwhile;
    						wp_reset_postdata();
    						?>
    					</div><!-- .recent-posts -->
    				<?php endif; ?>
    			<?php endif; ?>
    
    		</div><!-- .wrap -->
    	</div><!-- .panel-content -->
    
    </article><!-- #post-## -->
    

    Now the contact data is correctly displayed on the corresponding homepage panel.
    Unfortunately this is completely breaking the “Kontakt” page itself, which is now displaying the custom fields’ values on a blank page.

    I know, this is not the best solution, since the page ID is hardcoded.
    In addition, to avoid the users to see the blank page, I would have to redirect /kontakt/ to /#kontakt. The same logic should be applied to all the pages used as homepage panels (/ueber-uns/ and /angebote/). The SEO performances will be effected. And so on..

    Anyhow I couldn’t figure out something better to solve this issue.
    Does anyone have any suggestion?

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Template Page with ACF content not displayed in as homepage panel’ is closed to new replies.