Blog Thoughts
WordPress Tips and Ideas Learned From Implementation

Recently, I had to slice and implement a blog for the CEO of my company. I decided to go with WordPress because that is what I have become enamored with recently, when I created a job board using it. I used some features of WordPress that I had never used before, so I figured I would talk about them so that others could learn how to use them as well.

Multiple Loops

The blog contained a main blog section, along with a “Favorites” section in the sidebar, that would be used to list anything: favorite websites, books, etc. I didn’t think that using just the basic WordPress blogroll or a third party bookmarking site would give the CEO enough flexibility to mark whatever she wanted as a favorite. So I decided to just create a separate category for Favorites.

In the footer of the site, there is also information about the last 6 projects that we had worked on. I definitely did not want those to be static. Since we complete projects almost daily, I wanted “non-technical” people to be able to update them. So I decided to create a separate category for those.

So in total, I had 3 categories: Blog, Favorites, and Projects.

I figured I would just end up having the main loop in the content area, a loop in the sidebar, and a loop in the footer. I had never really done a site with multiple loops, but after reading the documentation, it didn’t look too complicated. So the key to having multiple loops is to use the query_posts template tag.

The Main Blog Loop

The Blog category has an id of 1. So all you have to do is call the query_posts template tag before you loop through the entries:

<?php query_posts('cat=1');
	if (have_posts()) :
		while (have_posts()) : the_post(); ?>
			…
		<?php endwhile;
	endif; ?>

Then the Favorites and Project categories are basically the same, you just plug in the correct category id into the query_posts template tag.

Paging with Multiple Loops

So since we are using the query_posts template tag, it messes up the paging of the main loop. So, in the main blog loop, we need to use the ternary operator to add in the paging argument:

<?php
	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
	query_posts("cat=1&paged=$paged");
?>

So those two lines would replace the previous call to the query_posts template tag that we used for the main loop.

Read More Links

When I had first implemented the blog, we were using the read more links (whenever they were added into the post) for all posts. Later in the implementation process, I was told that the most recent article should always show the full post.

I wasn’t sure how the heck I could do that, but after some Googling I figured it out. Basically what we need to do is just create a simple counter to see if we are on the first post. If we are, we set a global $more variable equal to 1. So I define the $count variable and set it equal to 1, then I have this at the beginning of the main loop:

<?php
if (is_home()) {
	global $more;
	if($count == 1) $more = 1;
	else $more = 0;
	$count++;
}
?>

Wait a Minute…

So I was all ready to publish this article, when I found out today that the first article on my CEO’s blog was still showing the read more link. From what I discovered, it looked like both the is_home() and is_front_page() conditional tags were not registering as true when on the homepage. For the life of me, I could not figure out why this was happening.

So this was a little bit of a hacky solution, but it was all that I could think of quickly. I had this code before the loop:

<?php
	if($_SERVER['REQUEST_URI'] == ‘/’) {
		$isHomepage = true;
	}
?>

So essentially, I was setting up my own flag to see if it was the homepage. What that is doing is checking the URL to see if it is the root of the site or not. Then I modifed the if statement in my other code to be:

<?php
	if (isset($isHomepage) && $isHomepage = true) {
		global $more;
		if($count == 1) $more = 1;
		else $more = 0;
		$count++;
	}
?>

I’m not sure if there is a better solution, but I think the reason the is_home() and is_front_page() conditions don’t work is because of calling the query_posts template tag, because they worked before the call.

Custom Fields

I had used custom fields before, and they are amazingly powerful in being able to extend WordPress functionality. For my CEO’s blog, I used 4 custom fields:

  • favoriteThumbnail
  • favoriteUrl
  • projectThumbnail
  • projectUrl

Favorites’ Custom Fields

The favorites are supposed to be little blurbs about something that my CEO likes, whether it is a book, website, etc. So the idea is that it is not supposed to be a full blog post, just a little blurb. So instead of linking to the WordPress post, we link to the favoriteUrl custom field. Here is how the favoriteUrl custom field is being used (this is called within The Loop):

<?php
$favoriteUrl = get_post_meta($post->ID, "favoriteUrl", true);
if($favoriteUrl != '') { ?>
	<a href="<?=$favoriteUrl ?>" class="heading"><strong><?php the_title(); ?></strong></a>
<?php } else { ?>
	<strong class="heading"><?php the_title(); ?></a>
<?php } ?>

So basically what I am doing there is first calling in the favoriteUrl custom field and assigning it to the $favoriteUrl variable. Then, I check to make sure it is not empty (meaning the custom field was not entered). If it is entered, I output the link to the URL. If not, I still do not link to the WordPress post, I just display the title in bold.

The favoriteThumbnail is pretty self explanatory and is called in the same way as the favoriteUrl. The reason I wanted to use a custom field for the thumbnail instead of just adding the image to the post content is because the design called for the image to be floated next to the title and because I wanted to link the image to the favoriteUrl. This way, when my CEO is adding a favorite, she does not have to worry about floating the image and linking it to the favoriteUrl.

Projects’ Custom Fields

Both of the Projects’ custom fields are used similarly to the Favorities’ custom fields. The projectThumbnail custom field is just used to show the most recent 6 projects in the footer. Nothing complicated, just showing and linking the photo to the WordPress post.

Until our new company website gets launched, we are linking to the short WordPress post which gives a little description about the project. The projectUrl outputs the URL to the project at the end of the post. Once our company website is finished, I will just modify the custom field to link directly from the footer to its respective page in our portfolio.

Conclusion

I really enjoyed doing this implementation. While it was just a simple blog, it is always great to learn a couple of new tricks/techniques. Any other WordPress tips that you have found useful?

Read more...
 
Weekly Link Round-Up #36

I actually got started on my redesign/realign this weekend. I think I want to have a larger focus on my portfolio, and not just my blog. But god is it hard to redesign when you aren’t a designer. Hopefully it will all turn out well in the end. Here is what I found interesting this week:

  • A New Day

    As much as I love Jason Santa Maria’s last design, I think his new direction/design is really interesting.

  • Spacing Is Everything

    Khoi Vinh shows what Gmail would look like with a little bit of spacing. I actually think it might look better, but he caught some backlash from the commentors saying that there would be less messages “above the fold”. But I think that you rarely look below the fold when looking for a message, and even if you did, you would be more likely to use the search instead.

  • A List Apart: Issue 261

    I was pretty excited to finally see a CSS article in A List Apart, Faux Absolute Positioning. It had been quite a while. I was actually really disappointed with it though. It seems like extraneous markup, and I don’t really see the advantages. The second article in the issue, Sketching in Code: the Magic of Prototyping, brings up a much more important issue. Prototyping is probably the most important part of the process of developing web applications.

  • The Education of Geeks and Freaks

    I think the current state of the education of web development is awful. I know how hard it must be to stay on top of new technologies and be a teacher, but still, it needs to improve. It’s great to hear that some schools are starting to take the right step and teaching new technologies.

  • From PSD to HTML, Building a Set of Website Designs Step by Step

    I kind of skimmed this article because it was really just a discussion about what I do when I slice a site. From what I saw, it seemed like a pretty decent description.

Read more...
 
<< Start < Prev 1 2 3 4 5 6 7 8 9 10 Next > End >>

Results 43 - 48 of 287

More Changes, Anyone?

Copyright © 2008 John Kolbert. Visit the original article at http://simply-basic.com/general/more-changes-anyone/.
Anyone who’s followed me for any period of time knows that I like to change Simply-Basic’s appearance…     Readmore

Thoughts for the Week

Copyright © 2008 John Kolbert. Visit the original article at http://simply-basic.com/general/thoughts-for-the-week/.
Well another week down, and what a week it has been! Not only has it been busy…     Readmore

WP Advanced Code Editor

Copyright © 2008 John Kolbert. Visit the original article at http://simply-basic.com/announcements/wp-advanced-code-editor/.
For those interested, I wrote a plugin for Techlyzer.com that was just released. It’s called     Readmore

Check Out My Other Home: Techlyzer.com

Copyright © 2008 John Kolbert. Visit the original article at http://simply-basic.com/general/check-out-my-other-home-techlyzercom/.
Hi all. I’m happy to announce the launch of a new website that I’ll be trying to…     Readmore

Gadget Advisor Blog

Copyright © 2008 John Kolbert. Visit the original article at http://simply-basic.com/reviews/gadget-advisor-blog/.
Being a tech-centric blog I’m always on the lookout for other technology related websites. For those with…     Readmore

Updates to Permalinks

Copyright © 2008 John Kolbert. Visit the original article at http://simply-basic.com/announcements/updates-to-permalinks/.
After a lot of deliberation I’ve changed the permalink structure of Simply-Basic. When I started the blog…     Readmore

Qwest Web.Help: Stop Hijacking My Browser (How to Opt-Out)

Copyright © 2008 John Kolbert. Visit the original article at http://simply-basic.com/posts/1941493.
Earlier today I was surfing the web and mistyped a URL. Rather then getting the customary “The…     Readmore

Change Default File Type and Path for Screen Captures [Mac Tips]

Copyright © 2008 John Kolbert. Visit the original article at http://simply-basic.com/posts/1941482.
Mac only - I frequently use Mac’s built in screen capture ability to create the images you…     Readmore

Coming Soon: Comment on Lifehacker Using Your Facebook ID

Copyright © 2008 John Kolbert. Visit the original article at http://simply-basic.com/posts/1941478.
I just noticed that Lifehacker is joining the ranks of sites using the new Facebook Connect,…     Readmore

dealdotcom
Earn $$ with WidgetBucks!