Solved

Fixing error on page

Posted on 2014-10-26
10
126 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
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!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

749 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