Blog

PDA for PDD

Late this past Sunday night, I launched the Philadel­phia Design Direc­tory, a personal project I had been work­ing on for the past 4 months. The response has been huge and I’m pretty over­whelmed by the amount of people that have contacted me in the past two days to get listed or to show their support. I’m not usually one to brag so I thought I’d share some of the responses I’ve received about the site.

“Thanks again for doing this site — fantastic!”

“Just wanted to say thanks for creat­ing such a great resource for the Philadel­phia creative community!”

“Look­ing forward to the site expand­ing and grow­ing even more!”

“Very cool. This may help me change my life!”

“It’s absolutely beau­ti­ful, and by far the best resource I’ve seen for connect­ing our community!”

In my port­fo­lio, I describe this project as an exper­i­ment. What I mean by that is that I’m adopt­ing an open source philos­o­phy to the site by open­ing up the devel­op­ment process of the site. I will soon publish a public changelog so site users can see what is planned for the site, give feed­back on the site, and how it has evolved. If you have any sugges­tions, do get in touch.

I’m really glad the site has already helped so many people and really hope it contin­ues to help build our commu­nity. I couldn’t be more excited about this project.

Cycle on the Fly

Cycle has to be my favorite jQuery plug-​in for slideshows/​galleries. It’s light­weight, super easy to imple­ment, and it’s highly customiz­able. The bummer is if you throw just one image at it, it breaks. Up until now I had been using two templates for galleries — one for single image pages and one for multi­ple image pages. Then it hit me why not use jQuery to check to see how many elements are in a DIV and then spit out navi­ga­tion if neces­sary. Bingo! So easy I should have thought of that one sooner.

So how-​se work-​se?

First grab jQuery and the Cycle plug-​in.

Load ‘em up in the header as normal.

1
2
<script src='path_to/jquery.js' type='text/javascript' ></script>
<script src="path_to/jquery.cycle.js" type="text/javascript"></script>

And now the fun part.

Cycle has a built in trig­ger that can be used to target a DIV to cycle and addi­tional trig­gers for DIV’s to be used as “buttons” for previ­ous and next tran­si­tions. For multi­ple image only galleries, this is super easy place some images in the cycle DIV and add some Previ­ous and Next DIV’s in your template. Then just tell Cycle which ones to use for which. But in our case we want to use a single template for single and multi­ple image galleries. So this won’t quite work — unless you think busted single image galleries or buttons that don’t work on a page is a good thing…

What we need to do is write some extra code that checks for the number of images on our page and then dynam­i­cally add our navigation.

The Check

jQuery has a built in core func­tion called .length. Guess what it does? That’s right checks the number of elements in an object. All we need to do is create a vari­able to hold this number and then test it to see if it’s larger than 1.

Here we go.

1
2
3
4
5
var img_no = $('#gallery . *').length;
 
if( img_no >= 2 ) {
     $('#img-nav').append("<span id='prev'>Previous Image<\/span> / <span id='next'>Next Image<\/span>");
}

Here, I’ve created a vari­able called img_no and its value is set to the total number of all elements (* = all) within a DIV I’ve given the ID of gallery. I then take this number and first check to see if it is larger or equal to 2. If it is true, I then use another jQuery func­tion called append to add a chunk of HTML to our page within an empty DIV called img-nav — one span with the ID of previous for our previ­ous button and one span with the ID of next for our next button.

Wiring it all up

Now that we’ve got our check set in place all we’ve got left to do is tell cycle what to cycle and what to use as our buttons.

1
2
3
4
$('#gallery').cycle({
    next:   '#next', 
    prev:   '#prev'
});

The first part $('#gallery').cycle tells our page to to use the gallery DIV as our cycle. Next, I use the built previ­ous and next func­tions using next: and previous: and tell each of them to trig­ger their respec­tive ID’s.

And viloa, single template gallery. That simple.

WP Last Update

Pretty recently, I had to add a “Site last updated” feature to the footer of a Word­Press site. Now there’s a couple of plug-​ins that will do this auto­mat­i­cally for you but if all you really need is the date of the last update, all of these plug-​ins are a little over the top. Believe it or not, every­thing you need is built right into WP in the get_lastpostmodified() func­tion. And with a little more PHP we can take this value and format it any way we like.

Let’s have a look…

The WP func­tion get_lastpostmodified() retrieves the last time a post was modi­fied. But that’s it, it just retrieves the value. To get it to show up, just echo the function.

1
<?php echo get_lastpostdate(); ?>

You now should have some­thing like this:

2009-11-10 11:38:47

That’s the raw date format from the data­base, but with a little more PHP we can take this value and make it pretty. As you prob­a­bly can guess, we’re going to use the PHP Date function.

Here’s our code:

1
<?php echo date("F j, Y", strtotime(get_lastpostmodified())); ?>

Ok so what’s all that…

We call the PHP Date func­tion with date — pretty obvi­ous, I know. Next we tell it what format we want — I’m using F j, Y but there’s a lot more ways you can output this — check the func­tion refer­ence to find the format you want. Our exam­ple will give us a format like this: Novem­ber 13, 2009. The impor­tant parts of this are the alpha­betic char­ac­ters; commas, dashes, spaces are optional.

Next we use the Word­Press func­tion get_lastpostmodified as a value for strtotime. The strtotime takes then takes our value, expects be a US English time­stamp and then tries to parse it to a UNIX time­stamp. The UNIX time­stamp then can be format­ted with our F j, Y and the date func­tion tells it how to be handled.

No clunky plug-​ins to manage, just a single line that does it’s thing. Pretty simple right?

совместимость гороскопов весы рак что обозначает дракон в гороскопе мужчина рыбы по гороскопу знак зодиака рыбы сексуальный гороскоп женщины совместимость гороскопов женщина стрелец мужчина весы описание гороскопа мужчины козерога любовный гороскоп на 2012г весы любовные тесты или гороскопы на совместимость гороскоп 2012 петух близнецы любовный гороскоп водолей назавтра гороскоп знака рыбы на 2012 год гороскоп на 2012 год для петуха скорпиона персональный гороскоп льва на 2012 год гороскоп для близнеца женщины гороскоп совместимости кабан и кабан гороскоп для раков на завтра sitemap любовный гороскоп 2012 водолей у солдата выходной mp3 скачать скачать песню из фильма кровавый спорт гороскоп рыбы характеристика знака скачать драйвер принтер canon lbp2900b гороскоп совместимости знаков для скорпиона бандитский петербург 2 адвокат скачать гороскоп дева 2012 работа совместимость гороскопов весы рак скачать доктор веб на русском языке шпаргалка по праву социального обеспечения скачать скачать игру на pc гонки самоучитель по программированию 1с скачать скачать total eclipse of the heart bonnie tyler гороскоп рыбы петух 2012 год