Jan 25 2007

Another post to confuse my mother

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!


Jan 24 2007

Multiple authors per post in Wordpress

Over on an academic journal site I’ve been setting up, I needed a way to assign multiple authors for a single post. Tempus Fugit developed a plugin to do just that, except it makes the assumption that anyone who edits a post should be listed as an author—true for blogs, not true for a site with editors posting others’ work. Here’s a simple fix, though, for anyone using Tempus Fugit’s multiple authors plugin…

In the plugin’s php file, delete the function that equates a post editor as an author:

function txfx_oa_add_author($post_ID) {
global $wpdb, $userdata;

if ( !$userdata ) get_currentuserinfo(); // shouldn't be needed, but can't hurt

$main_author = $wpdb->get_var("SELECT `post_author` FROM $wpdb->posts WHERE `ID` = '$post_ID'");

if ( $userdata->ID == $main_author ) return $post_ID; // the person who created the post is editing it... do nothing

// if we're still here, it must be a new author, so see if they are already logged as an author on this post
if ( $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = 'other_author' AND post_id = '$post_ID' AND meta_value = '$userdata->user_login'") ) return $post_ID;

// if we're STILL here, it's time to add this author
add_post_meta($post_ID, 'other_author', $userdata->user_login);

//and we're done
return $post_ID;

}

And at the very bottom of the file, to keep the file from breaking, delete the commands to add that now-ignored editor as an author:

add_action('edit_post', 'txfx_oa_add_author');
add_action('save_post', 'txfx_oa_add_author');

Done and done! Adding an author is manual now—you just add a custom field called “other_author” and type in the second (or third or fourth) author’s name in the “Value” box. And so long as it matches the name of a registered user, that person will be duly added as an author to the post.


Jan 21 2007

Cheers for Firebug; jeers for Lightbox2

For a while now I’d noticed FC was loading funny. That is, it wasn’t loading. All the content would be there, but the browser would keep churning away at something.

Then I got a couple messages from readers that the problem was manifesting itself more maliciously in other browsers: the site wasn’t loading at all.

The issue is fixed, so it’s not that big a deal, except that it offers another opportunity to tout the Firebug plugin for Firefox. Another of its invaluable features for examining websites is a realtime graph of the browser’s loading of every file on a page—every image, every script, every stylesheet import:

firebug screengrab

The problem turned out to be the Lightbox2 plugin, at least in combination with the other Wordpress image plugin used on this site. I’m not good enough with PHP to say exactly what’s wrong, but Firebug indicates that dozens of functions (or one fuction dozens of times) within Lightbox2 fail to resolve successfully. This after an updated version of Lightbox2 was made available to address this very problem.


Dec 7 2006

Best. Firefox extension. Ever.

Firebug logoA solid percentage of Fungible Convictions readers are bloggers too, and a solid percentage of you designed your own site. If so, USE THIS EXTENSION.

Roger Johansson’s indespensible blog 456 Berea Street has drawn attention to a stunningly well-thought-out Firefox extension called Firebug. For advanced and beginning developers alike, Firebug is the Web Developer extension on steroids, crack, and Cezanne.

Just look at these features!

  • Just the way you like it: Firebug is always just a keystroke away, but it never gets in your way. You can open Firebug in a separate window, or as a bar at the bottom of your browser. Firebug also gives you fine-grained control over which websites you want to enable it for.
  • Inspect and edit HTML: Firebug makes it simple to find HTML elements buried deep in the page. Once you’ve found what you’re looking for, Firebug gives you a wealth of information, and lets you edit the HTML live.
  • Tweak CSS to perfection: Firebug’s CSS tabs tell you everything you need to know about the styles in your web pages, and if you don’t like what it’s telling you, you can make changes and see them take effect instantly.
  • Visualize CSS metrics: When your CSS boxes aren’t lining up correctly it can be difficult to understand why. Let Firebug be your eyes and it will measure and illustrate all the offsets, margins, borders, padding, and sizes for you.
  • Monitor network activity: Your pages are taking a long time to load, but why? Did you go crazy and write too much JavaScript? Did you forget to compress your images? Are your ad partner’s servers taking a siesta? Firebug breaks it all down for you file-by-file.
  • Debug and profile JavaScript: Firebug includes a powerful JavaScript debugger that lets you pause execution at any time and have look at the state of the world. If your code is a little sluggish, use the JavaScript profiler to measure performance and find bottlenecks fast.
  • Quickly find errors: When things go wrong, Firebug lets you know immediately and gives you detailed and useful information about errors in JavaScript, CSS, and XML.
  • Explore the DOM: The Document Object Model is a great big hierarchy of objects and functions just waiting to be tickled by JavaScript. Firebug helps you find DOM objects quickly and then edit them on the fly.
  • Execute JavaScript on the fly: The command line is one of the oldest tools in the programming toolbox. Firebug gives you a good ol’ fashioned command line for JavaScript complete with very modern amenities.
  • Logging for JavaScript: Having a fancy JavaScript debugger is great, but sometimes the fastest way to find bugs is just to dump as much information to the console as you can. Firebug gives you a set of powerful logging functions that help you get answers fast.

My favorite feature so far was one I’ve been pining for for years: you can use Firebug to select an element on your page and it will a) tell you all the CSS that affects that element and b) of that, cross out the CSS that is overridden by other styles.

It’s brilliant.


Dec 5 2006

Site credits

Thanks first to all you Fungible Convictions readers. The stats show you’re very loyal, with about a quarter of all visitors returning regularly.

The last couple months saw some significant improvements to the technological guts of Fungible Convictions, none of which I can take credit for. If you are a lit blogger and/or WordPress user, I’m pleased to recommend the following goodies that are each recent additions.

WordPress plugins:

Income and networking:

  • Metaxu Cafe Litblog Network: Fungible Convictions is now a member. Many thanks for their profiling Fungible Convictions when FC became their 400th member blog—and for pointing me and others towards so many excellent writers.
  • Amazon.com Associates Program: Foolproof, money-making linking to books that interest Fungible Convictions readers. They also provide a spiffy linking feature that generates an information window alongside a link upon a user’s mousing over it. For example: WordPress 2 (Visual QuickStart Guide)
  • Brainiads: A recently launched Metaxu Cafe ad service featuring better ad targeting.

This site is the best thing that’s happened to my reading and writing life. I’ve received countless recommendations for great books, learned a lot of PHP coding, gotten the chance to interview editors and writers I admire, and discovered hours and hours of great blog-reading via links in your comments and e-mails. For all of that, my sincere thanks.