Remove spaces between pages

2
<?php
/*
Template Name: Index Page
*/
?>
<?php get_header(); ?>
<?php $about = new WP_Query( 'pagename=home' ); ?>
<?php if( $about->have_posts() ) : $about->the_post(); ?>
<?php the_content(); ?>
<?php endif; ?> 

<?php $service = new WP_Query( 'pagename=service' ); ?>
<?php if( $service->have_posts() ) : $service->the_post(); ?>
<?php the_content(); ?>
<?php endif; ?> 

<?php $portfolio = new WP_Query( 'pagename=portfolio' ); ?>
<?php if( $portfolio->have_posts() ) : $portfolio->the_post(); ?>
<?php the_content(); ?>
<?php endif; ?> 
<?php get_footer(); ?>

The above code works but it generates a space between one page and another how do I remove it?

    
asked by anonymous 27.03.2015 / 21:41

1 answer

0

You do not need (and should not) open the PHP tag on each line. Everything between <?php and ?> will be interpreted by the server as code in PHP. It is also not necessary to use ?> at the end of the file, unless there is some HTML code after the last PHP statement.

In your case, the code would look like this:

<?php
/*
Template Name: Index Page
*/

 get_header(); 
 $about = new WP_Query( 'pagename=home' ); 
 if( $about->have_posts() ) : $about->the_post(); 
 the_content(); 
 endif;  

 $service = new WP_Query( 'pagename=service' ); 
 if( $service->have_posts() ) : $service->the_post(); 
 the_content(); 
 endif;  

 $portfolio = new WP_Query( 'pagename=portfolio' ); 
 if( $portfolio->have_posts() ) : $portfolio->the_post(); 
 the_content(); 
 endif;  
 get_footer(); 
    
04.06.2016 / 17:21