Solved

Fixing error on page

Posted on 2014-10-26
10
124 Views
Last Modified: 2014-10-26
Hello,

We have an issue in our code where if a game is not associated with an event it should push our search box up in the space where the event would be at but its throwing an error. Here is an example of what is going on:

http://supercon2k.com/game-roster/persona-4-arena-ultimax/

Here is the code that supports that area:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 
//debug($post);
if($post->ec3_schedule[0]->active==1):
$timeStamp = explode(' ', $post->ec3_schedule[0]->start);

$timeString = str_replace('-','',$timeStamp[0]);

$organizeEvents[$timeString] = array('ID' => $post->ID, 'start' => $post->ec3_schedule[0]->start);
endif;
endwhile; ksort($organizeEvents, SORT_NUMERIC); endif; wp_reset_query(); ?>

<?php if(is_array($organizeEvents)): ?>

<h2 class="sidebar">This Game is Taking Place at:</h2>
<div class="content" id="related-events">
<ul>
<?php foreach($organizeEvents as $takingPlace): 
$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id($takingPlace['ID']) , 'medium' ); $perm = get_permalink($takingPlace['ID']); ?>

<li>

<?php if(!empty($imgLg)): ?>
<div style="background: url('<?php echo $imgLg[0]; ?>') #2D0043 no-repeat; background-size: 290px auto; background-position: center; width: 290px; height: 105px; margin: 0 auto;" class="fadeit">
<a href="<?php echo $perm; ?>" style="display: block; height: 105px;"></a>
</div>
<?php endif; ?>
<p>Taking Place: <?php echo date(" M. jS @ ", strtotime($takingPlace['start']));
$time_format=get_option('time_format');
$thaTimeStart = mysql2date($time_format,$takingPlace['start']);
echo $thaTimeStart; ?></p>
</li>


<?php endforeach; $imgLg = array();  ?>
</ul>
</div>
<br />

<?php endif; endif; ?>

Open in new window


What do I need to change in the code to eliminate this error.
0
Comment
Question by:DancingFighterG
  • 6
  • 4
10 Comments
 
LVL 11

Expert Comment

by:f_o_o_k_y
ID: 40404935
it should be something like this.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 
//debug($post);
if($post->ec3_schedule[0]->active==1):
$timeStamp = explode(' ', $post->ec3_schedule[0]->start);

$timeString = str_replace('-','',$timeStamp[0]);

$organizeEvents[$timeString] = array('ID' => $post->ID, 'start' => $post->ec3_schedule[0]->start);
endif;
endwhile;
//CHANGE HERE
  if(is_array($organizeEvents): 
       ksort($organizeEvents, SORT_NUMERIC); 
  endif;

// or move this lines to the if below

//END OF CHANGES 
endif; wp_reset_query(); ?>

<?php if(is_array($organizeEvents)): ?>

<h2 class="sidebar">This Game is Taking Place at:</h2>
<div class="content" id="related-events">
<ul>
<?php foreach($organizeEvents as $takingPlace): 
$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id($takingPlace['ID']) , 'medium' ); $perm = get_permalink($takingPlace['ID']); ?>

<li>

<?php if(!empty($imgLg)): ?>
<div style="background: url('<?php echo $imgLg[0]; ?>') #2D0043 no-repeat; background-size: 290px auto; background-position: center; width: 290px; height: 105px; margin: 0 auto;" class="fadeit">
<a href="<?php echo $perm; ?>" style="display: block; height: 105px;"></a>
</div>
<?php endif; ?>
<p>Taking Place: <?php echo date(" M. jS @ ", strtotime($takingPlace['start']));
$time_format=get_option('time_format');
$thaTimeStart = mysql2date($time_format,$takingPlace['start']);
echo $thaTimeStart; ?></p>
</li>


<?php endforeach; $imgLg = array();  ?>
</ul>
</div>
<br />

<?php endif; endif; ?>

Open in new window

0
 

Author Comment

by:DancingFighterG
ID: 40405063
What do I need to change in the code so that if the condition is not true that the header "This game is taking place at:" does not show up

<?php if(is_array($organizeEvents)): ksort($organizeEvents, SORT_NUMERIC); endif; wp_reset_query(); ?>

<h2 class="sidebar">This Game is Taking Place at:</h2>
<div class="content" id="related-events">
<ul>
<?php foreach($organizeEvents as $takingPlace): 
$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id($takingPlace['ID']) , 'medium' ); $perm = get_permalink($takingPlace['ID']); ?>

<li>

Open in new window

0
 
LVL 11

Expert Comment

by:f_o_o_k_y
ID: 40405068
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 
//debug($post);
if($post->ec3_schedule[0]->active==1):
$timeStamp = explode(' ', $post->ec3_schedule[0]->start);

$timeString = str_replace('-','',$timeStamp[0]);

$organizeEvents[$timeString] = array('ID' => $post->ID, 'start' => $post->ec3_schedule[0]->start);
endif;
endwhile;
//CHANGE HERE
  if(is_array($organizeEvents): 
       ksort($organizeEvents, SORT_NUMERIC); 
  endif;

// or move this lines to the if below

//END OF CHANGES 
endif; wp_reset_query(); ?>

<?php 
//ANOTHER CHANGE
if(is_array($organizeEvents) && count($organizeEvents) > 0): 
//END OF ANOTHER CHANGE
?>


<h2 class="sidebar">This Game is Taking Place at:</h2>
<div class="content" id="related-events">
<ul>
<?php foreach($organizeEvents as $takingPlace): 
$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id($takingPlace['ID']) , 'medium' ); $perm = get_permalink($takingPlace['ID']); ?>

<li>

<?php if(!empty($imgLg)): ?>
<div style="background: url('<?php echo $imgLg[0]; ?>') #2D0043 no-repeat; background-size: 290px auto; background-position: center; width: 290px; height: 105px; margin: 0 auto;" class="fadeit">
<a href="<?php echo $perm; ?>" style="display: block; height: 105px;"></a>
</div>
<?php endif; ?>
<p>Taking Place: <?php echo date(" M. jS @ ", strtotime($takingPlace['start']));
$time_format=get_option('time_format');
$thaTimeStart = mysql2date($time_format,$takingPlace['start']);
echo $thaTimeStart; ?></p>
</li>


<?php endforeach; $imgLg = array();  ?>
</ul>
</div>
<br />

<?php endif; endif; ?>

Open in new window

0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 11

Expert Comment

by:f_o_o_k_y
ID: 40405070
or another version of the same code

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 
//debug($post);
if($post->ec3_schedule[0]->active==1):
$timeStamp = explode(' ', $post->ec3_schedule[0]->start);

$timeString = str_replace('-','',$timeStamp[0]);

$organizeEvents[$timeString] = array('ID' => $post->ID, 'start' => $post->ec3_schedule[0]->start);
endif;
endwhile;

endif;  ?>

<?php 
//ANOTHER CHANGE
if(is_array($organizeEvents) && count($organizeEvents) > 0): 

 ksort($organizeEvents, SORT_NUMERIC); 
 wp_reset_query();
//END OF ANOTHER CHANGE
?>


<h2 class="sidebar">This Game is Taking Place at:</h2>
<div class="content" id="related-events">
<ul>
<?php foreach($organizeEvents as $takingPlace): 
$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id($takingPlace['ID']) , 'medium' ); $perm = get_permalink($takingPlace['ID']); ?>

<li>

<?php if(!empty($imgLg)): ?>
<div style="background: url('<?php echo $imgLg[0]; ?>') #2D0043 no-repeat; background-size: 290px auto; background-position: center; width: 290px; height: 105px; margin: 0 auto;" class="fadeit">
<a href="<?php echo $perm; ?>" style="display: block; height: 105px;"></a>
</div>
<?php endif; ?>
<p>Taking Place: <?php echo date(" M. jS @ ", strtotime($takingPlace['start']));
$time_format=get_option('time_format');
$thaTimeStart = mysql2date($time_format,$takingPlace['start']);
echo $thaTimeStart; ?></p>
</li>


<?php endforeach; $imgLg = array();  ?>
</ul>
</div>
<br />

<?php endif; endif; ?>

Open in new window

0
 

Author Comment

by:DancingFighterG
ID: 40405115
Fooky,

That code breaks the site website.

http://dev.supercon2k.com/game-roster/persona-4-arena/
0
 
LVL 11

Expert Comment

by:f_o_o_k_y
ID: 40405117
paste whole code again which u are using now.
0
 
LVL 11

Accepted Solution

by:
f_o_o_k_y earned 500 total points
ID: 40405125
I have no way to debug or test the code but try this one
<?php 
if ( have_posts() ) : 
	while ( have_posts() ) : the_post(); 
		//debug($post);
		if($post->ec3_schedule[0]->active==1):
			$timeStamp = explode(' ', $post->ec3_schedule[0]->start);

			$timeString = str_replace('-','',$timeStamp[0]);

			$organizeEvents[$timeString] = array('ID' => $post->ID, 'start' => $post->ec3_schedule[0]->start);
		endif;
	endwhile;
endif;  
wp_reset_query();
//ANOTHER CHANGE
if(is_array($organizeEvents) && count($organizeEvents) > 0): 
	ksort($organizeEvents, SORT_NUMERIC); 
//END OF ANOTHER CHANGE
?>

	<h2 class="sidebar">This Game is Taking Place at:</h2>
	<div class="content" id="related-events">
	<ul>
	<?php foreach($organizeEvents as $takingPlace): 
			$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id($takingPlace['ID']) , 'medium' ); $perm = get_permalink($takingPlace['ID']); ?>
			<li>
			<?php if(!empty($imgLg)): ?>
				<div style="background: url('<?php echo $imgLg[0]; ?>') #2D0043 no-repeat; background-size: 290px auto; background-position: center; width: 290px; height: 105px; margin: 0 auto;" class="fadeit">
				<a href="<?php echo $perm; ?>" style="display: block; height: 105px;"></a>
				</div>
			<?php endif; ?>
			<p>Taking Place: <?php echo date(" M. jS @ ", strtotime($takingPlace['start']));
			$time_format=get_option('time_format');
			$thaTimeStart = mysql2date($time_format,$takingPlace['start']);
			echo $thaTimeStart; ?></p>
			</li>
	<?php endforeach; 
	$imgLg = array();  ?>
	</ul>
	</div>
	<br />

<?php  
endif; 
?>

Open in new window

0
 
LVL 11

Expert Comment

by:f_o_o_k_y
ID: 40405129
And BTW in the first version of code u posted there are 4 IF statements and 5 ENDIF is this a part of bigger script?
If yes than to my last code add another endif.
0
 

Author Comment

by:DancingFighterG
ID: 40405135
Ok, it works. Thanks bud!!
0
 

Author Closing Comment

by:DancingFighterG
ID: 40405136
Good work!!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
In Part I (http://www.experts-exchange.com/Web_Development/Blogs/WordPress/A_8410-Getting-Started-In-WordPress-Part-I.html), I introduced you to the powerful WordPress backend, the WordPress administrative Dashboard.  In Part II, I will introduce yo…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question