I maintain an online database of auditions for musical theatre in the Philadelphia area, and up until now I’ve always used the phpMyAdmin interface to update it. It’s fine as a tool in general, though I don’t have much perspective because I’ve never used anything that’s very different. Accessing it for minor updates is kind of a hassle, though. So, today I added my own mechanism for updating my database, and it’s a heckuva lot easier =) Yay!
Archive: ‘Web Development’ Category
Updating mysql without phpMyAdmin
Saturday, June 12th, 2010404 errors fixed by resetting permalinks
Wednesday, June 9th, 2010I was messing around with .htaccess and php.ini files in my blog directory, trying to fix an irksome “HTTP error” that appears when I upload pictures. (Strangely, the pictures still seem to upload sometimes.) Lots of suggested fixes are floating around the internet, but none of them worked for me. I have a feeling that upgrading to PHP 5, as suggested here, would work for me, but I had built my theme (and the rest of my website) based on PHP 4, since that was the only version available to me when I first started. One day, when I have lots of time to check the entire site, I’ll see about upgrading.
Meanwhile, I deleted the .htaccess and php.ini files I had put in my blog directory, but then I realized that I was redirected to my main site’s 404 error page when I tried to view a single post, a category, or anything but the main blog index page. The problem didn’t clear when I emptied the browser cache, either. I panicked for about three minutes and then realized the issue might lie with my URL rewriting. So, I changed the settings for permalinks back to the default (which shows the query string, something like index.php?p=506) and then back to the permalinks I wanted. This appears to have corrected the problem.
Semi-automated import of Facebook comments on blog posts
Wednesday, June 2nd, 2010Facebook offers a mechanism to import your blog posts as Notes in your Facebook account, but I don’t believe there’s a way to import the Facebook comments on those posts back to your blog. (If you’ve found a way, let me know!) So, because I like to do things the hard way, I created a simple set of scripts to add those comments to your blog with the original date, time, and the commenter’s first name only. It requires cutting and pasting a block of text from the email notification, which is the only way I ever learn of comments on my Notes (I otherwise try to avoid the timesink that Facebook is). Too janky for public release, but it works for me =)
A WP theme for wide screens
Wednesday, June 2nd, 2010I’m used to viewing websites on my laptop, so I haven’t really designed websites with large screens in mind. However, Chris has two 20″+ monitors, and he often has a lot of screen real estate that goes unused. He needed a theme for his blog, so I figured it was a good opportunity to experiment with a wide theme.
If I were really good, I’d make the dimensions resize with the browser. However, my idea for his theme involved background images, which IMHO don’t resize well (since the resizing is done on the client side by the browser, I believe). I prefer to make sites with fixed sizes whenever fixed background images (which I almost always use) are involved. If instead only CSS and tiled images were used, making the theme resize would be much simpler.
The wide theme was pretty straightforward; I encountered only one wide theme-specific problem. When the browser was resized to smaller than the width of the theme, the background image for the body tag shifted left of the page, so that the bottom of the page sometimes appeared displaced to the left. I fixed this by adding a wrapper div and placing the background image there instead of in body. I also set the the body CSS property display to table, which I thought had fixed the problem initially. So, two steps for the fix:
- avoid background images in
body - set CSS to
body {display: table;}
Make WP gallery display non-image files, independent of file type
Thursday, May 27th, 2010Yesterday I made the WordPress gallery display all the post’s media according to the post_mime_type, e.g., pdf or msword. So if you want your post to have a gallery of images and then a gallery of pdf’s, or in my case msword’s and pdf’s, you can do that. However, I realized that it’s more useful to be able to create galleries according to some arbitrary common characteristic that the user designates (that is, the reason for dividing the gallery files). So, I came up with a different hack for the wp-includes/media.php file.
The first part is very similar to the previous solution, involving a revised definition of $attachments if the gallery shortcode parameter “linklist” is specified. Note that this parameter is merely one that I made up and could be called something else if it better suits your purpose. Under the default definition of $attachments, I added:
// ========================== anh hack 2010-05 =========================================
// get gallery to display list of links, eg for pdf's
if ( isset( $attr['linklist'] ) ) {
$listfilegroup = $attr['linklist'];
if ( !$attr['linklist'] )
unset( $attr['linklist'] );
$attachments = get_children( array('post_parent' => $id, 'post_status' =>
'inherit', 'post_type' => 'attachment', 'order' => $order, 'orderby' =>
$orderby) );
}
// ========================== end anh hack =============================================
Note that I didn’t use the value of linklist here at all; thus, the array $attachments contains all the media in the gallery (whereas the default fetched only images). Rather than limiting the results of my query for $attachments, I then added code (the next part) to limit the display of those results. Perhaps this is not the best way, since I imagine that limiting the query would be more efficient than limiting the display, but I was not able to limit the query according to post_content or post_excerpt, which correspond to editable fields for media (the “description” and “caption” respectively) in the default WP structure.
The next part of the hack replaces the command part of the foreach loop that generates the gallery output. Under foreach ( $attachments as $id => $attachment ) { , I commented out all of the commands (up to its closing bracket } ) and added:
// ========================== anh hack 2010-05 =========================================
/* the code in this hack block replaces the commented-out code. works with hack block
above; basically, if $listfilegroup is set, then list files according to $listfilegroup
(which is set for attachments only; $listfilegroup must match post_content - on admin
panel, this field is the media's "description" */
if (!empty($listfilegroup)) {
if ($listfilegroup == trim($attachment->post_content)) {
$link = isset($attr['link']) && 'file' == $attr['link'] ?
wp_get_attachment_link($id, $size, false, false) :
wp_get_attachment_link($id, $size, true, false);
$output .= "<{$itemtag} class='gallery-item'>";
$output .= "
<{$icontag} class='gallery-icon'>
$link
</{$icontag}>";
if ( $captiontag && trim($attachment->post_excerpt) ) {
$output .= "
<{$captiontag} class='gallery-caption'>
" . wptexturize($attachment->post_excerpt) . "
</{$captiontag}>";
}
$output .= "</{$itemtag}>";
if ( $columns > 0 && ++$i % $columns == 0 )
$output .= '<br style="clear: both" />';
}
} else {
$link = isset($attr['link']) && 'file' == $attr['link'] ?
wp_get_attachment_link($id, $size, false, false) :
wp_get_attachment_link($id, $size, true, false);
$output .= "<{$itemtag} class='gallery-item'>";
$output .= "
<{$icontag} class='gallery-icon'>
$link
</{$icontag}>";
if ( $captiontag && trim($attachment->post_excerpt) ) {
$output .= "
<{$captiontag} class='gallery-caption'>
" . wptexturize($attachment->post_excerpt) . "
</{$captiontag}>";
}
$output .= "</{$itemtag}>";
if ( $columns > 0 && ++$i % $columns == 0 )
$output .= '<br style="clear: both" />';
}
// ========================== end anh hack =============================================
This second part looks complicated, but I really didn’t add anything fancy. All it does is check if $listfilegroup is set, and if it is, it runs through the default display algorithm for only those media whose description (stored as post_content) matches $listfilegroup. (The default algorithm is the command part I had commented out; perhaps there’s a way to do this without commenting it out, but the above implementation seems the simplest to me.) If $listfilegroup is not set, then it runs through the default display algorithm for all media in $attachments (which are probably all the images).
So, the usage is the same as for yesterday’s hack: just use the gallery shortcode and set the linklist option to a gallery identifier, e.g., . Then use that identifier as the description for all files to be included together that gallery.
What if you want to use a gallery file in more than one gallery? Well, for images, you can try this multiple galleries plugin – I haven’t tried it myself, but it seems straightforward with a simple GUI change. For non-image file types, with the hacks I’ve described above, you could add the file again and give it a different description, so that each can be displayed in a gallery.
Thoughts? Always room for improvement.
Make WordPress gallery display pdf’s and other non-image file types
Wednesday, May 26th, 2010I run the Penn Med UltraSounds website, and I needed a way to display a list of pdf’s. As far as I know, you can upload non-image media (e.g., pdf’s and word docs) to the gallery, but its baseline allows you to display only images; you have to individually insert other media types rather than inserting the whole gallery.
The advantage of using the gallery to display media is that you can update the media list and display it sorted in various ways, for example by title or by date. Each gallery is unique to the associated post. So, you’d think that someone would have made a plugin or made this functionality accessible for other file types. I couldn’t find any, though. I just want a simple list of links!
So what did I do? After a mean monster breakfast of steak (that’s what Chris eats for breakfast, so that’s what I get), I decided to see if I could modify the code to enable me to do what I want. The solution, though in rough form, is surprisingly simple: I take advantage of the existing gallery shortcode by adding the following to the wp-includes/media.php, just below the $attachments = get_children..., around line 643:
// ========================== anh hack 2010-05 =========================
// get gallery to display list of links, eg for pdf's
if ( isset( $attr['linklist'] ) ) {
$listfiletype = $attr['linklist'];
if ( !$attr['linklist'] )
unset( $attr['linklist'] );
$attachments = get_children( array('post_parent' => $id,
'post_status' => 'inherit', 'post_type' => 'attachment',
'post_mime_type' => $listfiletype, 'order' => $order,
'orderby' => $orderby) );
}
// ========================== end anh hack =============================
Then, using the gallery short code, specify the type of file in the option linklist. This file type can be found in the details for the media item, underneath its title. In the MySQL database table wp-posts, it is the value under post-mime-type. Here is a screenshot:
For example, to display pdf’s and order alphabetically by title, use [gallery linklist="application/pdf" orderby="title"].
Hope this helps! Let me know if you have questions. Time permitting and curiosity motivating, I will attempt to make this into a plugin. I foresee that dealing with the myriad ways people might need the plugin will make the task exponentially more difficult, but still, it could be fun =)
Facebook blog importing, take 2
Wednesday, March 17th, 2010I’m a huge geek, or a little OCD, or both. In any case, I was frustrated when, after switching from my homemade blog to the Wordpress setup, the new blog feed (which comes with Wordpress) did a nice job of conveying text and images but couldn’t handle videos or other customizations I had implemented. (That’s not Wordpress’s fault, of course; I just occasionally add things to my posts that require the code within my site to work.) As a result, when I used the feed to import my posts into Facebook as Notes, the Notes aren’t quite displayed as I would like. For instance, I might refer to a video in my post, but it doesn’t appear at all in the Note.
With my old blog, I created a custom RSS feed that stripped out all enhancements and provided Facebook only an excerpt, along with a link to the original post where the customizations (should!) work. I realize this additional linking step might be annoying for Facebookers, but seriously, if you are on Facebook to begin with, you probably have time to kill, and I’d rather you see my post as I intended it. So, I revised that RSS feed to pull data from the Wordpress database instead. So far it seems to be doing okay!
Today, I enter the real world of blogging
Monday, January 18th, 2010I woke up this morning with the intention of doing some science reading. I usually allow myself some pleasure reading as I eat breakfast – catch up on the news, that sort of thing. Somewhere along the way I came across a post (this one, specifically) that made me reconsider the utility and value of a highly interactive blog. My old one enabled some limited interaction, and more importantly it helped me learn a lot about how databases can be used to display content.
But in terms of facilitating communication on the World Wide Web, it was nowhere near as sophisticated as, say, Wordpress (which I’m using, since I use it for web development too). So, approximately three hours later, I have now set up the platform within my site. It’ll take some work to merge the archives, but yay, here it is!
FriSatSun, soccer, and switchable CSS (that A|A|A font-size thing)
Sunday, October 4th, 2009This weekend has been sweet I still have to study for an exam tomorrow, but it’s been sweet.
I’ve always wanted to try that restaurant in Rittenhouse Square called Friday Saturday Sunday. Well, my birthday was last week, but I was too busy getting rocked by school to celebrate, so Chris took me to FriSatSun last Friday. It’s a cozy, romantic little place, not too trendy or loud, with great food — I loved it. I had the crusted tilapia and he got the duck. For dessert, …
[this is an excerpt from the original blog post]
Website restructuring, and a project in the works
Saturday, May 30th, 2009So I had some pictures to post, and then I remembered that I didn’t plan well for expansion of the Penn section. My quickie solution — could be better, but it works — was to create a “grad school” section that will henceforth serve as a catch-all for the next several years.
In other web-related news, I recently read on cnn.com about the Nature Seekers, a non-profit started by Suzan Lakhan Baptiste in Trinidad to end the slaughtering of the leatherback turtles that next upon …
[this is an excerpt from the original blog post]
