Mostly about my amusement

Author: Jan Dembowski (page 17 of 96)

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…

Christmas Tree Time!

Last year, the Sunday right after Thanksgiving I put up the Christmas tree with just the lights. I had intended to finish it after work but each week night I was too tired to do it. I get home after 7 PM and generally want to eat and relax. So the tree went a week without being completed.

Fortunately some friends came over the next weekend and with their help my family completed the tree. This year the same thing happened, except I planned it. The tree was put up this morning and after lunch my friends came over and helped my family again.

We all had a great time and Lily also put up some new decorations in front of the house. The kids made a mess in the basement but that happens when you have 6 kids running around. It’s now Christmas time and all is right in my world.

I can get used to this new tradition and I really enjoyed having our friends over with their kids.

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.

(Was) Microsoft Touch Mouse

For years I’ve been using the Logitech MX Revolution mouse and it’s gotten long in the tooth. The pointer would stutter, the mouse buttons wouldn’t click, the click would release at the worst time, etc.

I could read the signs and it was time for it to go.

I was leaning towards getting the Performance Mouse MX but I figured I’d give Microsoft a shot and picked up the Touch Mouse. Naturally I got the “artistic” version. Both versions are expensive.

The Touch Mouse is supposed to be the Microsoft version of the Magic Mouse. The materials are nowhere near Apple standards but it’s a good plastic attempt. The ergonomics are acceptable and it’s comfortable to use. I prefer to be able to rest my hand on the mouse and it’s just the right size.

There is just one little drawback. It really only has one physical button so mouse button combinations are not doable. When you want to right mouse click you need to lift your finger off of the left side and there is no middle button. This is not really a problem and I’ve been using the Apple Magic Mouse like this for a long time. By installing AutoHotkey I’ve already started making macros for Apple like mouse-keyboard combinations.

I’m bringing this up for one reason. In FPS games, I frequently press and hold down the right mouse button to zoom into my target while pressing the left button to fire. This is a good strategy while hiding behind cover.

. . .

Okay, that will take some getting used to. I’ve already mapped the right mouse button to the left control in one game and with a little practice I’ll be back to normal. It’s a good thing I haven’t purchased MW3 yet.

Update the very next day: I returned the Microsoft Touch Mouse to Best Buy and picked up the Performance Mouse MX. It’s on sale and the price now matches the Touch Mouse. It was the buttons or lack of buttons that made me do it; this is not a mouse for anyone who plays games.

Now validated with StartSSL

So while I was putzing around with my SSL sites and getting some grief with mod_gnutls, I realized that my life really would be much easier with a valid wildcard SSL cert.

So naturally I went to StartSSL and went through the process for a Class 2 Validation. I had meant to do it for a long time and have been using their free Class 1 certificates for ages.

The process was easy and once I logged in, I uploaded some documentation and waited for the administrative work to complete. I used PayPal and shortly afterwards I received a phone call from Startcom. It was Eddy Nigg personally calling me to ask me the control questions.

I couldn’t help myself and I laughed out loud. I have been long admiring what he and his company have been doing with affordable SSL certs. I regard what other CAs charge as quite a successful scam and StartSSL’s efforts have been well on par with the other “Big names”.

So now I’m successfully validated, using a wildcard SSL cert for my entire domain, and I am officially a satisfied customer. I can’t recommend them enough.

Getting carried away

https://twitter.com/#!/cynthiaboaz/status/139599128601706496

This sort of statement is inflammatory and is just another false equivalency. Yes, UC Davis and other militarization of American Police is awful and frightening.

But OWS is not a revolution and people really aren’t dying here. Not liking the outcome of elections or how the democracy played out isn’t what’s happening in Egypt.

Occupy Wall Street is an valid and legitimate protest but it’s important to remember that it’s just a protest and nothing more. Wishing otherwise doesn’t make it so and getting past a fad is a tough thing to do.

I don’t like the Tea Party. I think that they simplify politics to the absolute lowest common denominator and their complaints can be summed up as “It’s all YOUR fault!” with the YOUR being whoever is the flavor of the week. And despite words to the contrary, they do bring out racist behavior.

That said, as an American I am immensely proud of the Tea Party method. They organize and they vote. I don’t like their intentions but they are using the system and are achieving their goal of changing what the elected officials do and say.

The Tea Party drives the Republican Party. Just look at the endless GOP debates. With the possible exception of Jon Huntsman, each one of those candidates is pandering to the radical right. Mitt Romney is struggling because he’s compromised in the past as any good leader should do.

If Occupy Wall Street wants to change the way the 99% are being used by the 1%, then they have to work within that system. We’re not Egypt and comparing the situation to Tahrir Square is disrespectful of those efforts. The OWS protests have shown that they can get lots of people together but can they accomplish change like the Tea Party does? That remains to be seen.

Another Olympus Trip 35 for me

Camera 360

Back in March 2011 I started taking photos with my newly acquired Olympus Trip 35 cameras. Since then I’ve taken hundreds of photos with them and even went to China with them.

In China I gave one of them to my wife’s cousin and he takes excellent photos with it. I kept the Tripman one and the oldest one is safely put away in the basement.

I broke the Tripman one. I had it in my bag last week and put the bag down hard. As soon as I did it I thought that’s it and I was right. The shutter is no longer working and the inside has something rattling around that I can’t locate. Taking it apart didn’t help and after a while I gave up.

So I went to plan B and ordered a replacement from Tripman and another one from an eBay seller. I’m back to having three functional cameras. The new Tripman arrived today and I’m planning on taking lots of photos this afternoon.

The eBay one came Wednesday and I’ve already shot a roll with it. If there are no light leaks and the photos are okay, then I plan to strip the leatherette and put on a different one. I’ll let the kids decide which color.

Once again, anyone considering a film camera should take a chance with eBay and get one. Thanks to eBay sellers I now have two working ones and each one cost me less that $40 each including shipping. The Tripman version is more money, but I got that one because it just works, has a warranty, and is really in great condition.

If you don’t mind spending a little more then you just can’t go wrong with Tripman. They’re great reconditioned models and they ship quickly.

As for the broken one, I’ve sent an email to Streetshooter in the UK to see what the backlog on his services are. Just because I can’t fix it doesn’t mean I want to leave it broken.

Google is my co-pilot

Google’s car navigation for Android phones is pretty good.

The majority of my work is 9 to 5 weekdays but when I need to make (fully approved, vetted, it’s-not-my-fault-and-I-won’t-do-it-again) production changes I have to wait for after 5 PM. Depending on the potential impact, I have to wait until Saturday. This weekend the group I work in was doing Big and Potentially Terrible Things™ and I was part of that.

Yesterday I left the house at 5 AM, drove to Queens and Chinatown to pick up 2 co-workers, and drove 2 and a half hours to Princeton, NJ. I got home after 8 PM. And I used the Google Maps Navigation for Mobile Beta (GMNMB?) as my tool to get there. I turned on Bluetooth (I was in the car), Wi-fi, and GPS and plugged my phone into the car charger. The cup holder doubled as my GPS mount.

My phone has GPS, Verizon assisted, and Google assisted location services and I turned it all on. I did not expect wi-fi to work exactly but I wanted to use that to narrow down my position. It worked fantastically and suggested routes that I would never have thought of. Before 8 AM the drive was uneventful and except for my pal who knew better, the navigation worked well.

When I drove home, instead of suggesting the painful Holland Tunnel to BQE which it did on the way there, it lead me to Staten Island and eventually to the Belt Parkway. It took me just 2 and a half hours to get home about 100 miles away.

Yes, that doesn’t sound breathtakingly fast but I drove through New Jersey, Staten Island, and Brooklyn on a Saturday evening. Fellow New Yorkers who drive will know what I’m taking about.

The map data does not live on my phone and it’s all downloaded and cached from off of the Internet. This entire solution is dependent upon good connectivity. If I were driving to a desert in Arizona then I would use a Garmin or TomTom. But for driving in a metropolitan area this solution can’t be beat.