Solved

Fixing error on page

Posted on 2014-10-26
10
120 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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 …
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn how to count occurrences of each item in an array.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now