AJAXify your Wordpress

Learn how I ajaxified my wordpress blog with these few steps...

SBS Show!

Listen to the latest episode of the SBS Show, Dave Sobel talks about process management...

Vladville Newsletter!

Looking for a more focused, exclusive insight into the world of SMB tech & business? Sign up for my newsletter!

Archive for the 'WordPress' Category

|

WordPress 2.3.2 patches a security issue
Posted: 1:48 am
December 30th, 2007
WordPress

Of note for us WordPress fans is the release of WordPress 2.3.2, urgent release fixing a bug that can reveal the contents of your draft posts and database table structure.

Upgrading WordPress tends to be very simple – just grab the .zip file and uncompress it – upload everything except wp-content directory and wp-config.php file and hit /wp-admin to update the database. Thats all there is to it.

Read the whole post...

Making blogs look better on Windows Mobile
Posted: 5:12 pm
December 17th, 2007
WordPress

As I continue to tweak Vladville to fit in better with the upcoming Thieving Weasel framework, I decided to put in a little bit of work to make Vladville easier to navigate on Windows Mobile devices. Pulling up Vladville on a Windows Mobile (PocketPC or Smartphone) will now only display the content, sans the Javascript, AJAX, sidebar, slidey stuff or other blog gunk that you see in the full featured web page because.. well.. it’s what I do. Pull it up and see, hopefully this makes Vladville a little more pleasant in the pocket. It took all my might not to call it PocketVlad, for what its worth.

It’s a very quick WordPress loop hack that excludes certain form elements from the display when the browser is Windows CE based:

if(!strpos(“$_SERVER[HTTP_USER_AGENT]“,”Windows CE”))

{ display regular content to IE, FF, Opera.. }

WordPress checks the UserAgent sever variable for presence of Windows CE and if it doesn’t find it, it prints the regular blog content. However, if it finds out that you are on Windows CE it does not send the particular content to it.

So for example, let’s say your template code includes a like like <?php get_sidebar(); ?> and your sidebar has all that gunk useless to a mobile viewer? Just wrap it and it will not be displayed to the Windows Mobile browser:

if(!strpos(“$_SERVER[HTTP_USER_AGENT]“,”Windows CE”)) { get_sidebar(); }

What if you had some HTML markup like things you copied and pasted from the web site to include a comic, calendar or 8,285 buttons and ways to subscribe or share your posts?

<div id=’blah’>Blah blah blah</div>

Same thing, but a little different:

<? if(!strpos(“$_SERVER[HTTP_USER_AGENT]“,”Windows CE”)) { ?>
   <div id=’blah’>Blah blah blah</div>
<? } ?>

Gotta love the simplicity of PHP. Just put line #1 above the content you want to block from Windows Mobile and below. Now, naturally, you have to have the markup elements match up because if you cut your table or div elements in half your layout will fall apart.

Still, pretty easy to make WordPress friendly with Windows Mobile…

Read the whole post...

How do I come up with blog post topics?
Posted: 10:16 pm
December 8th, 2007
WordPress

One of the most frequent questions I get from new bloggers has to do with the concept of developing topics and stories. How do I come up with blog topics? What should I blog about? What makes a good post?

I come up with blog topics by reflecting on what I’m doing that day or thinking that week. The longer posts are the ones that have been on my mind for a few days and I just haven’t quite figured it out yet. The shorter posts are spur of the moment posts, just something that I’ve been discussing with folks that day and figured I’d offer it up.

It is not labor or intensive creative work that goes into writing articles and producing media (audio, video, documentation), it is actually more of a process of organizing thoughts, validating decisions and having some peace with what I’m doing. Truth is, if you’re an entrepreneur you already have enough pressure and your every waking moment is taken up with work and thinking of work. And if you let it bottle up and completely consume you, it will either kill you or completely exhaust you. So blogging is a great outlet as well.

Robbie Upcroft once asked me if I had an opinion on everything. Then he picked up a fork and asked “What do you think of this fork?” as I’m sure he expected me to break out into some sort of utencil analysis. I really am not that full of it! But when it rains it pours: I keep a flat text file on my desktop with blogging ideas. They are really just random thoughts that come to mind at odd moments and it’s more of a “Oh yeah, I’ve been meaning to mention that” kind of a thing.

Here, I’ll share with you my “Bloggable Crap” list:

How to create compelling video product walkthroughs
Got a PocketPC blog writer software to recommend?
Scott Adams Book: Stick to drawing comics, monkey brain!
Worst Book Ever Excreted: The 4 Hour Work Week
Arguments for or against web advertising schemes for content creators
 - ads, block digg/netscape, if you don’t click on my adwords you are a thief
 - but, remember if there is no commercial stuff, the projects die
Time to upgrade Web 2.0 – financing of the entire genre is dependant on infinite FAD and consumerism
How to staff a tech company in the down economy
 - Overpriced housing, no industry / unpopular
- Is Florida over?
- Where do you find the time to ___?
- How can you get a link on Vladville? – Simple domain, one dot.
- What makes those worn out silver marks on Dell Laptops?
- for entrepreneurs, Conservatism leads to failure. “contradiction, don’t decisions to pursue uncertain future nearly guarantee failure? Let me ask you this – how did you decide to become an entrepreneur, what exactly warranted that move. Do you not regret it? If not, you need to feed it, not starve it.
- Dont let emotion throw your focus on customer service.
- Why do techies collect computer trash? 4eee PC
- Why Vista is failing? Because it’s change, and people hate change… to web site layouts, to web browsers, to… well, anything. It should always come in just as the current one is, with the ability to turn on the insanity on demand. People consider things to suck when they cannot cope with the change – what sucks about Outlook? The fact that it doesn’t do what I expect it to do. When I find out the right way, if it ain’t my way, I get angry.
- Affordable SMS/Paging Solutions In The 21st Century


Notice that not everything is a headline, it’s not like I sit there and brainstorm blog posts. I just jot down ideas as I come up with them and I eventually put them together to answer a question that someone asked (or at someone ought to be asking).


This works for me because I don’t care about your critical literary taste – I don’t even bother spell checking the post. I just type as I go along and wish you the best of luck with understanding where I am heading. Truth is, it takes longer to proof and organize a body of text than to create a rough draft / stream of consciousness or lack thereof (the porn posts). Sometimes this is brilliant, sometimes it backfires terribly and leads to misunderstandings and hurt feelings.


The idea behind blogging is that you offer your view as you would face to face with someone you knew. This isn’t the state of the union or a testimony to the grand jury, it’s just me reacting to something. It will never end up in the newspaper, it will not become a fatwa or a book but it helps stay in touch with people and it starts conversations.


At the end of the day, thats what this stuff is all about – continuing the relationships you established or meeting new friends and coleagues online. Kind of how you know me.


(Pardon the post quality, typed in the back of a rental car as I tried to get an extra hour of sleep due to my phone being stuck in the wrong time zone.. when that failed to materialize, I typed this up)

Read the whole post...

WordPress without WordPress
Posted: 1:47 am
December 4th, 2007
WordPress

WordPress is one monster of a platform, and hacking it is probably as much fun as you can have with a web page without writing actual code. Unfortunately, that little convenience tends to bring out a lot of “Bubba the Web Alchemist” people out the woodworks that go buck wild with plugins and extensions to do some very, very simple things.

One of the biggest Bubba tasks is to use WordPress as a content management system but providing static pages for some parts of the content for one reason or another. While there is a plugin in WordPress 2.1+ to set a page as a homepage, there are also legitimate reasons to have pages in the WordPress powered page that are not part of the WordPress content database. That reason generally involves a third party web designer that doesn’t know how to code WordPress themes, inept content manager and more. Some people design an entire site from scratch then try to muscle WordPress into it. Some people go the opposite way, they start with WordPress but then have content sections they want to manage outside of WordPress content database.

But what if your template elements relied on WordPress functions?

Big gotcha. Suppose you had a flat web page that you wanted to use as a part of your online content but all your headers and footers had WordPress functions in them – to generate category printouts, archives or comments. You couldn’t just use a bare php include because PHP would crash when it couldn’t interpret the function you are trying to call. So, for all of you struggling Bubba alchemists out there, here is the simplest WordPress-aware page using content outside of the WordPress content database:

<?
define(‘WP_USE_THEMES’, false);
require(‘./wp-blog-header.php’);
get_header();
?>

Bubba the Web Alchemist
<br/>
Global HQ

<?
get_sidebar();
get_footer();
?>

The top section sets up the theme and includes the WordPress functions. get_header() gets the overall site header, and the other functions at the bottom (get_sidebar and get_footer) include the sidebar and footer. This can vary based on your template design but it gets the point across.

The part in the middle is the flat HTML you want displayed in the context of your WordPress theme without giving your webmaster a heart attack. They can go about designing the special pages (forms, surveys, internal/external content and more without bothering you or potentially destroying the WordPress deployment in the process.

See, how easy was that?

Read the whole post...

Howto: WordPress AJAX Newsletter Subscription with jQuery
Posted: 11:02 pm
November 25th, 2007
Vladville, Web 2.0, WordPress

Today I took the first steps towards publishing my newsletter and that of course means putting up a signup form. This is a dreadful, backwards process of creating a new template page, building a form, a processing script and then sending the user where they started out from. It involves unnecessary clicks, diminishes from design and flow of the site. But it doesn’t have to – enter jQuery and WordPress.

Using jQuery framework and a simple backend server script you can collect data from the user and post the response inline on the same page with the minimal interruption to the browsing process and minimal changes to the layout. For example, my form prompts users for their email address in the sidebar to the right. It communicates errors or success by fading in a container with the error or congratulations text. No page reloads, no dedicated pages to design or maintain – just embed another widget in the sidebar and enable the site to be more functional. Gotta love AJAX.

I wrote a quick and simple HowTo article on creating AJAX driven forms in WordPress: Check it out.

Enjoy!

Read the whole post...

WordPress Trackback SPAM Annoyances
Posted: 12:48 pm
November 15th, 2007
WordPress

One of the worst things in blogging (aside from the constant, unrelenting abuse and hate mail you subject yourself to) is dealing with SPAM. Here you are just talking openly about whatever and someone tries to make money off of it. Low…

I’ve gone out of my way to kill the spammers. First, I only allow comments by registered users and registered users only receive a password to the email address they provide at registration. This nearly eliminates comment spam, I may have had one junk message in the past year.

Second, I absolutely neutered the trackback SPAM. These are the fake comments you see on Vladville that say “Mike said this: ” followed by my post contents. What I have essentially done to neutralize these monkeys is removing the hyperlink to their URLs, so even though they SPAM me, it gets them nowhere and just sends more links to my blog.

I kind of make a living killing spammers so this goes a little beyond the lone annoyance, its outright emasculating. So I’m sitting here in the atomic tangerine lab trying to come up with some replicable pattern that I can use. Most trackback SPAM plugins rely on curl to check if the offending web page has the direct link to my blog post. For pretty much everyone, that seems to be the case. So here is about the only thing I have come up with so far:

All trackback SPAM has the full post URL in it. The page also quotes, partially, my blog post and attributes it to someone else. I am intercepting the URL, downloading it with curl, stripping out all the HTML and running preg_match between the two posts.

Because all HTML and punctuation is ignored, it should be pretty easy to find a pattern match over at least 100 characters.

For the most part, nobody quotes paragraphs and paragraphs of text in a blog post, they merely link to the article and offer their point of view on it. Let’s see how it goes, right now I am just logging the matches and not discarding them automatically.

Off topic… I tried this too:

Most trackback spam happens within minutes of the post going live. It is almost safe to say that nobody would have read, thought about and produced a post referencing me within let’s say 30 minutes of my blog post. Something that automated either has no life at all or is a spambot.

If you have a better idea, I’m all ears…

P.S. I killed the monkey-glide as a courtesy to Katie. As you may have noticed, there is some more AJAX happening on Vladville, this time just a stupid CSS trick that brings in additional navigation without cluttering the page — just click on the monkey tale thats right above my head on the top right corner of my page where it says “Whats on Vlad’s Mind?” – (In my best Stewie voice) Maybe I’m thinking maybe the wife needs to take up more blogging and less bitching about how inconvenient her husbands blog is? Write a compelling narrative about the javascript timeouts and smooth scrolling with jquery? Something that will make us all root for the protagonist? Maybe put in some life experiences in the plot? Nah, nah.

Read the whole post...

Dear Vladville Spammers: Suck it
Posted: 9:45 am
October 4th, 2007
WordPress

After deleting the billionth trackback spam from Vladville I figured it was time to do what I do best, wack lines of code until something happens. Thanks to Aksimet and Spam Karma 2 I don’t have a lot of comment SPAM. Yes, every now and then I get to delete one or two but I am at the point where I’m deleting dozens of trackback spams each day.

Trackback SPAM is just spammers way of getting more traffic to their site. They ping the popular blog in hopes that people will accidentally hit the link and end up on their site. Doing a trackback is also very convenient, spamwise, because it does not require them to have an account here, confirm anything or even exist – just put up a blog post and hit pingomatic. Life is good.

Two can play at that game. Here is how you disable trackback linking using WordPress:

/wp-content/comment-template.php

Edit the get_comment_author_link() function and replace it with what I had below.

function get_comment_author_link() {
        global $comment;
        $url    = get_comment_author_url();
        $author = get_comment_author();

        if ( empty( $url ) || ‘http://’ == $url )
                $return = $author;
        else
        {
                if(get_comment_type() == ‘comment’)
                {
                        $return = “<a href=’$url’ rel=’external nofollow’>$author</a>”;    
                }
                else
                {
                        $return = “$author”;
                }
        }

        return apply_filters(‘get_comment_author_link’, $return);
}

Pretty simple. Here is what it looked like before:

        if ( empty( $url ) || ‘http://’ == $url )
                $return = $author;
        else
                       $return = “<a href=’$url’ rel=’external nofollow’>$author</a>”;   

What I have basically done is to add another wrapper around the line of code that returned the author along with a link to their blog. My wrapper checks for the comment type and unless the comment type is a comment (which implies they have a registered account here, that I can nuke easilly if they start to SPAM) I don’t print their URL.

So SPAM away boys, nobody is going to click on your junk from this blog anymore.

Read the whole post...

Stopping WordPress Trackback SPAM
Posted: 11:28 pm
July 3rd, 2007
WordPress

Spamming is a hard job. Spamming blogs is even harder. I’ll save you the colorful description of what I think of the people that do this, and as of late a particular site (universityupdate.com) has been a big thorn in my side. It’s your typical Adwords scumbag, trying to get links any way possible so someone would accidentally click on some of the ads and bring them a quarter.

So how does one get rid of this site, or perhaps any site, you don’t want trackbacks from via WordPress? Simple, just edit your wp-trackback.php and add this somewhere towards the bottom of the script (make sure you’re not putting it inside any other if { } statements:

if (preg_match(“/\buniversityupdate.com\b/i”, $tb_url))
{
        wp_redirect(get_permalink($tb_id));
        exit;
}

Pretty simple. Save the file and you’re done. This can work in a number of ways, all that regexp looks for is presence of “universityupdate.com” string in the URL that the splogger is using. I don’t know why I didn’t do this sooner, its certainly faster than nuking a blog comment.

Read the whole post...

Hacking WordPress: Comma Delimited Categories & Other Space Wasters
Posted: 8:09 am
August 27th, 2006
WordPress

The biggest problem not just with WordPress but any blog is the eternal vertical list. Bloggers use lists of all kinds to fill up their blog and often abuse lists to show connections, interests and affiliations their posts do not. This post is all about taming those vertical lists and making WordPress categories comma delimited (means separated by commas).

Great Ways To Fill Your Blog

First of all, the problem: endless vertical lists. Nothing says “mine is bigger” like a huge vertical list. Here is what these unordered lists actually represent:

Blog Rolls – The list of people I met once that haven’t updated their site in 6 months

Categories - Watch me pretend my rants are actually organized and coherent thoughts

Links – Show people you’re a true intellectual by linking to Club Jenna, The Collected Works of Shakespeare, Vivid Entertainment and Michio Kaku’s String Theory
 
Comment Rolls – Nothing says “I am thought provoking!” like showing recent comments as a list with the top one being “PrinterCartriges4Less on Contemporary Evangelical Literature

Vertical AdWords – All the cash I’d make if people actually found me interesting.

Flare – Nothing screams Blogosphere like a collection of Web 2.0 crap found all over the net. First you link every which way someone can subscribe to you. Start by listing every feed format known to man. Then you help idiots that can’t cut and paste add you to MSN, My Yahoo, Bloglines, Google, Live Links, Kinja. After you have collected every icon on the web put that “Bloging Loser” crown on your head by putting in a ClusterMap. Nothing shows people your irrelevance more than a dead map of hits, most from random search engine spiders. Congratulations, you’re a blogger!

And the best for last Post Calendar – Show people just how dead your blog really is.

So now that we’ve identified all the flaws with standard blogging templates let’s look at the positive side. Let’s assume you actually had something interesting to say but still wanted to put up some flare. The problem you run into with even minimal use of side items is that your main content gets squished down to the point that your main thoughts look more like haiku than an article. Your options are to either stick these items in the header or the footer but if you had a lot of relevant stuff to put in, such as categories, your lists would take up more than half the page. The answer to taming lists is through hacking and css. I’ll let you pick which one is better.

 

Hacking Lists with CSS

The simplest way to comma delimit the category list in WordPress is to simply style the list accordingly. Mark Newhouse has a great article on taming lists in general but here is all you need to know about managing your categories in WordPress.

First, stick the following in your css stylesheet:

#inline-list {
 }

#inline-list p {
 display: inline;
 }

#inline-list ul, #inline-list li {
 display: inline;
 }

#inline-list-gen ul li:after {
 content: “, “;
 }
  
#inline-list-gen ul li.last:after {
 content: “. “;
 }

Now you just have to enclose your category list and apply the above style to it:

<div id=”inline-list”>
<ul>
<?php wp_list_cats(); ?>
</ul>
</div>

By default wp_list_cats generates <li> items (list items) which can be ordered, unordered or sorted any way you wish. The simplest way to consolidate these lists is by coma separating them so they take up as little room as possible.

Hacking WordPress code to Comma-delimit

Unless you’re a web monkey hacking the code directly is a lot more fun. Not only is it dirty but it also brings you closer to the code by making you maintain a list of changes every time WordPress is upgraded.

First, disable <li> formatting by passing ‘list=0′ parameter to wp_list_cats:

<?php wp_list_cats(‘list=0′); ?>

Second, hack the code. When you pass list=0 parameter WordPress appends <br /> after each category. Sticking a comma instead of a line break can save a ton of space. Using other separators (% | o x) can be even more stylish. So how do you make WordPress do this? Edit wp-includes/template-functions-category.php and replace <br /> with , on line 375 (in WordPress 2.0.4)

if ( $list ) {
 $thelist .= “\t<li”;
 if (($category->cat_ID == $wp_query->get_queried_object_id()) && is_category()) {
 $thelist .=  ‘ class=”current-cat”‘;
  }     
  $thelist .= “>$link\n”;
} else {
 $thelist .= “\t$link <br />\n”;
}

BEFORE:
$thelist .= “\t$link <br />\n”;
AFTER:
$thelist .= “\t$link, \n”;

Simple as that. In the PHP code sample above an IF construct is used to evaluate the $list parameter you passed through wp_list_cats(‘list=0′); It’s a simple boolean (0,1 – false, true) comparison. Top part of the code is executed if the $list value is true (‘list=1’) and else is executed if it’s.. well, guess :)

So there you go, from a 6 foot vertical list to a pretty block like this one:

Categories

How tall IS this ladder?

Some template functions implement before and after arguments to allow you to pass values before and after inputs and outputs. Unfortunately, wp_list_cats() does not support that so your only option is to write a filter. That however is a discussion to have much later.

Please keep in mind that I’m just showing you how to get your feet wet and how to edit and tweak the simplest of things in WordPress code. Hopefully this gets rid of your fears of things exploding and buildings coming down if you make slight changes. Hopefully it also makes you think about code, the simplicity and ease of transforming it to do what you want. You’ve got to start somewhere and this is just the least painful way.

Read the whole post...

WordPress Hack: Rotating Banners
Posted: 1:29 pm
August 26th, 2006
WordPress

As you know I use WordPress as my blogging platform simply because I love PHP and the simplicity that comes with a beautiful syntax. This post shows you how to create a rotating banner for your WordPress blog.

Getting Your Banners Together

First of all this is just a dirty template hack that will not go away as you upgrade your WordPress distribution. The first step is to create a set of banners you want to rotate and name them sequentially. For example, mine are named vladville-bar1.jpg, vladville-bar2.jpg, vladville-bar3.jpg and so on. Here they are:

Vladville-bar1

Vladville-bar2

Vladville-bar3

Vladville-bar4

Look familiar? Great. Notice how only one number in the filename changes? Now upload all of these banners to the same directory, mine are in /images.

Hack The Template

The second step is to actually hack the template file. Because WordPress is PHP based you can embed PHP code anywhere in your template. Mine is in the header.php but you can use this trick anywhere you want to.

Remember how only the number was different? The only thing I did was instruct PHP to select a random number from a range and insert that number in HTML code. So here is the entire mastery:

<table background=”/images/vladville-bar<?php echo rand(1,23); ?>.jpg” width=”800″ height=”155″ border=”0″>

Thats the entire mastery right there. When the template is parsed by WordPress and PHP it will call a rand function which returns a random integer in the range between 1 and 23. I happen to have 23 images on the server so returning a random number between 1–23 will return a number of one of the images in that range. The <?php part tells the server to start interpreting the next block of text as code instead of just plain filler. The ?> stops it. The echo sends stuff back to be printed and 1,23 are parameters sent to the rand function. Every time the page is reloaded the rand() function should return a different random number between 1–23 giving my visitors a different random banner from my pool of 23. For example:

First time rand(1,23) executes it returns 5. As a result, you will see vladville-bar5.jpg

<table background=”/images/vladville-bar5.jpg” width=”800″ height=”155″ border=”0″>

Second time rand(1,23) executes it returns 17. As a result, you will see vladville-bar17.jpg

<table background=”/images/vladville-bar17.jpg” width=”800″ height=”155″ border=”0″>

Thats all there is to it but I figured I’d start slow and build up. Imagine the possibilities here, you can insert greetings based on the time of day, display random quotes, insult visitors by guessing their IQ with rand(5,30) and so on.

So get creative. Your blog does not have to be borg it should reflect your individuality. After all, its all yours.

Read the whole post...
|





 

Categories

 

Archives

 

About

Divider Divider