Archive for the ‘WordPress’ Category

Using Wordpress (with some modifications) as a CMS

Thursday, January 17th, 2008

For a long time one of the things I’ve liked about Wordpress is it’s flexibility. I recently did a project for Savvydog Design for one of their clients: the National WASP WWII Museum - that involved doing some customizations to Wordpress. They wanted most of the pages on the site to be editable (I used Wordpress’ pages functionality here), they also wanted to be able to enter in news items (these would be standard blog posts with a category of “news”), as well as be able to enter in events (these would also be standard blog posts with a category of “events”). They wanted the home page of the site to show some (editable) content at the top, and then list the last 3 news or event items. On the side bar, they wanted to be able to list the next 3 upcoming events. Here is how I put it all together:

*Please note - some of the customizations take a few things as assumptions - (for example how you have your permalinks set up, etc.) So if you use any of this, do so at your own risk (most especially the part about editing a core Wordpress file - I’m sure I’ll get heat for that from SOMEONE.) Your mileage may vary, and I don’t guarantee this will work with your setup, yadda yadda yadda…
(more…)

Next Previous Posts in Same Category

Tuesday, December 4th, 2007

I’ve gotten a few emails about my (old) Next/Previous Post in Same Category plugin and about the fact that’s its broken - however, this functionality is now built into wordpress. (and I have it working on the site right now as a matter of fact). I’m a bit behind on what has been included with each new version of Wordpress, so I’m not sure when this made it’s way in there, but.. YAY! Now I don’t have to update the plugin! LOL! So, in any case, if you want to include links to the next/previous post in the same category as the one being viewed, you just need to do this (on the “single.php” template page INSIDE the “Loop“)

<?php previous_post_link('&laquo; %link', 'Previous post in category: %title', TRUE); ?>
<?php next_post_link('%link &raquo;', 'Next post in category: %title', TRUE); ?>

Where the first argument (where I have “&laquo; %link”) is the format of what is displayed… ie. if you want text before or a tag around the actual link (represented by “%link”) this is where you say how you want it to show.

And the second argument (where I have “Previous post in category: %title” is the text of the actual link. You don’t have to have the “%title” in there - but I think it’s useful) :)

Insert text/image block in the middle of a WordPress category page

Saturday, May 5th, 2007

For a long time I resisted the urge to put ads on the site. I’m sure you’ve noticed I finally caved in this past year. I’ve tried to keep it relatively unobtrusive. In one case I was contacted directly to put an ad up on one of my category pages in the content area. I didn’t want to put it at the top above the content. Ideally - I wanted it put in the middle in a separate div block, maybe after 3 or so posts, but only on the first category page. Here is the code I used to get that to work…

First, above the loop I added this:
<?php
$count = 0;
?>

This is to count the number of posts we’re on.

Then just after the end of the loop call (<?php while (have_posts()) : the_post(); ?>) but before you start the code for the posts, I added this:
<?php
if ($wp_query->get("page") || $wp_query->get("paged")) {
$onFirstPage = false;
} else {
$onFirstPage = true;
}
?>

That bit of code I got basically from this post on the support boards.

Then to determine if we should call the text for the ad (in this case I wanted it displayed only on category id #29), and to then display the ad…
<?php
if (is_category('29') && $count == 2 && $onFirstPage) {
?>
...ADVERTISEMENT TEXT OR IMAGE GOES HERE...
<?
}
$count++;
?>

Listing subpages in Wordpress

Monday, April 30th, 2007

I was looking for a way to list sub pages in a navigation bar if you were either on the “parent” page or one of it’s sub pages. I found this page on Clioweb that was perfect.

What’s also nice is that it gives you the variable $parent_id to play with if you need to. Copied from his site:

<?php
$page = $wp_query->post;
$parent_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE ID ='$page->post_parent;'");
if(!$parent_id) $parent_id = $post->ID;
?>

Then, to actually generate the HTML for the page list, I use the following code in the body of my page template:

<?php if(wp_list_pages("child_of=".$parent_id."&echo=0")): ?>
<ul id="subnav">
<?php wp_list_pages("title_li=&child_of=".$parent_id."&sort_column=menu_order&depth=1");?>
</ul>
<?php endif; ?>

Wordpress: Make home page show latest post (in the “single post” format)

Saturday, April 28th, 2007

In a custom wordpress theme design I was working on tonight, I was trying to do as the title describes - make the home page show only one post (yes I know there’s already a built in way to do this) but I wanted it to show up the same way the single view shows it - with the comments expanded and the comments form visible, etc. If you know of another/better way to do this, please say so in the comments. But this DID do the trick. I found this page in the support archives. The idea was to create your index.php to look like you wanted (ie. exactly like the “single.php” page) but add this before you start the loop:

<?php
$i=0; // Initialize to Zero;
if (have_posts()) :
while (have_posts()) : the_post();
if ($i==0) {$recentpostid = $post->ID; $i=$i+1;}
endwhile;
endif;
//get only the latest post
$posts = query_posts( 'p='.$recentpostid."'");
?>

and then you start your loop like you normally would…

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Worked for me!

Update As Danny pointed out in the comments - there’s a simpler way to do this. Put the following code on the page (I put it before the loop and it worked)
<?php $wp_query->is_single = true; ?>
Much simpler :)

Decoder Button

Saturday, December 23rd, 2006

Had to create a plugin. Guess this means I’m getting back in the groove. ;P Referring back to these posts, this plugin will make a button on your edit post/page making it possible to paste some code you wanted to show, select the code, then click “decode” - which will convert your < to &lt; and > to &gt; in the selection - so that it doesn’t break your page.

Installation instructions:
Download the Decoder Button plugin. (Save that page and just make sure the rename it to “decoder_button.php”) Upload it to your wp-content/plugins folder, and activate on the plugins page in your wordpress admin interface.

Overcoming the upgrade

Friday, December 22nd, 2006

I’ll make notes of issues I ran into and the solutions as I go along, but so far I’ve had two three issues come up when upgrading.

1) When I ran the upgrade, it sort of died before finishing… I refreshed and it told me it was all set. Checked on the main page, and everything seemed to be okay - but when I logged in to start tinkering around with the settings, I couldn’t log in completely. I got the dashboard with no navigation and then I clicked on something and all it wanted to do was send me to the profile page - but with nothing showing except “You do not have sufficient permissions to access this page”. Googled for a solution and found one on Mark’s site. Ran his script, and all was well again.

2) Then I discovered that clicking on the the “previous entries” link at the bottom sent me to a “page can not be found” error page. Google to the rescue - and found one on the Wordpress Codex… (scroll ALLLL the way down to “Paged Navigation doesn’t work” - There it will tell you that the error I was getting was due to the .htaccess file that WordPress generates. Delete the contents (or at least the wordpress stuff in there) and manually add the code back in from the Options -> Permalinks page. Again, all was well again.

3) This one was really weird. I had a post that was showing up in Firefox but not IE. It was like it didn’t exist at all on IE. Wasn’t in the source. Try to pull up the post page, and it gives you a 404 error not found. Turns out - and maybe this was because of the glitch during the upgrade - the post didn’t have any status indicated. It wasn’t marked as “Published”, “Draft”, or “Private”. (The weird thing is that, then WHY did Firefox show it at all?!?) Anyway, clicking the “Published” box and re-saving the post seemed to fix the problem.

If you find any other broken links or errors, etc. - please let me know!

Show Hide More - alive again in “collapsable more link”

Wednesday, June 8th, 2005

I’m still buried in boxes - and probably will be for some time to come. The move is going a little more bumpy than expected. It’ll get better, but not for awhile unfortunately…

In any case, I’m glad to see that some of my older plugins are getting a facelift in newer work:

Collapsable More Link plugin
[found via Blogging Pro]

Plugin Competition

Saturday, May 7th, 2005

While I *really* wish I could enter into the Wordpress plugin contest - the fact of the matter is my schedule doesn’t open up until next month - after the contest has closed for judging. But it sounds like it will be run again - so I should be able to enter it next time.

In any case - if I need ideas for plugins to “get back into the swing” - hopefully this “developers wanted” list will still be up and running in June.

Lazy Gallery Plugin

Monday, April 18th, 2005

I haven’t been posting links to new plugins as they’ve been coming out - Weblog Tools Collection and Blogging Pro are possibly the best places to look for that - but I still want to make note of plugins that I KNOW I’ll want to use in the future…

Lazy Gallery Plugin
Point to a folder with images and read it…

[via Blogging Pro]