April 18, 2011

CSS3 Columns in WordPress after a Certain Word Count

I've been using CSS3 Columns for various purposes lately. I've been really loving it. Especially how easy it is to manipulate from 3 to 2 or 1 count with media queries. More on that stuff later. The purpose of this post is mainly to share with you (and document) how to use this in WordPress and only when your content is over a certain length. (what is the point of having three columns if there only one to three lines each?!)

first of all: make sure you have your CSS3 columns setup for the first div class:

[code]
.article-col{
-moz-column-count: 3;
-moz-column-gap: 40px;
-moz-column-rule: none;
-webkit-column-count: 3;
-webkit-column-gap: 30px;
-webkit-column-rule: none;
column-count: 3;
column-gap: 40px;
column-rule: none;
}
[/code]

and then here is how you explode your the_content(); - get your word count - and then change the div class depending on the limit.

[code]
ob_start();
the_content();
$content = ob_get_clean();
$numWords = sizeof(explode(" ", $content));
$limit = 100;

if( $numWords > $limit ){

echo '<div class="article-col">';
}
else {
echo '<div>';
}

the_content(); ?>
[/code]

your $limit can be set to whatever your design is comfortable with. also, you can class that second div with something else (you can do something creative like change the div from two col to three col depending on the word count.)

More on css3 columns:
http://www.alistapart.com/articles/css3multicolumn/

Love and use this to make it work in IE:
http://www.csscripting.com/css-multi-column/

Thanks @joncave and @petemall for brainstorming this a bit with me.
sara

January 12, 2011

2010 – the year of WordPress

2010 has been an incredible year. It had its ups and downs. some parts were really hard and others just joyous! I've met some incredible people this year and got plugged into a great community that surrounds the very platform that this blog (and my livelihood) is based on: WordPress. Its been quite the journey. I've stumbled into great opportunities that led me to go many places and meet many new friends.

1/8-9 - WordCamp Atlanta

(Post on my talk: WordPress and Your Brand)

5/1-2 - WordCamp San Francisco

(I just went to this one: Recap Post1, Post2)

8/20-22 - WordCamp Savannah

(Post on my talk: Customizing WordPress themes / Child Themes)

9/18-19 - WordCamp Birmingham

(Post on my talk: Beyond the System Font: Advanced Web Typography) Other Post

10/16-17 - WordCamp NYC

(Post on my talk: Typography and Your Theme)

In conclusion: 2010 rocked my WordPress world. Thank you to everyone who has mentored me and guided me in the word of WordPress. And, absolute special thanks to those who contribute in any way to the release and improvement of this incredible software. - sara

December 16, 2010

WordPress Mode + Coda

I just have to say, this is incredible if you work in WordPress and use coda: http://pradador.com/code/coda/wordpressmode/
also, here are some WordPress clips for coda: http://coda-clips.com/category/wordpress
Thanks Dan!

Also, completely unrelated: this site is a great representation of responsive web design: http://hicksdesign.co.uk/
and I just love the colors and the awesome use of jQuery in this one: http://www.seattlesbest.com/

What are some sites you've been loving recently?
sara

October 16, 2010

Slides from WordCamp NYC “Typography and Your Theme”

Thanks to everyone who came out to my session at WordCamp NYC! I've uploaded my slides to slideshare for you to view. Please feel free to leave comments or even just let me know what your favorite webfont is!

October 4, 2010

Targeting Your Fonts in Firefox on Windows

Well, you can use this trick for just about anything in your CSS really. It just so happens that at a certain small weight, Museo Sans really crunches on Windows XP Firefox. Weather or not we can target specifically XP I'm not sure yet.. (if anyone knows chime in!) But we can target all Firefox's on all Window's Machines. So here is how you do it...

1. Make a css file called ff.css and put this code in there:

[code]

@-moz-document url-prefix(){
#hackery {
font-family: Helvetica, sans-serif;
}
}

[/code]

Now that you've made your little hack document...

2. fill up in between the moz brackets with whatever selectors you are trying to change.

3. call your new ff style sheet in your header.php like so:

[code]

<?php if (strpos($_SERVER['HTTP_USER_AGENT'], "Windows", 0) !== FALSE) { ?>
<link rel="stylesheet" type="text/css" media="all" href=&quot;ff.css" />
<?php } ?>

[/code]

voila! Firefox targeted on only windows!

You can now fix your fonts and go from this: (crunchy liberation serif to georgia italic)

to this:

To target Window XP in particular (note that this would not cover versions before that), this should work.

[code]
<?php
if ( false !== stripos( $_SERVER['HTTP_USER_AGENT'], 'Windows NT 5.1' )
|| false !== stripos( $_SERVER['HTTP_USER_AGENT'], 'Windows XP' ) ) :
?>
<link rel="stylesheet" type="text/css" media="all" href="ff.css" />
<?php endif; ?>
[/code]

August 27, 2010

Combating IE6: Drop Down Menu Plugin for WordPress “twentyten” Them

twentyten

I'm in love with the newly crafted WordPress theme "twentyten." The code is clean and the included functions are spot-on. So, I've decided to start making Child Themes based on twentyten. The one problem I would run into is in Internet Explorer 6. Now, I know that everyone hates it and that we all need to move on into the future.. but.. I have clients that I really need to continue support of that legacy browser. The problem that I encountered was with the drop down menu system. The code is so beautiful and perfect, but it just uses CSS... which IE6 can't recognize. So I decided to write a plug in (with a bit of helpful advice from some awesome geniuses) that I can install whenever I make a child of twentyten and need it to support drop downs in IE6.

WordPress Plugin Page: http://wordpress.org/extend/plugins/twentyten-ie6-menus/
DOWNLOAD from WordPress: Twentyten IE6 Menus

Here is the plugin php file: (if you don't want to use it as a plugin.. just steal the jQuery)

[code]
<?php
/**
* Plugin Name: Twentyten IE6 Menus
* Author: Sara Cannon
* Author URI: http://sara-cannon.com
* Description: Make the menu drop down in IE6 (if you care about that sort of thing)
* Version: 1.0
* License: GPL2
*/
function sara_twentyten_ie6_menus_enqueue() {
wp_enqueue_script( 'jquery' );
}
add_action( 'after_setup_theme', 'sara_twentyten_ie6_menus_enqueue' );

function sara_twentyten_ie6_menus_script() {
?>
<!--[if lte IE 6]>
<script type="text/javascript">
jQuery(document).ready( function($) {
$('#access li').mouseover( function() {
$(this).find('ul').show();
});
$('#access li').mouseleave( function() {
$(this).find('ul').hide();
});
$('#access li ul').mouseleave( function() {
$(this).hide();
});
});
</script>
<![endif]-->
<?php
}
add_action( 'wp_footer', 'sara_twentyten_ie6_menus_script' );
[/code]

Feel free to download and use and let me know if you encounter any bugs.
-sara cannon

This probably won't mean anything to you, but I wanted to document this for my reference. Here are some of the sites I visited when initially researching how to make this plug in. There are probably many more that I hit up in my research later on but I just thought I'd throw this in here considering it is on the same subject lines.

http://www.jdmweb.com/resources/jquery_to_wordpress_plugin
http://www.devlounge.net/articles/using-javascript-and-css-with-your-wordpress-plugin
http://www.lost-in-code.com/platforms/wordpress/wordpress-plugins/wordpress-build-a-thickbox-plugin/
http://www.noupe.com/tutorial/drop-down-menu-jquery-css.html
http://designreviver.com/tutorials/jquery-css-example-dropdown-menu/

March 27, 2010

Using Flutter for a Restaurant Menu in WordPress

I want to share with you something technical that i've been working on in WordPress. (you don't have to read this if you don't want to I won't be offended) Also, bear with me as I don't usually write technically as much as I should. Here we go....

I've been making a website in WordPress for a local fine-dining restaurant.  Their food and wine is spectacular. Anyway, I made some custom CSS for the restaurant menu. Custom alignments for different data, etc. Not a problem for me to implement, but I needed a way for the restaurant chefs and managers to update the menu without messing with the code. I tried WYSIWYG editors, which made changing menu items fine, but adding menu items in would mess up half the time. So I decided to use custom fields with the plug-in Flutter.

However, local developer Tammy Hart has told me that soon, with the release of WordPress 3.0 that includes Custom Post Types, we might not need to rely so heavily on the plug in flutter for custom content types as we do now. That being said, I am still going to tell you what I found to be helpful in building a restaurant menu in flutter. But I thought you should know.

Here is the general CSS Layout that I've done:

I installed Flutter. I then made three "Custom Write Panels" - one for each kind of menu I have.

This makes a new items on the Admin Bar. I especially wanted this because the restaurant can "manage" and update their menus daily and wont have to dig far.

After I did that I made the specific custom fields for the Menu Item Name, The Item Description, and the Price. The three things I need to insert into my CSS to make each dish look right. And make a Field for the Name of the Grouping (appetizers, etc) at the bottom so that the restaurant can change "Entree" to "Main Course" if they want and so-on.

Now that we are all set with our fields, we can start making the template. Take your page.php file or other custom template file you have made, and after <?php the_content(''); ?> we need to call our fields.  According to Flutter's Usage: to get one variable you use <? echo get('variable'); ?> to call.  However, in our menu items, we need to call duplicates. I started using getGroupDuplicates to call all the menu items, but I ran into a problem with the items that were deleted still showing up (bug?!). that is when I found This Thread .

In the file get-custom.php add this function:

/** Developed by Thang
* Return a array with the all distinct values in one array
*
* @param string $groupName
*/
function getDistinctGroupOrder($field_name){
global $post,$wpdb;
$elements  = $wpdb->get_results("SELECT DISTINCT group_count FROM
".RC_CWP_TABLE_POST_META." WHERE post_id = ".$post->ID." AND
field_name = '".$field_name."' ORDER BY order_id ASC");
foreach($elements as $element){
$order[] =  $element->group_count;
}
return $order;
}
Than in my Custom Template I added the following (this is for the appetizers section):
<?php $group_orders = getDistinctGroupOrder('app-menu-item');

foreach($group_orders as $group_order)
{ ?> <div id="foodmenu"><dl>
<dt>
<?php echo get('app-menu-item',$group_order,1); ?>
</dt>
<dd class="price">
<?php echo get('app-Item-price',$group_order,1); ?>
</dd>
<dd class="ingredients">
<?php echo get('app-item-description',$group_order,1); ?>
</dd>
</dl>
</div>
<?php }
?>

And then you just do the same for all sections on all templates and make sure that your field names match up.

However, I want to make this fool-proof. What if on the Special Menu, they did not want dessert? Setting up the template this way assumes that these are filled out. So, I have to set up a conditional statement so that I dont get a gap displayed with no items in it. Here's how you do that- add this to your template file:

<!-- check to see if there's actually content filled in.  -->
<?php
$content = get_post_meta($post->ID, 'd-item-name', true); if ($content) { ?>

Then put in your flutter/template code in, and then add this at the end.

<?php } else { ?>
<?php } ?>

So for this "Dessert" Section, my code looks like this:

$content = get_post_meta($post->ID, 'd-item-name', true); if ($content) { ?>
<?php $group_orders = getDistinctGroupOrder('d-item-name');
foreach($group_orders as $group_order)
{ ?> <div id="foodmenu"><dl>
<dt>
<?php echo get('d-item-name',$group_order,1); ?>
</dt>
<dd class="price">
<?php echo get('d-item-price',$group_order,1); ?>
</dd>
<dd class="ingredients">
<?php echo get('d-item-description',$group_order,1); ?>
</dd>
</dl>
</div>
<?php }
?>
<?php } else { ?>
<?php } ?>

All this does is checks to see if you have fields filled out. If you dont, it just moves on.

Here is what the Custom Write Panel looks like in your page editor:

Simple huh? You just duplicate the group to make more Entres. There are also the other panels there too (appetizers, desserts, etc) So the restaurant can now add and subtract Menu Items without any fear of messing up the custom CSS. And, with the way you can label things, you can make adding a menu item pretty intuitive. (no more non-labeled Custom Field box! "value"?! what does that mean?)

Anyway, it does takes a bit of effort, but it is worth it in the long run. I wont be getting calls every time they update something and messed it up. or don't understand, etc. Flutter can be a bit clunky for beginners. (I was really scratching my head and wondering where all the simple documentation was located) But, there are some good articles out there. My friend Tammy Hart pointed me to this one on duplicate fields. And, I found this one to be helpful as well.

Here's to the wait for WordPress 3.0. and Custom Post Types.  Till then, Flutter away!

- sara cannon

Sara Cannon is a Design and Digital Strategy Consultant, UX/UI Designer, Creative Director, & Artist.
Have a project I could help you with? Contact me at sara@saracannon.com.

Skip to content