Mostly about my amusement

Tag: WordPress (page 5 of 13)

It’s not my fault, the wife uses Internet Explorer 8

For my home PCs I typically run the latest and greatest web browsers. I even run Internet Explorer 9 which is even not that bad™. Lately I’ve been vacillating between Firefox and Chrome.

At my wife’s work they’re now using Internet Explorer 8. That’s an improvement, they’ve been on version 6 for years.

This blog’s theme uses CSS border radius effectively and it doesn’t render correctly on version 8. You get square blocks where you wanted round corners. The next version it works fine, version 8 and below not so much.

There is a work around but it’s ugly. Add conditional CSS to your head for any version of IE less than 9 and reference PIE.htc from CSS3 PIE.

This is easily done by adding some code to my theme’s functions.php file.
Read more

Fun with oEmbed and Twitter

This tweet is being displayed using oEmbed between WordPress and Twitter. This capability was added a few minutes ago after I pasted Otto’s code snippet into my theme’s functions.php file:

That’s pretty remarkable. I’ve embedded a tweet that has an embedded Youtube video in it. I didn’t even bother to wrap the URL in the [ embed] … [ /embed] shortcode, I just pasted in the link to that tweet.

That’s very cool! It shouldn’t be long before this is put into a plugin; I put it into my theme’s functions.php because I’m used to poking in there.

Interestingly enough, when the Twitter Blackbird Pie plugin is activated it overrides the oEmbed output and puts the tweet into that nice format that they use. For now I’ll use the oEmbed option.

Themify child theme fix

Update: Themify fixed the issue and an update is now available. The child theme fix is no longer needed.

I updated my Elemin theme to the latest and greatest and ran into a problem. They’ve changes how style sheets are queued up to use wp_enqueue_scripts.

That’s good, but now my child theme’s style.css will not get loaded, just the Elemin parent style.css file.

Easy to fix and I’ve added the following lines to my child theme’s functions.php file:

add_action( 'wp_print_styles', 'mh_remove_themify_styles' );
function mh_remove_themify_styles() {
        wp_dequeue_style( 'themify-styles' );
}
add_action( 'wp_enqueue_scripts' , 'mh_add_child_style' );
function mh_add_child_style() {
        wp_register_style( 'mh-child-style' , get_stylesheet_uri() );
        wp_enqueue_style( 'mh-child-style' );
}

That removes the parent theme style sheet and adds the child theme’s version.

Update: Themify (seriously, they’re really good and you should buy their themes) is going to address this problem with an update today. Which is good, de queuing their style sheet broke other styling and I ended up using add_action(‘wp_head’… instead of the above.

I really am limited by my PHP and CSS

As part of purchasing the Elemin theme I get support from Themify and I asked for CSS help on their forum. It’s a good benefit and part of the package.

I was able to get two full posts on the home page and leave the rest as excerpts but the CSS was baffling me. I couldn’t work out how to set the post-meta to format as I wanted it to.

My CSS is at best “not too good” and I was messing up some inherited properties.

The response was good: why not just wrap the posts in divs with the correct class and let the default style.css do the rest? That way the generated output would look kind of like this:

<div class="list-post">
 [post 1]
 [post 2]
</div>
<div class="grid2">
 [post 3]
 [post 4]
 [post 5]
 [post 6]
 [post 7]
 [post 8]
</div>

That was a real light bulb moment for me. I know I can do that by making a copy of the elemin/index.php file into my child theme directory and making modifications.

So that’s exactly what I did and replaced the regular get_template_part() line with this code:

<!-- child mods -->
<?php if( is_home() and $post_layout == "grid2" and $paged < 2 ) {
   $mh_post_count++;
   switch($mh_post_count) {
      case 1: ?>
         </div><!--/loops-wrapper list-post-->
         <div class="loops-wrapper">
         <div class="list-post">
         <?php get_template_part( 'includes/loop','index');
         break;
      case 3: ?>
         </div><!-- /list-post -->
         <div class="grid2">
         <?php get_template_part( 'includes/loop','index');
         break;
      case get_option('posts_per_page'):
         get_template_part( 'includes/loop','index'); ?>
         </div><!-- /grid2 -->
         <?php break;
      default:
         get_template_part( 'includes/loop','index');
   }
} else {
   get_template_part( 'includes/loop','index');
} ?>
<!-- /child mods -->

I also had to put in a conditional right before get_sidebar() to properly close off the last div. Changing the excerpt to the post content is still handled in the child theme functions.php file.

It all works and I’m now using it my child theme. This only gets applied when I select the two column excerpts page format. Switching to anything else restores the default Elemin formatting.

But you copied and edited a theme file!

Yes, I did and I’m thoroughly ashamed of myself.

There are hooks into different parts of the WordPress loop so that I should be able to put into my child theme’s functions.php file the logic to figure out where in the loop we are and insert the HTML as needed.

The logic is dependent on if we’re at post #1, post #3, and the last post defined by the posts_per_page option. So all I need to do is add the appropriate add_filter() or add_action() to my functions.php file. I already add to the_content using a filter for before and after.

But I’m not quite there yet. I’m pretty sure that I can pull it off with something like add_action( ‘the_post’, ‘insert_before_posts’ ) but I’m still doping it out.

I’m also having a great time doing it too which is really the point of all this effort. Now if only that WordPress Bible would get here sooner…

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.

Time for a new WordPress theme

Old Hybrid child theme

The last time I switched this site to another theme was March 2010, before that April 2008. This time I’ve switched to a commercial them called Elemin. This is a first for me as I’ve never purchased a theme before. But it was on sale for Black Friday and I had been eying it since Automattic added it to their premium theme line up.

It was very easy to work with and the built-in option menus are simple to use. After installing it on my test blog I went to the control panel and made a couple of small setting adjustments. On my home page I want to show the full posts and hide the featured image.

After that I created a child theme and except for small CSS changes, a random header script, some PNG files for said headers, and some code in the child theme’s functions.php file I was all set.

Elemin on an iPad

I could have put the CSS into the theme settings under “Custom CSS” but I’m a huge fan of child themes.

You can examine my changes at the theme’s CSS file here. Rounded corners are a new thing for me; my CSS skills are non-existent.

Naturally the corners don’t work with Internet Explorer 8 and below, but hey, people should upgrade to IE 9.

One of the features I like about this theme is the ability to scale to the browser. When I move the window to become smaller, the columns shrink until the sidebar moves below the content. This causes my blog to be easy to read on an iPad.

Ideally all themes would be fluid and scale like this and it makes the viewing more attractive. I think the Twenty Eleven theme supports some scaling like that already but I’m not entirely sure.

Why a commercial theme?

Primarily for my curiosity. The Themify themes are GPL’ed and the distribution of this code is not restricted. I can make whatever changes I like as well as use the software as I see fit. The GPL is great that way and seeing how professional coders create themes enables me to learn even more.

I know that I could (probably, eventually, I’m sure I could…) get a free theme such as Twenty Ten or Twenty Eleven working like this, but I’m horrible at the styling. This theme is very flexible and the documentation is very good.

One thing Elemin is not is a theme framework. My blog was using a child theme of Hybrid and the theme author Patrick Daly knows his stuff. Patrick’s child theme WP Full Site was packed with PHP! Good stuff, but more than I could utilize. This current theme is more my speed.

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.

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.

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.