In response to yesterday’s post about tweaking a multiple authors plugin for WordPress, my mother wrote me an e-mail with a link to the post and the word “Huh?” I just made another coding breakthrough on a project (breakthrough being relative; I only changed one line of code), and will discuss it below, but first here’s a mom-level description of yesterday’s post.
I’m creating an academic journal website for work. The website will use the same blogging software that this site uses: WordPress. WordPress is nothing more than a bunch of files that make a very simple (though robust) website, but those files happen to be editable by anybody. Thus, thousands of people make improvements to the code in those files, and then they share those improvements by blogging about them or submitting them to a site that organizes such things.
One limitation in WordPress as-is is that each post can only have one author—to “have” an author on a post not only means they are given credit for that post but that their name is linked to more information about them, such as contact information, other posts they have written, etc. Having a single author per post is fine if your site is a personal blog or even if your site has multiple authors writing their own things. But for a site that will be an academic journal, posts need to have two or more authors, as research is often conducted and written jointly.
Thus someone had to come along and rewrite (“hack”) or add to (provide a “plugin”) to the basic WordPress code. The author of the website Tempus Fugit did just that. However, his plugin automatically granted “authorship” to anyone who edits a post. (He had written the plugin specifically for a WordPress user who co-authored posts with his wife.) But for an academic journal, that wouldn’t do. Editors of a piece are editors; they are not authors.
So I had to rewrite code in the plugin—or, specifically, delete the code that automatically added any post’s editor as an author.
Meanwhile…
I’m a big fan of a plugin called Timeline. It’s what generates the scrollable archive on this site. And I’m going to use it on the new academic journal site.
But there’s a problem. Timeline’s code is written such that it grabs not just the posts but also stand-alone pages. That means it thinks my academic journal archive should include the “About” page and the submission guidelines and, ironically, the full archives page (it archived the archive!). But there’s a simple edit to the Timeline plugin that fixes this:
On line 692 add the limit AND post.post_type='post' so that the query looks like this…
// Build query to get posts
$Query = <<
SELECT
post.*
FROM
$wpdb->posts as post
$FromFilter
WHERE
post.post_status='publish' AND post.post_type='post'
$Filter
ORDER BY
post.post_date DESC
$Limit
EOT;
Narratively, that means this… Select all the information from the table called “post” from the WordPress database called “posts” (which by the way we’re going to rename “post” for some reason). Filter out specific categories of posts if the user specified such ($FromFilter). Of that information we got from the table “post”, only get that information if the post_status happens to equal “publish” (as opposed to draft or private) and where the post_type happens to equal an honest-to-goodness “post” (as opposed to those stand-alone pages). Then when that information comes back, make sure it’s sorted by date in descending order.
So what do we end up with?: a list of every post on the site (not including stand-alone pages) sorted from most recent to oldest. The plugin then goes on to insert that list into the pretty, styled boxes that show up in our sidebar.
Done and done!