Archive for the ‘WordPress Hacks’ 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…)

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 :)

Notify users of comment moderation

Friday, October 29th, 2004

Feedback to users about what is happening on the site is always a good thing. Especially if it’s to tell them why a comment they just submitted is not appearing on the site.

WordPress Hack: Notify Users of Moderation
Mark has a hack that will pop up a javascript alert to let users know when their comment is going into moderation. (This way they don’t think the comment just got “lost” and submit it again)

[found via Blogging Pro]

The redesign of Pixelog.org

Thursday, October 21st, 2004

One of the things that drove me to WordPress was the fact that it was PHP based. It leaves the doors wide open for you to do practically any kind of hack you could possibly think of.

I recently reworked Pixelog.org for Christine. The original was a table based design, powered by MT. Now it’s all CSS based, valid XHTML 1.0 Strict, and powered by WordPress!

However, to get everything to work just so I had to pull a few tricks….
(more…)

Allow only registered users to post comments

Saturday, July 31st, 2004

This isn’t really new - but just stumbled on this post in the wp forums and wanted to save the link in case I ever needed it.

WordPress Hack: only registered users can post comments

Google Hi-Lite fix

Sunday, July 4th, 2004

Peggy emailed me about a problem I was having on this site with the Google Hi-Lite plugin that’s included with 1.2. She did all the searching to find the fix the problem (which was posted on huddledmasses.org here ) (So all credit for finding this goes to her) Certain searches (I think ones that contain a backslash - you know how WP eats these for breakfast) ;-) will cause errors on the page.

Here’s what you need to do to fix it. Look for these lines (should be Orig lines 104, 105, 106, 107)

if (!preg_match(’/<.+>/’,$text)) {
$text = preg_replace(’/(b’.$term.’b)/i’,'<span
class=”hilite”>$1</span>’,$text);
} else {
$text = preg_replace(’/(?<=>)([^<]+)?(b’.$term.’b)/i’,'$1<span
class=”hilite”>$2</span>’,$text);

Change those lines to this:

if (!preg_match(’«<.+>«’,$text)) {
$text = preg_replace(’«(b’.$term.’b)«i’,'<span
class=”hilite”>$1</span>’,$text);
} else {
$text = preg_replace(’«(?<=>)([^<]+)?(b’.$term.’b)«i’,'$1<span
class=”hilite”>$2</span>’,$text);

Add a “remember me” checkbox to the login form

Thursday, July 1st, 2004

Neil had asked about adding a “remember me” checkbox to the login form. The idea here is that if you’re really forgetful (like me! Ack!) and you know you’re really forgetful - and you know you’re probably going to forget to “logout” before closing your browser - if you don’t click the “remember me” checkbox - then when you close your browser, you will be automatically logged out of WordPress. (This is good when you’re working on a shared computer)

It does require some core WP editing - minor tweaks to just the wp-login.php page - but wanted to warn you up front (I have to apologize for the core edits. I’m more than welcome to hear suggestions of how one can do this WITHOUT doing the core editing - but I just can’t come up with it)
(more…)

Comment Moderation - Select all for delete

Wednesday, June 30th, 2004

My spam words list is pretty good and has been catching almost all spam (and very few “legitmate” comments) - however, my complaint has been that the moderation page makes you manually select under each and every comment, the delete “radio” button. If a lot of comment spam has been thrown into moderation, I want an easy way to “select all for delete”. So I wrote a little javascript that you can add to your moderation.php page (in wp-admin folder) (yes, sorry, core wp file editing - if you have another way - suggest it) that will auto-select the “delete” radio for all comments on the moderation page.
(more…)

Removing “curly” quotes

Monday, June 14th, 2004

I’m not a big fan of the “curly” quotes. Wordpress does them automatically - but this can really mess you up if you’re copying and pasting code from a post. So I’ve turned them off…

As seen on this thread on the WP support forum - I’ve commented out all the lines at the end of vars.php (found in your includes folder) that look like this:

add_filter(’the_SOMETHING‘, ‘wptexturize‘);