0

I have a checkbox in the customizer which lets you choose to display content or not. I've got everything to work besides displaying the page content; it echoes the HTML tags but not the WordPress dynamic page date.

<?php $servicescontent = get_theme_mod('services-page', 1);
$mod = new WP_Query( array( 'page_id' => $servicescontent ) ); while($mod->have_posts()) : $mod->the_post();?>
<?php $abc = get_theme_mod('services-check', 1);
if( $abc == 1) {
echo  ('<div class="section default-bg">
  <div class="container">
    <h1 id="services"  class="text-center title"><?php the_title();?></h1>
    <div class="space"></div>
    <div class="row">
      <?php the_content();?>
<?php endwhile; ?>
    </div>
  </div>
</div>
  <!-- section end -->');}

else{
  ('');}
?>

Can someone tell me what characters need escaped? I am trying to teach myself through building a theme from scratch but have not been able to solve this issue myself. When looking at the rendered page's HTML, it looks like the WordPress PHP is being commented out.

0

Here is a modified version of your original code. Your echo statement isn't right and really isn't necessary. It's probably better to jump out of PHP like I've done in the code below. Also, the unnecessary else statement was removed:

<?php
$servicescontent = get_theme_mod( 'services-page', 1 );
$abc = get_theme_mod( 'services-check', 1 );
$mod = new WP_Query( array( 'page_id' => $servicescontent ) );

while ( $mod->have_posts() ) : $mod->the_post();
    if ( $abc == 1 ) { ?>
        <div class="section default-bg">
            <div class="container">
                <h1 id="services" class="text-center title"><?php the_title();?></h1>
                <div class="space"></div>
                <div class="row">
                    <?php the_content();?>
                </div>
            </div>
        </div><!-- section end --><?php 
    }
endwhile;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.