Remove spaces between a page and another

Asked

Viewed 45 times

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 generates a space between a page and another how do I remove this?

  • Are you sure it’s in PHP?

  • 4

    That code made a small part of me die... You don’t need to put <?php for each function, just put one and make as many statements as necessary. As for the question, we need you to show the HTML part to evaluate where the spacing is arising...

1 answer

0

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

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(); 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.