August 2nd, 2010

Applying one theme to multiple blogs in a WordPress Multisite network

Here’s a good bit of code I found in the WordPress MU forums and slightly altered for my own purposes – conditional tag based on blog ID. This will work for WordPress 3.0:

1
2
3
4
5
6
7
8
9
10
<!-- SWITCH CODE BASED ON BLOG ID -->
<?php $current_blog_id = $GLOBALS['blog_id'];
 if ($current_blog_id == 1) {?>d
Do this for blog ID 1
<?php } elseif ($current_blog_id == 2) { ?>
Do this for blog ID 2
<?php } else { ?>
Do this as a default.
<?php }?>
<!-- end CODE HOMEPAGE BASED ON BLOG ID -->
July 30th, 2010

How to create a WordPress 3.0 Multisite Network on a Windows server using sub-directories

I recently spent many hours — most of it Googling and staring at error pages — trying to get the new WordPress Multisite functionality working on a Windows server. I thought I would share how I finally ended up succeeding.

This tutorial is primarily for people who have control over the Windows server they are working on OR a flexible sysadmin who can make a few changes to the server should you run into problems. I’m assuming you’ve already successfully installed WordPress 3.0 and the basic functionality is working. That’s another tutorial for another time and another blogger.

In my next post, I’ll tell you how to enable Global Search functionality for those of you trying to create one cohesive site using multiple blogs. Warning: It involves spending money.

STEP 1
Add this line to your wp-config.php file and save the file:

1
define('WP_ALLOW_MULTISITE', true);

You should now see a “Network” link under Tools.

STEP 2

Temporarily disable all of your plugins. Click the Network link under Tools.

Choose “Sub-directories” for your Network type, enter a Network Title and an admin e-mail address.

If you see this error…

“Because your install is not new, the sites in your WordPress network must use sub-domains. The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.”

… it’s because you’ve had WordPress 3.0 installed for more than 30 days. They’re trying to stop you from creating directories that may conflict with content you’ve already created. If this is not a concern for you, go ahead and install your network anyway ignoring that message. You’ll just need to edit this line after you’ve completed Step 3:

1
define( 'SUBDOMAIN_INSTALL', true );

… to say …

1
define( 'SUBDOMAIN_INSTALL', false );

If you’re WordPress install is relatively new with relatively little content, overriding this setting shouldn’t be a problem. If you have a lot of content already in your WordPress installation, you may want to reconsider using sub-directories. Either use sub-domains or create a fresh install of WordPress to avoid problems. If you decide to risk it anyway, make sure you backup your database in case anything goes haywire.

STEP 3

From here, follow the instructions WordPress gives you. Add the first two blocks of text to your wp-config.php file. The third bit of code probably won’t apply to you if it looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

That’s for an .htacess file. WordPress is assuming you’re on a server running Apache, which you’re probably not. Since you’re on a Windows server, you’re probably running IIS. If your server IS running apache, then use the .htaccess file instead of the web.config file.

Add the following code to your web.config file located at the root of your site.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="WordPress Rule 1" stopProcessing="true">
                    <match url="^index\.php$" ignoreCase="false" />
                    <action type="None" />
                </rule>
                <rule name="WordPress Rule 2" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?files/(.+)" ignoreCase="false" />
                    <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" appendQueryString="false" />
                </rule>
                <rule name="WordPress Rule 3" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" />
                    <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
                </rule>
                <rule name="WordPress Rule 4" stopProcessing="true">
                    <match url="^" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
                    </conditions>
                    <action type="None" />
                </rule>
                <rule name="WordPress Rule 5" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" ignoreCase="false" />
                    <action type="Rewrite" url="{R:2}" />
                </rule>
                <rule name="WordPress Rule 6" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
                    <action type="Rewrite" url="{R:2}" />
                </rule>
                <rule name="WordPress Rule 7" stopProcessing="true">
                    <match url="." ignoreCase="false" />
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

If you don’t have a web.config file located at the root of your site, create one in Notepad. If you already have a web.config file setup, just add everything between the <rewrite> tags, making sure they’re nested within the <system.webServer> tags of your existing file. Save the file.

STEP 4

Go back to your Network page in WordPress and click the “Log In” link at the bottom. You’ll log in again and voila, your ability to create a Network is now available under the “Super Admin” area. This actually may just be the beginnings of your problems, but hopefully it’s the end.

If, when you tried to log in you started getting a 500 Internal Server Error, something has gone awry with your web.config file. For me, it turned out that the URL Rewrite module had not been installed on my server. You can test that by removing the <rewrite> tags and everything in between. If the site functions when that’s removed, then your server doesn’t have the URL Rewrite module. You can grab that here and install it:

http://www.iis.net/download/urlrewrite

If you don’t have the ability to install modules on your server, you’ll need to ask your sysadmin to do that for you. It’s a requirement for a sub-directory network, so you can’t skirt this issue.

STEP 5

Under Super Admin > Sites, create a new site and try to visit that site. If you’re able to see it, then you’re home free.

July 13th, 2010

Controlling the number of posts in multiple loop calls on a single WordPress page

That’s kind of a mouthful, eh?

With all the talk of organizations using WordPress as their website CMS, it’s pretty surprising some features aren’t yet part of the core code or at least surprising that some hacks aren’t more distributed. A very basic feature I know every news site would want is the ability to post multiple headline stacks on one page and control how many headlines each stack displays.

I’m currently in the process of transforming a very static agency intranet homepage into something more vibrant and news-powered using WordPress and I spent an hour searching for the most fool-proof, direct way to accomplish the display of multiple categories on one page. I thought I’d pass along the best solution I’ve found.

The crux of the problem is that using multiple loops on a single page seems to affect the way each loop displays, and not in a good way. No matter how I tried to reset or rewind a loop, it just caused problems for itself, another loop or the entire page. I used WP Modder’s solution and it worked like a charm.

His usage was slightly different than mine. His setup was:

1) Pull the first few headlines from a particular category and display them in a unique way
2) Then display the rest of the headlines normally without duplicating headlines from the previously displayed category

My setup was:

1) Every post is assigned ONE category
2) Every category will display X number of headlines on the front page and that number will vary depending on the category

To accomplish that, you replace this in every instance of your loop:

1
<?php while  ( have_posts() ) : the_post() ?>

… with this:

1
2
<?php $my_query = new WP_Query('category_name=My Badass Category&showposts=3');
while ($my_query->have_posts()) : $my_query->the_post(); ?>

… obviously replacing the category name and the number of posts to show. Using the same query name multiple times for this purpose may not be kosher, but it works and my page isn’t broken, so I’m sticking with it. Of course, most news sites would assign multiple categories to a post, but, uh, that’s your problem. :)

June 30th, 2010

FAA clears path for flying cars FINALLY!

This is the Terrafugia Transition, a plane/car hybrid developed by some MIT genuises. It costs $100k with $10 down, which I actually find quite reasonable compared to some of the high-end car prices out there. The FAA recently eased some restrictions to allow this thing to start selling commercially, which opens up the possibility of competition and lots of future improvements.

It’s runs on a 20 gallon tank that gets 30 miles per gallon on the road, so I’m wondering how long it can actually fly with a 20 gallon tank. You have to have 20 hours of training under your belt before you can operate this thing and you have to take off and land from airports. This is obviously not a practical vehicle yet, but imagine the possibilities!

June 29th, 2010

How to create a CSS rollover effect for buttons


I’ve decided to start using this space more for keeping track of random things I learn that I want to make a record of. I typically scour the internet for a solution, bookmark a site and then completely forget about bookmarks altogether. I figure if I blog about it, it’s more likely to stick with me and I’m more likely to be able to find it later with my site’s search engine. If someone else learns from it, all the better.

I wanted to figure out a way to do a rollover button effect where it looks like the button is being “pushed” when you hover over it. I figured I could achieve the effect by using a drop shadow in it’s inactive state and remove it in it’s active state, but I wasn’t quite sure of the best method to achieve the switch between active and inactive.

After an exhaustive (5 minute) search on Google, I found a solution that was written a gazillion (6) years ago on a Webmaster World forum.

Here’s the trick. Create a mini-sprite where you have the active and inactive states within the same image:

Then use this code in your stylesheet:

1
2
3
4
5
6
7
8
9
10
11
.buttons a {
display: block;
width: 146px;
height: 77px;
background: transparent url(http://www.lauragentry.com/wordpress/wp-content/uploads/2010/06/buttons.png) no-repeat;
text-decoration:none;
border:none;
}
.buttons a:hover {
background-position: -153px 0;
}

And this code in your body:

1
<div class="buttons"><a href="http://lauragentry.com"> </a></div>

Essentially what you’re doing is limiting a DIV to the width of the first half of your image and when you roll your mouse over that image, you shift the image to the left X amount of pixels to reveal the second half of your image. This allows a flicker-free transition and requires no Javascript.

Yay! That’s easy!

In case you want to know how to create a similar button style, there are a variety of ways to accomplish this, but I used Illustrator. For a quick read on creating buttons in Illustrator, give this short tutorial a try.

April 24th, 2010

Laurallani’s trip to Europe: The Lodging

We’re planning on shlepping through Europe this fall, and I’m in full planning mode, so I thought I’d share some of our plans with “picture pages, picture pages, open up your picture pages” (you sing the rest). If you’ve ever traveled with the General, you know I don’t screw around with planning vacations. Since I’ve been wanting to go to Europe for, basically my entire life, I’m sewing up all the details now to make sure I don’t forget anything.

The following gallery shows all of the places we’ll be staying while in France. We’re staying for 3 nights at one of Carollani’s friends places in London when we first get there, so there aren’t any photos of that. But then we’ll travel through the Chunnel on the Eurostar Train to Paris. We’ll be staying at an apartment in Paris for five days that is literally one block from the Louvre and the Palais Royale. We decided to go this route so we could stay outside of the normal tourist comfort zone, but mostly because we want to hit up the local markets and make several of our meals.

I digress, on with the show! I recommend going full screen mode with this bish (button in the top right corner).

SimpleViewer requires JavaScript and the Flash Player.


April 21st, 2010

WordPress Plugin: Post XML for Simpleviewer Gallery

After writing my first WordPress plugin (which creates an XML file of your blog using every post’s title, excerpt, permalink and custom fields), I started getting several requests from people who wanted post-specific XML that pulls out images stored in a post’s gallery to populate a Flash gallery.

Since there are several Flash gallery solutions out there that all require different XML structures, I decided to focus on one at a time. First up: Simpleviewer (free version).

SimpleViewer requires JavaScript and the Flash Player.


The Simpleviewer gallery above is populated by a dynamically generated XML file for this particular post. With my new plugin, Post XML for Simpleviewer, every post on my site has its own associated XML file that lists all of the post’s attachments, as well as captions and thumbnails.

After installing and activing the plugin, the XML files are generated simply by visiting a single post in a browser. Basically, the file generates each time someone looks at a specific post (not an index or archive page), so the XML is updating each time a single post is visited. If you get a ton of traffic, this might not be the best solution for you due to potential server overload.

The XML generated for each post will be located in a folder called “SVxmlfiles” within your wp-content folder. Each filename will be galleryXXX.xml where the XXX is your post ID number. For example, the location of the XML for this post is:
http://www.lauragentry.com/wordpress/wp-content/SVxmlfiles/gallery343.xml

You can set your preferences for Simpleviewer parameters by visiting the options page which is located under “Settings” in your dashboard.

I’m making the assumption with this plugin that you’re already familiar with Simpleviewer and are just looking for a way to dynamically generate the content with your WordPress blog.

If you think you’ll want every post to have a Flash gallery, I’d recommend putting the embed code in your template. If not, you can do it within the body of your WordPress post or page.

If you are going to have more than one gallery, you’ll need to give the “flashContent” a unique ID to match your blog post ID. Something like “flashContent343″ would be good for this post. Here’s the embed code I used for the gallery above:

<script type=”text/javascript”>// <![CDATA[
var flashvars = {};
flashvars.galleryURL = "http://www.lauragentry.com/wordpress/wp-content/SVxmlfiles/gallery343.xml";
var params = {};
params.allowscriptaccess = "always";
params.allowfullscreen= "true";
params.bgcolor = "555555";
swfobject.embedSWF("/wordpress/wp-content/uploads/simpleviewer.swf", "flashContent343", "600", "550", "9.0.124", false, flashvars, params);
// ]]></script>
<div id=”flashContent343″>SimpleViewer requires JavaScript and the Flash Player.</div>

THE BASICS

1) Download and install the plugin into your WordPress plugins folder

2) Activate the plugin. You can tell the plugin is working by visiting any of your single posts and then visiting http://www.yoursite.com/wordpress/wp-content/SVxmlfiles/galleryXXX.xml where XXX is the post’s ID.

3) Download and install Simpleviewer (free) somewhere on your site

4) In the Simpleviewer embed code, replace the gallery.xml reference with http://www.yoursite.com/wordpress/wp-content/SVxmlfiles/galleryXXX.xml where XXX is the post’s ID. If you’re placing the embed code in a template rather than a post or page, be sure to have the template dynamically generate that post ID.

THE PROBLEMS

1) There’s no way to exclude a photo from a gallery if it’s one of the post’s attachments. That’s outside the scope of this plugin, as I’m working within the confines of the WordPress gallery feature.

2) It does not currently differentiate between photos and other types of post attachments, so it will attempt to treat documents, videos and images the same. I’ll get that fixed in the near future.

3) As mentioned above, this generates XML on the fly every time someone visits a single post. If you’ve got a lot of images and a lot of traffic, there could be a site performance issue. If anyone experiences this, let me know.

UP NEXT

I plan on tackling Simpleviewer Pro and Autoviewer next. If anybody knows a way to reliably embed Autoviewer into a WordPress post without using iframes, hit me up at its.the.general@gmail.com!

January 21st, 2010

Fun times in the iPhone App Store: “But will this app provide a good noodle environment for me?”

Anyone familiar with iTunes knows the user reviews are a total cesspool of morons, but did you know about the special level of crazy happening in the App store specifically? It’s really wonderful.

Here we have a review (#10) of an Alice in Wonderland app. This app provides you yet another vessel to digest Lewis Carroll’s masterpiece and, well, that’s about it. One reviewer discovers that it actually is so. much. more.

Noodle Master

January 7th, 2010

Weirdest random image I’ve found today

December 6th, 2009

WordPress plugin: Photo Gallery XML Export v1.0.0

This is my first attempt at a WordPress plugin. I implemented it on The News Tribune‘s homepage several months ago and there haven’t been any disasters, so I’m considering it a success.

This plugin takes post data from your WordPress blog and creates an XML feed of that data. I suppose it could have several uses, but it is optimized to feed data to Flash photo galleries with info from the Title and Excerpt fields as well as each post’s permalink.

Download the plugin: Photo Gallery XML Export v1.0.0

I’ve also added the ability to include up to five custom fields (good for thumbnails) and the option of limiting to just one category.

Here’s a screenshot of the options page:

setting_examples

How you might use this in the real world:

If you have a photo blog or a blog that usually includes at least one photo per post, you could use exported XML data from your blog to feed a Flash content rotator that you would use to promote that blog on another page of your site.

Or, if you have a special feature on your blog — say, “Recipe of the Week” — that includes a photo, you could assign that special feature a category (like “recipeoftheweek”) and use exported XML data from just that category to feed a Flash content rotator to promote that special content.

Here’s an example of my blog’s content as XML generated from this plugin:

xml_screengrab3

And here’s a live example of a Flash content rotator that’s pulling data from XML generated by this plugin:




A few suggestions for Flash content rotators:

Simpleviewer

JW Image Rotator

Flash Image Rotator using XML Playlist

Some notes:

1) The XML declaration is hard-coded to be: <?xml version=”1.0″ encoding=”UTF-8″ ?> … I don’t have any plans to change that unless I get requests for other declarations.

2) You can name most XML elements however you see fit, but right now the parent element is hard-coded to “images” and each blog post parent element is hard-coded to “pic.” I’m hoping to make that customizable in the future.

3) If your excerpt isn’t populated, it will pull from your blog post. Not entirely ideal, but that’s how WordPress excerpts work by default.