Display What Page You’re on in a WordPress Post
Did you know that you can break WordPress posts into multiple pages by adding <!--nextpage--> to the html of your page content?
Here's a easy way to output the current and total pages in your post (in your theme file):
<?php
if(isset($pages) && count($pages) > 1)
{
echo '<span class="page_navi">(page ' . $page . ' of ' . count($pages) . ')</span>';
}
?>
We only display that code if there's more than one page. The $pages variable contains an array of the_content() broken into their individual pages, and the $page variable is an integer of what the current page number is.
This little snippet will output something like: (page 2 of 5) - if there's 5 total pages.
All Sorts of UNIX Timestamp Goodness
I'm writing some tracking software and came upon the need to be able to get the two timestamps (UNIX timestamp: the number of seconds elapsed since midnight Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds) of a given period of time. This period of time would be represented in words via a GET parameter in my application. To you, I present my switch statement to produce those two timestamps.
The hardest of all was getting "this week last year". Please note that all weeks begin on Monday.
You can check the resulting timestamps using this cool online timestamp converter.
switch($period)
{
case "yesterday":
$timestamp_start = mktime(0, 0, 0, date("n"), date("d")-1, date("Y"));
$timestamp_stop = mktime(23, 59, 59, date("n"), date("d")-1, date("Y"));
break;
case "this_week":
$timestamp_start = mktime(0, 0, 0, date("n"), date("j"), date("Y")) - ((date("N")-1)*3600*24);
$timestamp_stop = time();
break;
case "this_month":
$timestamp_start = mktime(0,0,0, date("n"), 1, date("Y"));
$timestamp_stop = time();
break;
case "this_year":
$timestamp_start = mktime(0,0,0, 1, 1, date("Y"));
$timestamp_stop = time();
break;
case "last_week":
$timestamp_start = mktime(0, 0, 0, date("n"), date("j")-6, date("Y")) - ((date("N"))*3600*24);
$timestamp_stop = mktime(23, 59, 59, date("n"), date("j"), date("Y")) - ((date("N"))*3600*24);
break;
case "last_month":
$timestamp_start = mktime(0,0,0,date("n")-1, 1, date("Y"));
$timestamp_stop = mktime(23, 59, 59, date("n"), date("d")-date("j"), date("Y"));
break;
case "last_year":
$timestamp_start = mktime(0,0,0,1, 1, date("Y")-1);
$timestamp_stop = mktime(23,59,59,12,31, date("Y")-1);
break;
case "last_half_hour":
$timestamp_start = mktime(date("h"), date("i")-30, date("s"), date("n"), date("d"), date("Y"));
$timestamp_stop = time();
break;
case "last_hour":
$timestamp_start = mktime(date("h")-1, date("i"), date("s"), date("n"), date("d"), date("Y"));
$timestamp_stop = time();
break;
case "last_24_hours":
$timestamp_start = mktime(date("h"), date("i"), date("s"), date("n"), date("d")-1, date("Y"));
$timestamp_stop = time();
break;
case "last_seven_days":
$timestamp_start = mktime(date("h"), date("i"), date("s"), date("n"), date("d")-7, date("Y"));
$timestamp_stop = time();
break;
case "last_thirty_days":
$timestamp_start = mktime(date("h"), date("i"), date("s"), date("n"), date("d")-30, date("Y"));
$timestamp_stop = time();
break;
case "same_day_last_week":
$timestamp_start = mktime(0, 0, 0, date("n"), date("d")-7, date("Y"));
$timestamp_stop = mktime(23, 59, 59, date("n"), date("d")-7, date("Y"));
break;
case "same_week_last_year":
$timestamp_start = mktime(0, 0, 0, date("n"), date("j"), date("Y")-1)
- ( (date("N", mktime(0, 0, 0, date("n"), date("j"), date("Y") - 1 ) ) - 1 ) * 86400 );
$timestamp_stop = mktime(23, 59, 59, date("n"), date("j") + 7, date("Y")-1)
- ( (date("N", mktime(0, 0, 0, date("n"), date("j"), date("Y") - 1 ) ) - 1 ) * 86400 );
break;
case "same_month_last_year":
$timestamp_start = mktime(0,0,0, date("n"), 1, date("Y") - 1);
$timestamp_stop = mktime(23, 59, 59, date("n"), date("t"), date("Y") - 1);
break;
case "today":
default:
$timestamp_start = mktime(0,0,0, date("n"), date("d"), date("Y"));
$timestamp_stop = time();
break;
}
Aptana Studio: My New IDE
I've been looking for something to replace the "kludgyness" of Dreamweaver for a while now and I've always shied away from Java applications. However, there are not a lot of great powerful development platforms for the Mac. Sure, there's Coda, and TextMate, both of which are great applications in their own right. But I wanted something more.
Here is my list of things on my wish list for a web development IDE:
- Seamless FTP Integration
- Seamless SVN Integration
- Project and file management
- Code Assist
Lo and behold, I found Aptana Studio 1.1!
Yes, it is a java application, but it's based on the Eclipse IDE which is a very full-featured and mature open source project.

The interface can be a bit intimidating at times until you learn what things are called and how to interact with the application.
Aptana Studio does everything in my list and more. One thing I really enjoy is the real time PHP debugging. You're writing some code and in a "validation" window below the text editor will tell you immediately if you have a syntax error. Brilliant!
Another nice feature is that I can browse my SVN repositories right from the main window. Right click on a directory and check it out of SVN as a new project in Aptana Studio. Aptana keeps track of your changes and marks changed files with an * and files not in the repository with a ?. It supports synchronize, commit, update, create patch, apply patch, branch/tag, merge, show history, cleanup, and most important: diff. I think it's SVN support is the Subclipse plugin for Eclipse.
I've been using this software for about 2 weeks now and It has completely replaced Dreamweaver for me. The only time I've opened Dreamweaver was to grab some FTP settings that were stored there.
One thing I've noticed with Aptana is that is doesn't play well with the Mac OS X Dock. It happily shows up there when launched, but when you try to retain its icon in the dock after closing, the icon turns into a unix executable icon and is linked to "/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java". That is very strange behavior. There's even a bunch of open bug reports about this problem specifically.
One way around this, annoying as it may be, was to create an alias of the launching application and put the alias in the dock. Only problem with that is when Aptana Studio is launched there are two icons in the dock. Not a big deal to me till the bug gets fixed.
Overall I'm really enjoying my new development IDE. It launches fast on my Macbook Pro Core 2 Duo and has a snappy interface. I just wish there was an option to "automatically upload on save" like Dreamweaver had. I'm willing to overlook that one shortcoming and work happily in Aptana, but I have a big sign above my monitor that says,
"Upload the file! CMD+SHIFT+U"
If you're tired of Dreamweaver, give Aptana Studio a try.


