12th August 2010
I’ve not really used sticky posts in WordPress. I’ve just been hacking around to try and use this system instead of my own custom field checkbox for “featuring” posts. There’s some definite pros: the user can toggle the status via the Quick Edit feature instead of having to edit the whole post. There’s also some cons: the sticky posts system has some quirks which, while understandable, limit it slightly.
One niggle is that sticky posts in standard post loops only really impact things (i.e. bubble to the top) when is_home() is true. The real killer is that when you’re only outputting a certain number of posts, using, say, get_posts and the numberposts argument, if there are sticky posts, you’ll get the sticky posts plus the number of posts you specify from the rest of the posts. So if you ask for 3 posts and there’s 1 sticky post, you’ll get 4 posts in total. Grrr!
This is acknowledged in a couple of trac tickets. There are reasons for this—it’s a feature, not a bug, as they say—but what do you do if want to do things your way?
Read more »
Permalink |
Posted in WordPress |
No comments yet » |
12th August 2010
The introduction of custom menus in WordPress 3.0 was very welcome. They can be a bit baffling at first (see the ever-reliable Justin Tadlock’s guide if you’re confused), but they’re a great CMS addition to WP.
Here I want to detail a couple of tips for going beyond the standard usage.
Read more »
Permalink |
Posted in WordPress |
No comments yet » |
5th August 2010
I’ve recently been looking at de-cluttering the WordPress admin interface. There’s some good plugins for this, such as Adminimize, WP-CMS Post Control (for hiding boxes on the post screen, according to user role) and White Label CMS (for extensive customization of logos, menus, etc.).
As ever, I’m also interested in getting just a particular aspect working with a bit of theme code—if only one aspect is needed, it’s sometimes nice to drop it into the theme and have one less plugin loading. The aspect I’m thinking of here is removing a few menu items.
So, with the usual caveat that this is code for theme developers, to be dropped into the active theme’s functions.php file, and a nod to hungred.com for initial inspiration, here goes.
Read more »
Permalink |
Posted in WordPress |
12 comments » |
19th July 2010
I’m just back from WordCamp UK 2010 in Manchester. Another inspiring gathering of WordPress people, from the curious to the obsessed, with a fantastic, vibrant city as the backdrop.
I’m too exhausted now for a detailed write-up, but I want to jot some things down while they’re fresh. Here’s the main things that stick in my mind…
Read more »
Permalink |
Posted in WordPress |
15 comments » |
9th June 2010
I periodically get queries about WordPress issues through this site, often in relation to code I’ve posted here. These days I’m usually far too busy to go into deep, free coding consultation; and usually when I do help out I’m just Googling and using the same resources available to everyone.
I totally appreciate that I might have much more experience than some people, and I’ll have a few little hints that could save a lot of time. But sometimes people emailing me seem to be doing something that I fully confess to being guilty of, in the past and even now: shouting out for help too soon instead of stepping back and tackling the problem properly.
So, here’s a little guide I can point people to, partly in lieu of an email reply template. If you’re facing a WordPress coding problem that either looks daunting right from the start, or is driving you insane after hours of trying, the following hints can help a lot.
Read more »
Permalink |
Posted in WordPress |
Comments closed |
9th April 2010
Here we go with some more nifty code for you WordPress developers… As ever, this code is roughly tested but probably not for novices. It’s designed to drop into a custom theme’s functions.php file. It probably should be a plugin, and it might make it one day when it’s thoroughly tested and I get time…
Anyway, it’s a solution to a problem that I’m very surprised isn’t built into the WP core (as an option at least), and isn’t addressed by any easily found plugin or code already out there. As we know, WP provides a good “password strength meter” on the user profile page, which is great as strong passwords are (or should be) one of the first lines of defence against attacks on your site. But it’s just an indicator—there’s nothing stopping someone using “password” as their password, or something dumb like that. All you need is one Administrator or Editor with a dumb password, and the whole site is highly vulnerable.
How about a little enforcement?
Read more »
Permalink |
Posted in WordPress, security |
4 comments » |
20th March 2010
I find PHP’s date handling a bit confusing. It’s easy when you know how, of course; but even at the same time as appreciating that it’s good in the end that it offers a lot of flexibility, it’s sometimes seemed like there are too many hoops to jump through to do some simple date operations.
Anyway, I’ve just cracked a minor issue I’m working on thanks to this post and this thread. I’m posting the solution here for my quick reference as much as anything…
Problem: how to check if a WordPress post_date (from a $post object) is from a day in the future? Solution:
$postDate = strtotime( $post->post_date );
$todaysDate = strtotime( date( 'Y-m-d' ) );
if ( $postDate > $todaysDate ) {
[ post is from the future! ]
} else {
[ post is from today or the past]
}
Permalink |
Posted in WordPress |
2 comments » |
22nd November 2009
Most WP developers know by now that the right way to add script libraries from a plugin or theme is to use the wp_enqueue_script function. It makes sure scripts aren’t loaded more than once, and so on.
However, I just had some problems getting some jQuery to run on the login / registration form. I used wp_enqueue_script like a good WP developer but… no go. Where’s my jQuery?
It seems the answer lies in the fact that after scripts are enqueued in a normal WP page, they get spit out by something inside the call to wp_head(). I guess you could add wp_head() to the login header, but who wants all those redundant plugin scripts and styles that (presumably) aren’t even meant to be there.
After a bit of digging around it seems that the solution is the wp_print_scripts() function. So, to get jQuery working on the login form, put these lines in the code you hook onto login_head:
wp_enqueue_script( 'jquery' );
wp_print_scripts();
Permalink |
Posted in WordPress, jQuery |
No comments yet » |
11th November 2009
Here’s a quickie that can help with WordPress sites that have a lot of pages. If some of the pages have longish titles, the “Parent Page” drop-down on the edit page screen can get unwieldy. The scroller for the drop-down can run off the right side of the screen.
OK, it’s fine (often easier) to use the keyboard to navigate drop-downs. But not everyone knows how to, and even so, with a large amount of pages, selecting the right parent can become a pain.
I think I adapted the following code from a plugin or someone else’s post. Thanks whoever you are, but frankly I’m so busy at the moment I’ve forgotten where it came from! Anyway, if you drop the following into your custom theme’s functions.php, you’ll get a new “Create child” link under every page listed in WP admin, when you hover over the title:
function slt_childPageAction( $actions, $page ) {
$actions["create-child"] = '<a href="/wp-admin/page-new.php?parent_id=' . $page->ID . '" title="Create a new page with this page as its parent">Create child</a>';
return $actions;
}
add_filter( 'page_row_actions', 'slt_childPageAction', 10, 2 );
function slt_setChildPage() {
global $post;
if ( $post->post_type == "page" && $post->post_parent == 0 && isset( $_GET["parent_id"] ) && is_numeric( $_GET["parent_id"] ) )
echo '<script type="text/javascript">jQuery( document ).ready( function($) { $("#parent_id").val("' . $_GET["parent_id"] . '"); } );</script>';
}
add_action( 'edit_page_form', 'slt_setChildPage' );
The first bit adds the page action link. The second bit adds some jQuery to the right edit screen to set the specified parent, if it’s been passed. I couldn’t find another way to set the drop-down… Well, it works!
Permalink |
Posted in WordPress |
No comments yet » |
30th October 2009
I’m currently working on a client’s WordPress site where there’s quite a few bits of custom functionality in my custom theme that rely on them entering values for posts or pages using WP’s custom fields.
Custom fields are really flexible. However, they’re not perfectly user-friendly. For instance, if no post or page is currently using a custom field that you’ve built functionality on, the user has to enter the name as well as the value of the field the first time it’s used. The drop-down of field names is dynamically gathered from the fields currently in use. Also, sometimes you want to make things easier for clients by having inline tips, and inputs that suit the field (e.g. a checkbox or select drop-down instead of just a plain text entry).
So, I set about piecing together a way to take over the Custom Fields meta box…
Read more »
Permalink |
Posted in WordPress |
52 comments » |