in » Resources

WordPress Customization Notes

These are my notes on customizing WordPress. I must thank, and congratulate, the folks at both WordPress and the WordPress forums, and those who create plugins, for providing and supporting such a brilliant tool. As always, I promise nothing and take no responsibility for anyone's results; the following information is used at your own risk, without warranties or promises of any kind.

WordPress Customization
A lot of this is from the WordPress 1.2 days, but may be helpful.

Plugins & extra code I've used

WordPress Links — External Pages

 

line image

WordPress Installation

I used the standard 5-Minute Installation.

line image

Making Templates

WordPress uses index.php as its template for all blog pages (except for the backend Admin area). If you want separate templates for other pages (whether to pull posts from the database, or otherwise), a copy of index.php will do. Although the underlying page coding can be a bit blinding if you're not familiar with PHP (or HTML), in essence, you would remove anything you wish; whether you remove the header, footer or menu is up to you.

To use a copy of index.php for pages *not* pulling posts from the database, simply remove The Loop (the link goes to the WordPress Wiki).

The coding I used for the category page on this site is below.

line image

Prettified URLs without Broken Links

WordPress allows the option of converting the default URLs (site.com/index.php?p=6) to URLs based on the page title (site.com/word-based-URL/), utilizing mod_rewrite to direct visitors to the correct pages. The problem with this is that some links -- Category, Date, etc. -- may break. If they do, then the solution, whichever URL version you choose, is to ensure that the year, month and day are included:

Options/Permalinks
/%year%/%monthnum%/%day%/%postname%/

Don't forget to pick up the mod_rewrite code in the box lower on the page; paste it into a text editor (e.g., NOT Word), save it as .htaccess and upload it to your root directory.

line image

Multiple Templates without Broken Links

Since the default WordPress installation uses one template for all pages, all pages generally look alike ... the logo, followed by a post. Even for those familiar with blogs, it can be confusing and difficult to determine whether you're on the home page, in a Category or on a post's permanent page, etc. without scouring the page for clues. I felt that usability (and, perhaps, courtesy to visitors) dictated that we do more to identify just where/what any given page might be.

The answer was multiple templates (which I prefer over piling if/else statements on the one template), but this is not as simple as it sounds. I've cobbled together tips from the WordPress forums to make it work without breaking the post links, annotated here from my original post.

I was having problems with URLs breaking when using multiple templates and the prettified URLs (URLs based on the page title). Depending upon what I'd change, the links would break in the categories, archives or the calendar. Fix one thing and another set of links would break. Over and over. This is the method I used to utilize different templates for single post pages (the permalink pages) and categories without breaking other links (and thanks to all whose tips and hints helped):

(1) URLs. For the nice text URLS, the URL *must* contain year, month, day. From testing the multiple templates, it appears that monthly archives, categories, etc. call info from the database in different ways, and removing certain portions of the URL structure above seemed to give problems. For instance, I didn't want the day in the URL, but remove it and the calendar links go kabooie. So:

Options/Permalinks
/%year%/%monthnum%/%day%/%postname%/

(2) mod_rewrite. Put the mod_rewrite code in the text box near the bottom of the page into your .htaccess file and upload it.

(3) Templates. Make the alternate templates, but do NOT name one category.php; "category" appears to be a word reserved by WordPress for its own use.

(4) More mod_rewrite. Open the .htaccess file and convert:

RewriteRule ^category/?(.*) /index.php?category_name=$1 [QSA]

to

RewriteRule ^category/?(.*) /categorypage.php?category_name=$1 [QSA]

I am not saying this is the only way; I suspect that better mod_rewrite and/or messing with the .php files can do it, but this works. We are using different templates for single post (permalink) and category pages without breaking links.

line image

Category Page as an Index

Next, I felt the Category page should be an index of links to posts for any given category, rather than the default display of all posts in that category:

<ul> <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
<li id="catpost-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"> <?php the_title(); ?></a><br />
<?php the_excerpt() ?> <?php the_author() ?> ~ <?php the_date(''); ?> at <?php the_time() ?></li>
<?php endforeach; else: ?> </ul>

<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

line image

Menu falls below content

I posted this at the WordPress forums, but it'll likely get lost, so:

Having the menu mysteriously fall below the content is one of the gotcha's of changing WP's layout to fixed width. Initially, WP's layout is "fluid" -- meaning it expands to fill the screen -- and the menu is (or was) set to adhere to the right side of the screen and has enough margin/padding to keep the content away.

When changing the layout to fixed width, the first thing you'll find is that at higher resolutions, your menu moves out of the content area and sits, all by itself, at the right of your screen. Fix that by fiddling with the CSS, and the menu may mysteriously fall below the content.

What's happened is that the menu's margin/padding (which served as a buffer between the content and menu and which doesn't show since it is, after all, blank space) are now too large to be contained in the space to the right of the content. Worse, Internet Explorer does it's famous make-me-crazy "you asked for a 40-pixel margin, so obviously you want us to double it to 80 pixels" display. These are just things to know, and easy enough to fix given some time to sort through what's causing what.

A good CSS trick is to put borders on the areas that are giving you trouble ... in which case you'll see why the menu falls below the entire content area ... it's just too large to fit.

line image

Lost Password Email Bug

So you forgot your password; you ask WP to email it to you; it never arrives. Get the fix-it code at the WP forums.

line image

SiteMap - Nicer Sortable Archives

Our Site Map was made using the narchives (nicer sortable archives) from weblogtoolscollection.com. (Thanks!)

Add this to top of page (I think I ended up hard-coding our URL):

<?php /* Don't remove this line. */ require('./wordpress/wp-blog-header.php'); $single = 1; $siteurl = get_settings('http://yoursite.com/'); ?>

If prettified URLs are enabled, the site map links break on multiple-word category titles. Around line 121, change:

$output .= '<strong><br /><br /><a href="'.$siteurl.'/'.$blogfilename.'?m='.$thisdate.'">'.$month[$thismonth].' '.$thisyear.'</a></strong>';

to

$output .= '<strong><br /><br /><a href="'.$siteurl.'/'.$thisyear . "/". $thismonth.'/">'.$month[$thismonth].' '.$thisyear.'</a></strong>';

Around line 134, change:

$output .= '<br/><br/><strong><a href="'.$siteurl.'/'.$blogfilename.'?cat='.$thiscategory.'">'.get_catname($thiscategory).'</a></strong>';

to

$output .= '<br /><br /><strong><a href="'.$siteurl.'/category/'.sanitize_title(get_catname($thiscategory)).'/">'.get_catname($thiscategory).'</a></strong>';

line image

ScriptyGoddess Comment Email Notification

Jennifer/ScriptyGoddess' script to allow people to opt in to post threads to which they've commented. Also allows them to unsubscribe themselves. Nice stuff well done. My instructions are for WP 1.2-1.5, but probably will work more or less in 2.0+.

» The script at scriptygoddess.com

1) Upload subscribe-to-comments.php to wp-content/plugins/

2) upload wp-subscription-manager.php to the top level of your wordpress install directory (same directory wp-config.php is in)

3) Add the following inside your comments form (between your <form> </form> tags) (in wp-comments.php and in wp-comments-popup.php):

<p>
<input type="checkbox" name="subscribe" id="subscribe" value="subscribe">
<label for="subscribe">Subscribe to comments (Email field must be filled in)</label>
</p>

3a) OPTIONAL
If you'd like to display on your comments if a particular commenter is subscribed to comments or not - you can use this function: comment_subscription_status() like this (customize for your own use)

<?php comment_text() ?>
<p><?php comment_type(); ?> <?php _e("by"); ?> <?php comment_author_link() ?>
<?php if (comment_subscription_status()) { echo "(subscribed to comments)"; } ?>
etc. etc. etc.

[comment_subscription_status() function thanks to Mark: http://www.TxFx.net]

4) Activate the subscribe-to-comments plugin through the WordPress plugin admin page. You're done :)

5) **Optional change:**
When emails get sent to commenters who have subscribed to comments - the default "from" will be your blog's name and your admin email address.
If you want to change this, open the subscribe-to-comments.php plugin and change the two lines as appropriate (these are towards the top of the page):

$emailContact = "email@example.com";
$nameContact = "YOUR NAME";

If you want to leave them as the default - DO NOT CHANGE THE VALUES.

ADDITIONAL NOTES:
Using this script, people may accidentally ask to be blocked from all emails from the site.
To remove this block:
1) login to WordPress (user needs to be a level 10) - do NOT logout.
2) Then visit the wp-subscription-manager.php page - enter in the address that has the block on it
3) The page will recognize your wordpress login cookie and give you the option to remove the block.

Archives
© 2004-2014 DianeV Web Design Studio. All Rights Reserved.
17 queries. 0.182 seconds.