WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
[resolved] Shortcode not working in custom page template (7 posts)

  1. atreyu6
    Member
    Posted 6 months ago #

    Hi,

    I have a custom made WP theme and I'm trying to insert a contact form on a page with a custom page template ("template-page.php"). However, it's not displaying the form - it just displays the shortcode itself: [contact-form-7 id="12263" title="form name"]

    The contact form displays when I use the standard page template (page.php). But I need to use the custom page template, otherwise the rest of the page content is not displaying correctly.

    I'm guessing something is missing in the template-page.php file:

    get_header(); ?>
    	<?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    			<div class="wrapper">
    				<div class="page-content<? if($curpage->post_parent != 0) { echo " subpage"; } ?>">
    					<div class="cols">
    						<div class="main-content" style="padding-top: 68px; float: right;">
    							<?php
    							    echo $curpage->post_content;
    							?>
    						</div>
    					<?php
    					    echo '<div class="navbar"><div class="box"><h2>';
    					    if($curpage->post_parent == 0) {
    						echo get_the_title();
    					    }
    					    else {
    						$parent = get_page($curpage->post_parent);
    						echo $parent->post_title;
    					    }
    					    echo '</h2><ul class="nav-list">';
    					    $args = array("sort_column" => "menu_order");
    					    $pages = get_pages($args);
    					    foreach ( $pages as $pagg ) {
    						if(($curpage->post_parent == 0 && $pagg->post_parent == get_the_ID()) || ($curpage->post_parent != 0 && $pagg->post_parent == $curpage->post_parent)) {
    						    $option = '<li><a ';
    						    if(get_the_ID() == $pagg->ID) {
    							$option .= 'class="selected" ';
    						    }
    						    $option .= 'href="'.get_page_link( $pagg->ID ).'">';
    						    $option .= $pagg->post_title;
    						    $option .= ' ยป</a></li>';
    						    echo $option;
    	    				        }
    					    }
    					    echo '</ul></div></div>';
    					?>
    					    <div class="navbar brownbox" style="background-color: #2b2223; clear: left;"><div class="box" style="background-color: #2b2223; padding-bottom: 10px;">
    						<?=get_post_meta($post->ID, 'brownbox', true);?>
    					    </div></div>
    					</div>
    				</div>
    			</div>
    			<script type="text/javascript">
    			    if(jQuery('.brownbox > div').html().replace(/\s/g,'') == '') {
    				jQuery('.brownbox').remove();
    			    }
    			    jQuery('#main').css('background-image','url(<?=preg_replace("/^.*?src=\"([^\"]*)\".*?$/","$1",get_the_post_thumbnail( $post->ID, 'big-thumb' ));?>)');
    			</script>
    		<?php endwhile; ?>
    	<?php else : ?>
    		<div class="wrapper">
    			<div class="page-title">
    				<h1>Not Found</h1>
    			</div>
    			<div class="page-content">
    				<p>Sorry, but you are looking for something that isn't here.</p>
    			</div>
    		</div>
    	<?php endif; ?>
    <?php get_footer(); ?>

    I don't know a lot about php though, so I can't figure out how to fix this. Any ideas?

    Cheers

    https://wordpress.org/plugins/contact-form-7/

  2. esmi
    Forum Moderator
    Posted 6 months ago #

    Your page template is not using the_content(). This function uses a number of filters - one of which parses shortcodes.

  3. atreyu6
    Member
    Posted 6 months ago #

    Alright, thanks. Could I post <?php the_content(); ?> in there somewhere then? Or would it break the page template?

  4. alchymyth
    Forum Moderator
    Posted 6 months ago #

    try and apply a filter to this line:

    echo $curpage->post_content;

    example:

    echo apply_filters( 'the_content', $curpage->post_content );

    http://codex.wordpress.org/Function_Reference/apply_filters

  5. atreyu6
    Member
    Posted 6 months ago #

    Thanks, that did the trick!

  6. radassamber
    Member
    Posted 4 months ago #

    Im having a similar issue but with a different page template using a plugin called simple staff list. The shortcode displays fine on one page and doesnt work on another - thats using a different template. I dont know where to add in <?php the_content(); ?>

    <?php get_header(); ?>
    <?php
    		global $post;
    		$custom 	= get_post_custom();
    		$t_name 		= get_the_title();
    		$name_slug	= basename(get_permalink());
    		$title 		= $custom["_staff_member_title"][0];
    		$email 		= $custom["_staff_member_email"][0];
    		$phone 		= $custom["_staff_member_phone"][0];
    		$fax 		= $custom["_staff_member_fax"][0];
    		$bio 		= $custom["_staff_member_bio"][0];
    		$prof 		= $custom["_staff_member_prof"][0];
    		$fb_url		= $custom["_staff_member_fb"][0];
    		$tw_url		= 'http://www.twitter.com/' . $custom["_staff_member_tw"][0];
    		$li_url		= $custom["_staff_member_li"][0];
    		?>
    
    		<?php
    		if(has_post_thumbnail()){
    
    			$t_photo_url = wp_get_attachment_url( get_post_thumbnail_id() );
    			$t_photo = '<img class="staff-member-page-photo" src="'.$t_photo_url.'" alt = "'.$title.'">';
    		}else{
    			$t_photo_url = '';
    			$t_photo = '';
    		}
    		$email_mailto = '<a class="staff-member-email" href="mailto:'.antispambot( $email ).'" title="Email '.$name.'">'.antispambot( $email ).'</a>';
    ?>	
    
    <div class="bios">
    <div class="content">
    	<div class="row">
    		<div class="large-12 columns">
    		<?php while (have_posts()) : the_post(); ?>
    			<h1><?php the_title(); ?></h1> <!-- This is the Standard page title -->
    		</div>
    		<div class="large-6 columns">
    			<?=$t_photo?> <!-- This is the Staff Memeber Photo -->
    		</div>
    		<div class="large-6 columns">
    			<h2><?=$title?></h2> <!-- This is the Staff Memeber Title -->
    			<p class="staff-bio"><?=$bio?><?php the_content(); ?></p>  <!-- This is the Staff Memeber Bio -->
    		</div>
    
    			<?php the_content();?>
    	</div>
    </div>
    				<?php endwhile; ?>	
    
    </div><!-- #page-full -->
    
    <?php get_footer(); ?>

    No idea here.

  7. jpdokter
    Member
    Posted 1 week ago #

    This is my solution

    $q = new WP_Query(array('post_type' => 'post'));
            if ( $q->have_posts() ) {
                while ( $q->have_posts() ) {
                    $q->the_post();
    
                    ob_start();
                    the_content();
                    $c = ob_get_contents();
                    ob_end_clean();
    
                    $items[] = sprintf($item_tpl, get_the_title(), $c);
                }
            }

Reply

You must log in to post.

About this Plugin

About this Topic