Mostly about my amusement

Category: Software (page 5 of 22)

Customizing the Elemin theme

NOTE: No parent theme files were harmed, modified, or otherwise abused in the making of this blog post.

Sometimes I do learn things! I was able to customize the layout of my blog using a child theme, some CSS, and some additions to my child theme’s functions.php file.

The Elemin theme from Themify is a great theme and I’m a satisfied customer. The only settings on my theme are on the Default Index Layout as follows:

  1. Display the sidebar on the right
  2. Display excerpts and not the full post content
  3. Post layout is in 2 columns
  4. Image size is 75×75 (for the featured image)

All the other settings are left to the default. Any customized CSS is handled in my child theme’s style.css file.

I like the layout of 2 columns of excerpts but also wanted to have 2 full content posts on top. My blog setting is to display 10 posts per page so that’s two posts on top and 8 excerpts afterwards in a 2 columns. Oh, and I want to maintain the scaling capability of the theme and do not want to modify copies of the parent theme files.

That turned out to be pretty straight forward. WordPress assigns a CSS class tag to each post with the post ID appended to it. So if this post ID was 4153, then a CSS class tag of post-4153 would be embedded in the generated HTML code. It’s done that way exactly so you can style individual posts like this.

For the latest 2 posts (for example ID 4153 and 4123), I want to generate CSS so that the width is now 100% and the featured picture, tagged with post-image class, is hidden. Also the second post I want to float left and adjust the left margin.

That CSS looks like this:

.post-4153 {
	 width: 100% !important;
}
.post-4153 .post-image a {
	 display: none !important;
}
.post-4123 {
	width: 100% !important;
	float: left !important;
	margin-left: 0 !important;
}
.post-4123 .post-image {
	 display: none;
}

To generate this output, I need to get the last 2 published post IDs, generate the CSS, and insert it into the header using this code in my child theme functions.php.

//
// Get the last two published post IDs.
//
$args = array(
'numberposts' => 2,
'post_status' => 'publish' );
$mh_post = wp_get_recent_posts( $args );
$mh_post_ID1 = $mh_post['0']['ID'];
$mh_post_ID2 = $mh_post['1']['ID'];
//
// Add my CSS to wp_head
//
add_action( 'wp_head' , 'mh_first_two_posts' );
//
// Create the code for the header
//
function mh_first_two_posts() {
global $mh_post_ID1, $mh_post_ID2;
if (is_home()) { ?>
<!-- child theme header -->
<style type='text/css'>
.post-<?php echo $mh_post_ID1; ?> {
width: 100% !important;
}
.post-<?php echo $mh_post_ID1; ?> .post-image {
display: none !important;
}
.post-<?php echo $mh_post_ID2; ?> {
width: 100% !important;
float: left !important;
margin-left: 0 !important;
}
.post-<?php echo $mh_post_ID2; ?> .post-image {
display: none;
}
</style>
<!-- /child theme header -->
<?php   }
}

That takes care of the CSS, but that only get’s me 2 full width excerpts. I want those 2 posts to output the whole content not an excerpt. The rest of the posts I want to remain in the excerpt format using two columns.

Easy to do because I can filter the excerpt and restrict my changes to just those two identified posts.

//
// Add my filter to the excerpt
//
add_filter( 'the_excerpt' , 'mh_excerpt_to_content' );
//
// Swap the excerpt for those two posts with the content.
// Don't forget to apply the filters to the content.
//
function mh_excerpt_to_content( $content ) {
global $mh_post_ID1, $mh_post_ID2;
$mh_id = get_the_ID();
if ( ( $mh_id == $mh_post_ID1 ) or ( $mh_id == $mh_post_ID2 ) ) {
$content = get_the_content();
$content = apply_filters( 'the_content' , $content );
}
return $content;
}

That works. The only disadvantage to this method is that the apply_filters get’s ran twice. If you have something that adds to the content, it will run once when the loop runs and again when I run it in functions.php. For me this isn’t a problem but I do want to see how I can clean that up.

The full content posts don’t look exactly like they do as a single post but I’m satisfied for now and I’ll keep playing with it for my amusement. Doing it this way really appeals to me because I’m able to maintain my blog’s changes and not worry about breaking something in the parent theme.

Still a sucker for WordPress beta

I took the plunge and once again used SVN to switch from running WordPress 3.1.3 to 3.2 beta. The betas are usually solid and I test my nightly backups on a different server from time to time.

Unless something really drastic happens to the WordPress repo, I’ll be fine with the beta.

The new fullscreen distraction free interface for composing posts? It’s unreal. The keyboard commands work fine, it’s just that the minimal GUI is hidden until you move the mouse. You “Just write” and that’s all there is to it. It’s just a blank page for you to type on.

The other improvements so far seem to be GUI based. I haven’t dug deeply into the documentation yet but my plugins work fine and I’m running a network of blogs from this installation. There is an oddity that when I load the post edit page, the TinyMCE does weird things during the load. Not a big deal and it sorts itself out in a second, just strange is all.

So far I like it. WordPress continues to improve and the beta keeps that record going strong.

Using IPv6

When IPv6 day came around, I installed Squid3 and a IPv6 tunnel setup on my in-house Linux server. I used the instructions from Ubuntu’s Wiki and made some minor configuration changes to Squid3 and that was it. You need to use version 3; version 2 of Squid lacks the right support.

The tunnel broker I am using is Hurricane Electric’s excellent Tunnel Broker. Just create an account, provide some information and you are good to go.

Easy! Now using Squid3 I can browse to Google and CNN’s IPv6 pages without any hiccup. I preferred to do it this way because setting up my Linux server as an IPv6 gateway would have required more (not much) work from me. This was quick to do and I had no problems.

Moving on, I created another HE tunnel on this web server. Using Apache 2 virtual hosts, I just added to the config file these lines.

<VirtualHost [2001:470:1f10:f10::2]:80>

 ServerAdmin webmaster@localhost
 ServerName blog.dembowski.net
 ServerAlias *.blog.dembowski.net
 ServerAlias photo.dembowski.net
 ServerAlias blog.epyon-1.com

 DocumentRoot /var/www/vhosts/blog.dembowski.net/
 #DocumentRoot /home/jan/public_html/

 <Directory />
 Options FollowSymLinks -Indexes
 AllowOverride All
 </Directory>

 ErrorLog /var/log/apache2/blog.dembowski.net-error.log

 # Possible values include: debug, info, notice, warn, error, crit,
 # alert, emerg.
 LogLevel warn

 CustomLog /var/log/apache2/blog.dembowski.net-access.log combined
 ServerSignature On

</VirtualHost>

The lines are duplicated from the existing vhost entry. I substituted the A record address of 209.20.89.108 with the AAAA record address of 2001:470:1f10:f10::2. This address was provided by Hurricane Electric.

Next up was to update my dembowski.net DNS zone by adding the AAAA record. This is the IPv6 address record and now my DNS name blog.dembowski.net has two entries.

blog.dembowski.net. 900 IN A 209.20.89.108
blog.dembowski.net. 900 IN AAAA 2001:470:1f10:f10::2

I restarted Apache and now when a IPv4 or v6 request comes in, it gets handled by correct IP address and all is well. My server and proxy logs show which address I am hitting, and the site validates.

So what did this get me? Nothing really, except to show how easy it is to add IPv6 to your site and web connection. A buddy of mine almost exclusively uses IPv6 only at home. The old address space is or has ran out (depending on how and who you ask). Migrating to anything new can be a challenge but really, there is no reason for ISPs or hosting providers to not support IPv6.

Nikon GP-1

Sometimes you just like to know where you were when you took the photo. Luckily there are many options available for a DSLR and I went with the default Nikon solution.

Last week on a whim I ordered a Nikon GP-1 for my camera. This GPS receiver plugs into my D300s and when it has a lock onto enough GPS satellites (3 or more) it embeds the coordinates and UTC time for when and where you took the picture.

I like it a lot but it’s an imprecise technology. The receiver is only as accurate as the data sources it locks onto, meaning if it locks onto 4 or more satellites, it’s good for ~20 feet or so. My first photos didn’t have any GPS coordinates recorded. Later on I was getting a good signal and got better results.

The default camera settings is to enable Auto Meter off, which from the manual explains

Auto Meter Off

If Enable is selected for GPS > Auto meter off in the setup menu for D3, D700, D300, and D90 cameras, the exposure
meters will turn off automatically after the time specifi ed in the camera Custom Settings menu. This reduces the drain
on the battery but may prevent GPS data from being recorded if the exposure meters are not activated until immediately
before the picture is taken.

I had some problems keeping a lock on the GPS with that feature enabled. Once I disabled the feature, the GPS receiver took a couple of minutes to acquire the satellites. But once it found them, I had a solid green light and was floored as to how accurate the readings were.

If you look at the above map, you can see where the GP-1 did not quite get a lock onto my position. After I disabled Auto Meter Off, the GP-1 put me (correctly) onto 23rd Street. Even with 3 satellites it still puts me in the general vicinity and that’s good enough for my street photography.

After I uploaded the photos to Flickr, I Googled for a tool and found iMapFlickr. After providing a small amount of info I was able to generate the above map in no time. I’ll continue to play around with it but so far it works exactly as I thought it would.

Trying Firefox 4 beta again

Recently I gave Firefox 4 beta 4 a try but ended up removing it. As a beta it was not bad but I had some minor problems with Adobe Flash and the benefits were not enough to get me to keep it.

Firefox 4 beta 7 is another story. On a whim I installed it on my Windows 7 PC and it’s been smooth sailing ever since. It’s fast and I don’t seem to get any web page rendering issues. I use my browser for news reading, WordPress, Facebook (okay, almost ashamed to admit that one), etc. and some of the content is mixed and dynamic. With this new beta, the only thing that is different is the menu is hidden. Other than that, the experience is very smooth.

It’s definitely not for the casual user (I am not installing it on the shared iMac) but if you want to see what’s next then give it a try.

It’s the goofy user avatars that threw me off

My participation in the WordPress support forums was never overly ambitious. I would generally aim for questions that I could either respond to quickly or I had the time for. But for the last few months I have been refraining from picking up threads. Mostly because the questions fall under these categories:

  1. Something broke please help me fix it! (User provides no info to find out what happened, gets belligerent when asked for more info)
  2. How do I make my site look like this one? (User points to professionally made site that may not be running WordPress)
  3. I can do this on WordPress.COM, it should/must/has to work on WordPress.ORG’s version. (User points to feature that requires one or more plugins and was never built-in)
  4. Demands that !!WordPress!! fix! this! NOW!!! (Who do they actually mean? Automattic?)
  5. Philosophical debates re GPL and commercial success.

You get the idea. These are not new types of questions and the support forum has had these from day one.

What’s new is that the volume of these questions obscure the really good support problems that are out there. It’s like there is a vast tidal wave of people who really do not know that they are running a roll-your-own version of WordPress. They don’t know about requirements, reasonable expectations, or how to troubleshoot their own server. Sounds like a problem alright! But it’s not.

This is confirmation that WordPress is wildly successful.

WordPress has moved from being a PHP hackers pet blogging software and into a mainstream software product. These new users in such huge quantity means that WordPress “made it”. These users are along for the ride and the WordPress forum regulars (moderators and support ninjas) have these requests well in hand.

The support forums continue to evolve and will deal with the flood of new users. Everything moves and changes happen all the time to make the support experience better. I have just one request.

Can the WordPress support forums please lose the new default user icons? The MonsterIDs are freaking me out.

dd-wrt to the rescue (again)!

My Netgear WNR834B v2 has been showing it’s age and giving me grief lately. After a few hours of network usage, my Netgear would suddenly start rebooting itself and keep doing that every few minutes.

The only thing that would bring it back to life would be to pull the plug, wait a few seconds, and put the plug back in. The last firmware for my device is version 2.1.13 dated May 16th, 2oo8. This doesn’t fill me with confidence that the vendor can solve my problem. I don’t blame Netgear for that; they make money on the sale of hardware and not support.

I use a pair of these WNR834Bs to connect my second floor to my ISP in the basement.  It’s strictly for bridging a gap where I am not easily able to run a wire.

So I went to the dd-wrt website and picked out the firmware using their router database tool and put in my model. This lead me to their wiki page to read some instructions, and in less than an hour of playing with settings I had dd-wrt running.

The speed difference is pronounced. It’s not just my imagination, web pages are loading more quickly than before. I don’t think that means the Netgear firmware was defective, I do think that tuning additional options in dd-wrt helped improve the situation.

This is a low cost solution to extending the life of some hardware and keeps me from running cable. So far so good and I’ll just see how it goes.

Easy Twitter Button for WordPress

Twitter announced their own Tweet Button and have provided a page for creating a button on your web site. You enter some info and you get the HTML code to add.

Extending WordPress has always been easy. You can add what you want via a plugin, or you can put the functionality into your theme’s function.php file.

I wanted to play around with adding this to my blog, so I went to their page and created my button. I then used the generated code as a template for what I wanted to do.

There is no way I’m savvy enough to write a plugin, but adding a filter to my theme’s function.php file is within my reach.

This is from an idea I got when I read WP Beginner’s post on how to add post thumbnails to your RSS feed. I used his code to do this.

function tweet_button($content) {
        global $post;
        // Your Twitter ID goes here
        $twitterid = 'jan_dembowski';
        $tweetbutton = '<div class="tweet-button">';
        $tweetbutton = $tweetbutton . '<a href="http://twitter.com/share" class="twitter-share-button" data-url="' . get_permalink() .'" data-text="' . get_the_title() .'" data-count="horizontal" data-via="' . $twitterid . '">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>';
        $tweetbutton = $tweetbutton . '</div>';
        // $content = $content . $tweetbutton;
        $content = $tweetbutton . $content;
        return $content;
        }
add_filter('the_content', 'tweet_button');

You can download the code via this text file link.

It’s not exactly user friendly, but it gets the job done. I wrapped it in a <div> so I can style it later. If you want the button at the end instead of the beginning, then comment out line 9 and un-comment out line 8.

It’s a fun hack for me and I am sure that soon there will be a plugin to do this. If you do decide to do this then make sure you backup your theme’s function.php file. Any typo’s or mistakes will make your WordPress blog stop working.

Coraline child theme

Have I mentioned how easy it is to use WordPress child themes? I can’t stress it enough, never modify a WordPress theme. Create a child theme instead.

I just converted a blog from an old outdated Cutline theme to a SVN copy of Coraline.  This is the WordPress.COM replacement for the Cutline theme.  The old theme bugged me for a few reasons, mainly it was the lack of basic features such as Gravatar support. I had meant to clean it up but never got around to it.

It took me less than an hour to make the switch. I retrieved a copy of Coraline like so

$ cd wp-content/themes
$ svn co http://svn.automattic.com/wpcom-themes/coraline coraline

This keeps an unmodified copy of the Coraline theme.  Once it’s in the WordPress.ORG website, I’ll replace it with that copy.

All I had to do was create a separate directory and create a style.css file with the following:

/**
 * Theme Name: Coraline for Stefan's Stuff
 * Description: Jan Dembowski's Coraline Child Theme
 * Version: 1.0
 * Template: coraline
 */

@import url("../coraline/style.css");

/* =Asides
---------------- */

.home #content .aside {
 border-left: 1px solid red;
}

The old asides had a slightly different styling.  I made copies of the header.php and footer.php files into my child theme directory and added an archives.php template. I modified one line in each of the copies.

I tossed in a rotate.php script and copies of the random banner images and I was all set. I did need to resize the old banner images from a width of 970 to 990 but that was it.

Child Themes are cool and once again I can keep the parent theme up to date without worrying about my changes.

Android or iPhone 4?

Do I get an Android phone or an iPhone 4? I’m in no rush to get a new phone but I do periodically suffer from phone envy.

I am a fan of easy-to-use technology. I currently own an iPhone 3G with iOS 4.0.1 installed. My phone has been jailbroken not because I have a “SOFTWARE MUST BE FREE!!!1!” itch, but because I wanted to tweek my phone in ways that Apple doesn’t support for my hardware.

Cool Applications, not so cool app store

One of my favorite apps on my iPhone is Camera+. It lets me take photos, make adjustments, and share those photos online. All within the app and very easily.

The Camera+ developers came up with the idea of modifying the volume up button to be used as a shutter button. This re-mapping of the button would only be done while the user is in the app. It’s a great idea and makes using Camera+ easier.  But the idea was rejected by the app store, so the developers created a back door to enable that setting.

That’s a sensible work around because the app store was apparently afraid that re-mapping the volume up key while in the Camera+ app would create confusion. Since the end-user would have to access a specific application URL, they would have to know what they were doing.

But as expected the Camera+ app has been removed from the app store. Rules are rules, especially when they are arbitrary, imaginary, mostly made up, and not published.

Do I really want to continue using a product that fosters an environment like this? I know that the Android Market Place has it’s pitfalls too but the Apple App store is driven by incompetence.

Android is becoming more cool

I know two people who have Android phones from Verizon.  The first phone I’ve seen is the HTC Incredible.  The UI is easy to use and makes the experience fun.

The other phone is the Droid X.  The display portion alone feels like it’s bigger than my iPhone 3G.  It’s not a small phone in comparison but the display is fantastic. It’s not as slick as an HTC phone but it is close.

How would a Gorilla design a better Gorilla?

I’ve also seen the iPhone 4.  The display is phenomenal but it’s essentially a better iPhone 3GS. It’s more resolution, more memory, faster CPU.  But it’s still an iPhone and I already have an inferior version right now.

Why just get a better version of the iPhone 3G? Why not get a new phone and try out the other guys? If Camera+ existed for the Android phone, that would go a long way to hastening my decision.