Trials and Tribulations with PHP

 

I read through a lot of PHP over this past weekend to fine tune the site’s new look and feel. There was actually one rather nasty bug in the last version that I’ve missed for the past 6 months or so. So, to elaborate on that bug and the relatively easy solution, here is some code below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php if ( !is_page() ) : ?>
	<span class="date"><?php the_time('F jS, Y') ?></span> &bull; <span class="postmetadata">Tags: <?php the_category(', ') ?>
<?php endif; ?><?php edit_post_link('Edit','<strong>|</strong> ',"); ?></span>
 
<div id="entry">
 
	<?php the_content('Read the rest of this entry;'); ?>
 
	<!– Checks to see if this is a post page. If it is, then we don't want to display the comments link. If not, we want to display it (main page basically) –>
	<?php if (!is_single() && !is_page()) : ?>
		<p><div id = “main-comments">There are <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> for 'lt;?php the_title(); ?>'</div></p>
	<?php endif; ?>
 
</div>

The problem I was trying to fix was simple. When you are on the main page of the site with all the posts, you want to be able to see the area under the post that displays information like “There are (some #) comments for (post name)”. You don’t need to see that when you are on the actual post’s page to read the full post and look at comments. You also don’t need to see a date and tag info for pages in Wordpress, such as the new About and Downloads pages. Just of note, I have left Rapidweaver for this site. It’s on a sad note since Rapidweaver is what spawned this site almost a year ago this week. It’s been a great year and I’ll more about that later, but I’m no longer using Rapidweaver on the site.

To put it simply, the issue I was having was with the PHP if() statement, by trying to have the HTML code on the page only if it met that condition. The solution my my problem came with the realization of a colon operator in PHP that allowed me to write the above code. Just out there for anyone else that might be having issues as well.

// Anything between this and the endif statement will only execute if the viewer isn’t viewing a page (ie, viewing the main blog page)
<?php if ( !is_page() ) : ?>
<? endif; ?>
Comments (0) Leave a Comment
  1. No comments yet.
Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
  1. No trackbacks yet.