pancake theorem a tech/life blog


Yearly Archives for 2010

Using CSS border-image to make a neat wooden frame 12.21.2010

[Update 5/25/2011: Check out my border-image generator for Polaroid-like photos!]

CSS border images work in the most bizarrely beautiful way, with a single image being sliced into 9 pieces and used to surround our wonderful content with whatever we please (so long as we’re using compatible browsers-this worked for me on Firefox, Chrome and Safari on the Mac-but we can use regular borders as a fallback).

One thing I wanted to try out was making a wooden frame out of a “wood texture” I found online, and use CSS to display and easily manipulate frame thickness. It’s tedious to put frames around multiple images, especially when you want to test different thicknesses and designs. Even if you don’t want to risk compatibility issues, CSS border-images are a great tool to use when mocking up your design with more efficient trial and error whenever you are putting any image border around your content.

Here is the effect that I got:

dreamboat pete, framed

Continue reading


Making a head explode into confetti with CSS3 is actually not a cure for the common cold, it turns out. 12.14.2010

I was couch-ridden these past few days with the worst cold ever (I can judge, because I once had Mono for 2 months longer than I was told I was supposed to). It left me with little motivation and focus to do real work-also it was the weekend-so I caught up with my RSS feeds, played around with this site’s layout & style, and experimented with CSS3 to see if I can get a head to explode into confetti.

Continue reading


More Than You Ever Wanted to Know About Cubic Bézier Curves and Their Use In CSS3 Transitions 11.22.2010

CSS3 introduces the transition property, which adds some new behaviors that we used to only be able to do with JavaScript or Flash. I’ve been using transitions on this site for a long time, to add a cool fading color-change when you hover over any links. You can find tons of resources on the Web about the property, specifically the syntax.

#elementID { transition: target-property, duration, timing-function; }

Of course, vendor prefixes are necessary, and from what I can tell it only works in Webkit browsers (like Safari and Chrome), but I’m not here to write a blog about a CSS3 property (plenty of that nonsense already all over the Web). I want to discuss the timing functions, because it’s become very stylish to just blow off the mathematics of Web design and development. Let’s make math sexy again, and fail miserably…

Continue reading


Hide/Show WordPress post content when clicking post title, with jQuery 10.12.2010

Less cats, more code. Let’s roll…

This week I deployed/launched/droppedlikeitwashot a new version of Barista Kid’s Upcoming Events page.

It’s basically a separate blog within our network of WordPress sites. Each day had a single entry with events listed within the post and were scheduled for the day of those events (I have the blog set up to publish future posts). This was totally inefficient, though, and Georgette (the editor-in-chief) wanted something nicer, efficient’er and a little more dynamic’er.

We wanted to have individual posts for each event, and just have the event’s name and date show. When the user clicks the event title, then all extra information and copy would show by sliding down. Here is how it looks all jQuery’d and prettied up:

So there are two important elements to making this work:

1. You need the content to hide. In this case, I’m hiding any output of the_content(). I wrapped that function call with a div of class="event-info".

2. You need the trigger for showing and hiding your content. I want to have the content toggle when the user clicks on the title, which is output with the call of the the_title() function, so I wrapped that in a h3 header of class="event-title".

<h3 class="event-title">
	<?php the_title(); ?>
</h3>
 
<div class="event-info">
	<?php the_content(); ?>
</div>

If you go to the site, you can see that I have a LOT more going on in the loop than just title and post content, but you can get the gist of what’s going on. Anything inside the event-info class will be hidden and clicking on anything inside the event-title class will toggle the visibility of the event-info class.

Of course, nothing is happening now, because we need some jQuery to make it work. And to make this jQuery code work, you need to import the jQuery UI library along with the main one. You can get links to the latest versions on Script SRC. Let’s start with the code:

<script type="text/javascript">
jQuery(document).ready(function($){
 
        $(".event-info").hide(); // make sure all content in event-info class is hidden
 
    	$(".event-title").click(function(){
	    	// find the .event-info within the same div as .event-title is and slide to show
	    	$(this).parent().children(".event-info").toggle("slide", {direction: "up"}, 500);    		})
 
});
</script>

You can do an if/else statement to show content if hidden and vice-versa, but using the toggle function eliminates the need. What that parent/child nonsense does is make sure that we’re only toggling the event-info content that is in the same post as the event-title we are clicking on – otherwise every single post’s content will show when you click on any title. This will cause mayhem with the user experience gods, and myself.

Whenever I teach JavaScript or any language, I like to stress that some really cool things can be done with just a little bit of code. This change to the Events site is a great example, because not much work was needed to transform this blog-like page into a sophisticated events listing.


Elegantly showcasing Tumblr posts in WordPress 08.17.2010

I’ve been using Tumblr for nearly a month and I absolutely love it. My site remains on WordPress, and it will continue to do so, but I wanted to bridge the gap between the two platforms to make the transition easy for my site visitors (dad) and myself. Tonight, I did just that.

Using some extra PHP within a WordPress page template, and some beautiful jQuery (Masonry, courtesy of David Desandro), I created a showcase of excerpts of my 10 latest Tumblr posts. To fit this with the rest of the theme and style of my website, I went beyond just showing a bulleted list in a widget and, instead, put each excerpt into it’s own box.

You can see the demo page right here.

When you’re working with WordPress, you already have a lot of pre-made PHP functions at your disposal – in this case, those for fetching content from an RSS feed. I grabbed the latest 10 posts using my Tumblr’s RSS feed and placed the following PHP in the page template where I wanted it to go:

<div id="tumblr-feed">
	<?php require_once (ABSPATH . WPINC . '/feed.php');
	$rss = @fetch_feed('http://feeds.feedburner.com/jennschifferontumblr');
 
	if (!is_wp_error( $rss ) ) :
		$maxitems = $rss->get_item_quantity(10);
		$rss_items = $rss->get_items(0, $maxitems);
	endif;
 
	if ($maxitems == 0) echo '<div class="tumblr-post">Nothing to see here, folks.  Go to <a href="http://pancaketheorem.com" target="_blank">pancaketheorem.com for the fun stuff.</div>';
	else
	foreach ( $rss_items as $item ) : ?>
		<div class="tumblr-post">
			<p><?php echo string_limit_words($item->get_description(), 25); ?>
		[<a href='<?php echo wp_filter_kses($item->get_link()); ?>'>read more...]</a></p>
		</div>
	<?php endforeach; ?>
 
   <?php } ?>
 
</div>

tumblr-feed is the container that holds all the tumblr-post boxes. You need the container for using the Masonry function later on.

Within the tumblr-post div, I’m echoing the description of the post (the post content). I don’t want the entire entry to show, though, so I created a function called string_limit_words that takes a string and your maximum word count and outputs an excerpt of your post. To use that function, though, you need to add it to your functions.php file within your WordPress template:

function string_limit_words($string, $word_limit)
{
  $words = explode(' ', $string, ($word_limit + 1));
  if(count($words) > $word_limit)
  array_pop($words);
  return implode(' ', $words);
}

So that will display your content. Of course, you need to add some CSS to make your tumblr-post boxes look fabulous and float. I also made sure – and this is important – that the maximum width of any images or embeded objects are the same size or smaller than the tumblr-post box width. The rest of my CSS is just for styling the header and paragraphs.

.tumblr-post { width: 270px; padding: 5px 15px; float: left; margin: 10px;}
.tumblr-post img, object, embed { max-width: 270px;}
.tumblr-post h3 { font-family: Helvetica, Arial, sans-serif; font-size: 15px; font-weight: bold;}
.tumblr-post p { padding: 2px 0; margin:0;}

Now, to make your boxes float nicely, without any vertical gaps, download Masonry, load the script in your template, and then add this snippet of code to your template’s Javascript – be it external or internal:

$('#tumblr-feed').masonry({
    singleMode: true,
    itemSelector: '.tumblr-post'
});

This is why you need the tumblr-feed container – so that the Masonry function knows where to look for the boxes that it’s laying out.

I apologize for not getting deeper into explaining all of the code, this was just something I threw together late this evening, after spending the entire day getting my freaking iPhone 4 activated. My point in all this is that it’s really easy to integrate content from two completely different platforms, thanks to RSS and PHP. If you have questions, you can comment here or email me or whateva.