Solved

Fixing error on page

Posted on 2014-10-26
10
127 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

717 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