WordPress Plugin: Custom post relationships (CPR) v1.01
June 10th, 2010 - Backend, Wordpress - 48 Comments
Update: Plugin is now hosted in the official Plugin directory: http://wordpress.org/extend/plugins/custom-post-relationships/

Hello everyone. It’s been a while since the last post but i think it’s worth it. It’s a wordpress plugin and it’s all about custom post relationships. All these years i was looking for a plug-in that would let me relate posts manually. None existed. All of the good ones rely on some short of algorithm and they pull a list of related post based on that.
In various projects all i need is a simple list of posts that i can relate to each other. And that’s what i did.
How it works
So first, download the plugin, extract and upload it to your plug-ins folder. Activate it and you are all set. If you create or edit a new post you will set a screen similar to the one above. You can choose how many posts you want to see, in what order, from what category to pull posts from and of course you can filter the results by typing a few letters from any part of the post title. Then all you have to do is add the posts to the Related Posted pane by clicking “Add”. In the related posts pane you have the ability to reorder the posts just by dragging and dropping.
And that’s it actually. Your post is now in a relationship with a series of posts that YOU chose. Can you imagine the possibilities?
How to display these posts
I have put a lot of thought on that. First i was thinking to create a shortcode that you could use in your posts but that approach was limited. So i decided to go with the “hand-coded” version which also provides a flexible way of displaying related posts. It’s very easy actually. If you have put your hands on wordpress templates file, you’ll pick this up in a minute. Here it goes.
Open your single.php file and locate the place that your want to display your related posts. Enter this piece of code:
<div id="related">
<h2>Related Entries</h2>
<?php
$relations = cpr_populate(get_the_ID());
if (!empty($relations)) {
echo "<ul>";
foreach ($relations as $related) {
echo "<li><a href='".get_permalink($related->ID)."'>".$related->post_title."</a></li>";
}
echo "</ul>";
}
else {
echo "<p>No related entries</p>";
}
?></div>
Presto! This small piece of code will create a new section (div id=”related”) with a section title (Related entries) and will display an unordered list with the related posts. If there aren’t any relationships set for a post a “No related entries” message will be shown. Have in mind that in the loop (foreach) you have access to every element of a post. For example if you want to display the thumbnail for a post (2.9.0) you could add the following to the code above:
get_the_post_thumbnail($related->ID, 'thumbnail')
This should go next to the post_title for example and display the post’s main thumbnail. Actually you can display anything. Even custom fields.
Current Version
Current version of Custom post relationships (CPR) works in WordPress 2.9.0+ including WordPress 3.0 RC1. For the time being it works only for posts. So no pages for now.
Future versions
I have already created a fork of this and i am working on a version just for WordPress 3.0 that includes custom content types and pages relationships. Expect though an options page for that as things are getting a bit more complicated for WordPress 3.0.
I hope you find this plug-in useful and i’d love to let me know how you use it. Also do not hesitate to share ideas and comments. Have fun!
Changelog
June 10th, 2010 : Initial release.
Junue 11th, 2010: “All categories” option added. (thank you: @christoschiotis)
120 new icons!
May 12th, 2010 - Design, Icon Sets - 3 Comments
My partner Helen, released a really cool new icon set of 120 amazing icons. In the zip file you will find 2 versions of the icons (48×48 – 68×68) and a vector version (AI – EPS files). Cool eh?
Class JS – Basic class structure in under a kilobyte of code
May 10th, 2010 - Frontend, Javascript - No Comments
Javascript freak? Do you need setters, getters, constructors and class extending capabilities? Class JS provides a basic class structure in under a kilobyte of code.
jQuery Offline plugin
May 7th, 2010 - Frontend, jQuery - No Comments

jQuery offline plugin provides a mechanism for retrieving and storing data through JSON on the client side. While the plugin makes use of the HTML5 localStorage API for persistence, the plugin will fall back to making a request to the server each time for browser that don’t support localStorage. The author states that jQuery Offline should be used in conjunction with Rack::Offline for automating the process of generating a cache manifest and jQuery-templ for taking a javascript object and producing the necessary HTML out of it.
Pagination with jQuery: Sweet Pages
May 6th, 2010 - Frontend, jQuery - 1 Comments
A jQuery plugin and a tutorial on how to paginate small sets of data on the client side using jQuery.





