Link to home
Start Free TrialLog in
Avatar of Mike Waller
Mike WallerFlag for United States of America

asked on

Blog posts not showing up on Blog page

Hi there. Our WordPress site is using the FoundationPress theme and on our blog page here: https://centrosanjuandiego.org/blog/ the posts are not displaying. The file that serves up these posts is blog-template.php and inside that file I have the following:

<!-- start posts -->
<div class="row overloaded archive" role="main">	
<?php $i = 0; ?>
<?php if ( have_posts() ) : ?>
		<?php /* Start the Loop */ ?>
		<?php while ( have_posts() ) : the_post(); ?>
			<div class="small-12 large-6 columns" >

			<?php get_template_part( 'content', 'archive' ); ?>

			</div>
			<?php $i++; if($i%2 == 0 ) { ?>
		</div><!-- ending row -->
		<div class="row overloaded archive" role="main">
			<?php } ?>
		<?php endwhile; ?>		
		<?php else : ?>
		
<?php endif; // end have_posts() check ?>	
<?php get_template_part( 'content', get_post_format() ); ?>
</div>
<!-- end start posts | -->

Open in new window



Any idea why these posts would not be showing?
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Presumably the posts have a Status of Published?

Have you had them displaying before, such as in a previous theme?

Have you added some debugging to see how much of the code is run (eg by inserting a PHP call die("made it here"); into the code above?
Do you have any caching in place?
Either a wordpress plugin, or a local caching server like apache mod_cache, nginx or varnish? Maybe you have a CDN like Cloudfront, Cloudflare, or any other?
I checked and your server returns a 500 error. Here are the headers. So it seems that you have a cache in place, but this time your WP bombs with http 500.  Time to debug.

>curl https://centrosanjuandiego.org/blog/ -I

HTTP/1.1 500 Internal Server Error
Server: nginx
Date: Fri, 02 Dec 2016 10:11:42 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 13354
Connection: keep-alive
Keep-Alive: timeout=20
Set-Cookie: lang=es_ES; path=/
X-Cacheable: YES:briefly:500
Cache-Control: max-age=10, must-revalidate
Accept-Ranges: bytes
X-Cache: MISS
X-Pass-Why:
X-Cache-Group: normal
Avatar of Mike Waller

ASKER

it just seems it's not properly looping through and displaying the posts. Does the above code look correct?
ASKER CERTIFIED SOLUTION
Avatar of Shalom Carmel
Shalom Carmel
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Looks like you mixed up python syntax with php syntax.
for example, this line:
if ( have_posts() ) :
     do something;
should be
if ( have_posts() ) {
   do something;
  }

php does not recognize blocks by indentation, but by encapsulation in curly brackets.

Also, it will be immensely easier if you group your php code in blocks, rather than doing it on every line.

So something like this (untested)

<!-- start posts -->
<div class="row overloaded archive" role="main">	
<?php 
$i = 0; 
if ( have_posts() ) { 
		/* Start the Loop */ 
		while ( have_posts() ) {
			the_post(); 
			echo '<div class="small-12 large-6 columns" >'; 

			get_template_part( 'content', 'archive' ); 

			echo '</div>'; 
			$i++; 
			if($i%2 == 0 ) { 
				echo '</div><!-- ending row -->';
				echo '<div class="row overloaded archive" role="main">'; 
			} 
		} // endwhile; 		
		else {
		} 
		
} // endif; // end have_posts() check 	
get_template_part( 'content', get_post_format() ); 
?>
</div>
<!-- end start posts | -->

Open in new window

Hi Shalomc. That code broke the site. I may have to reach out to the author of the theme.