WordPress First & Last Navigation Items

I used to have a function which I would include in my WordPress functions.php file that would add a unique CSS class to the first and last menu items. This would be so you could assign them unique styles, such as padding or borders, for better looking menus in your themes.

With the advent of WordPress’s Menu system in version 3, I found it necessary to add some more functions for given situations: calling wp_list_pages(), wp_list_categories(), or wp_nav_menu().  So here they are:

First and Last Class for wp_list_pages();

// adds a unique class to the first and last items in the listfunction add_markup_pages($output) {$output= preg_replace('/page-item/', ' first-page-item page-item', $output, 1);$output=substr_replace($output, " last-page-item page-item", strripos($output, "page-item"), strlen("page-item"));return $output;}add_filter('wp_list_pages', 'add_markup_pages');

First and Last Class for wp_list_categories();

// adds a unique class to the first and last items in the listfunction add_markup_categories($output) {    $output= preg_replace('/cat-item/', ' first-cat-item cat-item', $output, 1);    $output=substr_replace($output, " last-cat-item cat-item", strripos($output, "cat-item"), strlen("cat-item"));    return $output;}add_filter('wp_list_categories', 'add_markup_categories');

First and Last Class for wp_nav_menu();

// adds a unique class to the first and last items in the listfunction add_first_and_last($output) {  $output = preg_replace('/class="menu-item/', 'class="first-menu-item menu-item', $output, 1);  $output = substr_replace($output, 'class="last-menu-item menu-item', strripos($output, 'class="menu-item'), strlen('class="menu-item'));  return $output;}add_filter('wp_nav_menu', 'add_first_and_last');

Disclaimer: I don’t remember where I picked up these functions from along the way, so I apologize if there is credit due to someone, somewhere.

Some Updates

Here are some updates of what has been happening around here lately.

First, I moved in with Rachael a few weeks ago, and last week they pulled a dead person out of the apartment downstairs. He or she had been there long enough to stink up the stairwells pretty bad. The EMS folks had to wear full-on biohazard suits. Check it out:

Dax and I went out to a farm in Clyde with Gary and his girls to check out a party where they were building a real, working trebuchet. Unfortunately, there were a series of setbacks, and they never got the thing working, but it still looked pretty cool.

Rachael and I attended the 16th Annual James Brown Oktoberfest, which was the first time for both of us, where I walked away with the Best Male Costume prize.  No one else was able to pull of the German pimp look as well as I. I owe it all to Rachael, of course, since she sewed my costume (and her own as well).

That’s all for now. Stay tuned!

Quick overview: H vs S vs E IPS monitors

If you’re looking for a new monitor and want the very best for graphic/design usage you may want to look into an IPS display. Obviously, Apples 27 inch is sweet, but unless you’re a dedicated Mac user, you may want to look else where. However, I think they are the only ones with a 27 incher with all those features under a grand at this time.

Anyway, here’s a few quick and decent articles to get you started.

H-IPS vs S-IPS vs TN

List of IPS LCDs

LCD Panel Types

Keep in mind, if you’re a gamer, you may want to stick with the standard LCD’s at this time, especially since 3D enabled ones are decently priced and will work well with your PS3 etc.

HTH

WordPress and jQuery issues

First, I don’t remember where I found this along the way, but this is a smart and efficient way to include jQuery in your WordPress themes. Just add this to your theme’s functions.php file:

// ADDING JQUERY
add_action( ‘init’, ‘jquery_register’ );
add_filter( ‘script_loader_src’, ‘jquery_unversion’ );

function jquery_register() {

if ( !is_admin() ) {
wp_deregister_script( ‘jquery’ );
wp_register_script( ‘jquery’, ( ‘http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js’ ), false, ‘1.x’, false );
wp_enqueue_script( ‘jquery’ );
}
}

// remove version tag to improve cache compatibility
function jquery_unversion( $src ) {

if( strpos( $src, ‘ajax.googleapis.com’ ) )
$src = remove_query_arg( ‘ver’, $src );

return $src;
}

Now, the issue I have been having is that when I try to add your own jQuery scripts or functions in your theme’s header.php file, I always get this error:

“$ is not a function”

What?  Yes it is, dammit!

Turns out WordPress has reserved the $ character, so you have to rename all occurence of $ to ‘jQuery’.  Example:

Before

<script type=”text/javascript”>
$(document).ready(function() {
$(‘.slideshow’).cycle({
fx: ‘fade’,
timeout: 4000,
speed: 2000
});
});
</script>

After

<script type=”text/javascript”>
jQuery(document).ready(function() {
jQuery(‘.slideshow’).cycle({
fx: ‘fade’,
timeout: 4000,
speed: 2000
});
});
</script>

Hope that saves someone the hours of frustration I have had with this.

Guatemala Day Something

It’s Tuesday, I think. We have been very discombobulated regarding time since we got here. Guate is 2 hours behind home, and there is no daylight savings, so having recently done the time change in the US, going back to standard time here, minus an hour, is weird.

Anyway, yesterday turned out to be quite adventuresome. Rachael and I went and did a little yoga in the highest temple, which was awesome. We were then scheduled for massages from a Phillipino-Hollander named Theo. He gave the best massage ever. As you may know, my wrist has been an issue for me the last couple of months since I sprained it one night at band practice. Theo work on it, and he got it feeling very good.

While Rachael was getting her massage, I met a nice guy from Seattle named Jeff, who was here for the week-long yoga retreat. Every week at Villa Sumaya, there are retreat packages that people sign up for, but you can also come for ‘personal’ retreats, which is technically what Rach and I are doing. Jeff and I talked about basketball and other interesting things as we checked our email.

After the massages, we walked with Lizzy to Santa Cruz to see Myles and check out her place. Lizzy lives in a place where the translation means “the place where the rocks fall”, and indeed, it was strewn with rocks from the high cliffs surrounding her. During hurricane Agatha last year, there was a giant rockslide all around her house, and a layer of rock five feet high covered the surrounding valley. Her place was largely spared, luckily.

It was great to see Myles, and he was excited to get the gifts I brought from Dax and Gray. We hung out around Lizzy’s place for a while until we decided to get back to Villa Sumaya for dinner. Rachael and I took off on foot to make the journey back, which was about a 40 minute walk.

Heading down through the valley towards the lake, we commented on how exciting it was to be all alone in the middle of the jungle in Guatemala. Shortly afterward, we heard barking dogs running towards us through the trees. After having seen all these wild dogs then last few days, I had visions of hungry teeth snapping at us.

My adrenaline kicked in, I said, “come on” to Rachael, and the next thing I knew I was 12 feet up the tree next to me, trying to make sure she had enough room underneath me to make it to safety. As she started to climb up behind me, the dogs stopped, and we realized that they cared nothing at all about us, and were fighting with each other.

We soon were laughing at the whole thing. Yes, I overreacted, but all I know is that if it had really been a rabid pack of dogs trying to eat us, we would have been safe thanks to my cat-like reflexes!

We made it back to dinner at last and had a good time enjoying the cool evening air.

Today, we decided to take it easy. I worked with Lizzy some to update the Villa Sumaya website, after which Rach and I got some sun by the pool. After a dip and some lunch we hit the sauna.

Tomorrow we meet Lizzy at the dock to get a boat into Panajachel where we plan on hitting the market and having lunch. Hopefully there will be no more rabid dogs.