Help a brother out

A couple of days ago I added a contribute button to my project pages. I’m posting about it here to prod those who already use my code into contributing something to my I’m a poor law student fund. I was encouraged to add such an option after receiving several requests to use some of my code in a commercial setting. Depending on how lucrative (or not) this turns out to be, I might be compelled to put the button on all of the individual archive pages as well, you know, for those random surfers bent on giving away money.  🙂

Implementation

I thought I’d elaborate a bit on the method I used to display the contribute button only on the project pages. For other special pages (i.e., yearly, monthly, and individual archives), I just run simple PHP if statements that use WordPress functions to check for the type of page we’re dealing with. Obviously though, my project pages exist completely outside of WP (i.e., I don’t use the WP pages feature and there’s no built-in function to discern a project page from any other page).

Because all of my project pages are located off of the projects directory in the URI, I use a simple regular expression to check for this in an if statement.

if (preg_match(/projects/i,$_SERVER['REQUEST_URI'])) {
    // Word found in URI
}
else {
    // Word not found in URI
}

There’s nothing more to it. If you are looking to do something similar, be sure that this check runs after all other checks (to the extent possible) if the word/phrase you’re looking for occurs somewhere in the title of your posts (assuming of course, that you use post titles in your archive scheme).