Splitting WordPress content with ‘more’ on single pages
WordPress uses the "More" button to create a small snippet of content, usually used on the blog page, to create article teasers and such. WordPress ignores the "More" function on single posts, pages and several other pages.
Here's some code of make use of the "More" function on single pages and single posts. Perhaps splitting the content into columns or hiding extra content in an accordion or pretty much anything. Look, I'm going to press the "More" button right now.
WordPress Archive Redirection (Single Items)
If you are using the standard archive-[custom-post-type] and single-[custom-post-type] theme structure for your Custom Post Types, you may come across a situation where the archive-[custom-post-type] needs to redirect to your first custom post. So, rather than duplicate code across templates. Duplicate code is messy code. You can use the wp_redirect function.
[Snippet] How to install cron (crond, crontab) in CentOS
Sometimes small installations of CentOS don't come with cron. Here's how to install cron easily and quickly.
- yum install vixie-cron crontabs
- /sbin/chkconfig crond on
- /sbin/service crond start
See my retro post I hate vi. (aka Changing your default crontab editor) for how to change the editor from vi to nano.
Overwriting WordPress loop parameters per page
In some instances you may want to overwrite WordPress loop parameters per page.
For example, a recent request from a client
"Can I have all my portfolio items on a single page?".
Yes, client, you can. "Portfolio" is a custom post type. Using Everett's Custom Content Type Manager. The theme is fully structured so it uses single-custom-content.php and archive-custom-content.php.
Prevent images from displaying while loading with AnythingSlider
AnythingSlider is just another jQuery slider effect, except we can embed any content as it uses a semantic unordered list HTML (5) structure.
My recent client wanted a mixture of HTML, videos and images, which means you get the nasty flash of the UL elements whilst your browser renders the window. Apparently its called Flash Of Unstyled Content (or FOUC). Whatever. Its called really annoying to me. So here is a bit of code that should be included in the default anythingslider.css but isn't for some reason.
[Snippet] Formatting the date in twitter XML feed
The date in the Twitter XML feed is daft and ugly! It reads [created_at] => Wed Aug 03 23:34:35 +0000 2011
We can easily format this with PHP using date() and strtotime()
Using the Twitter XML Feed in PHP
Parsing the Twitter XML feed for a user in PHP is now super simple.
- $username = 'Kieran_Barnes';
- $format = 'xml';
- $tweet = simplexml_load_file("http://api.twitter.com/1/statuses/user_timeline/{$username}.{$format}");
Disabling Core Dumps
I recently found a (cPanel) server was generating over 100Gb of core dumps every time a bad PHP script died or Apache died. Writing these generally useless (who actually debugs these on a live web server) to disk is a pointless waste of disk I/O, especially in a VPS environment.
Here is two methods of disabling core dumps;
Custom Shopp Gallery with FancyBox
Following on from a previous post Custom Shopp Gallery, here is how to do make a custom Shopp gallery with FancyBox.
Removing l10n.js in WordPress
l10nn.js is a JavaScript library that enables localization through native JavaScript methods, gracefully degrading if the library is not present. WordPress 3.0 enables l10n.js by default and most of the time if you are working on single language, non-localised WordPress sites, you can safely disable it and save yourself a few bytes of code at each page load.
Clean code is happy code!



