php tips

featured article How to SEO Optimize Your WordPress Site
Published on October 18th, 2012

When creating a new website, you should always have Search Engine Optimization in art. Literally, SEO is the art of optimizing your website’s pages and post content for the search engines. SEO is effectively telling the search engines what your content is about, and who should be reading your content. For example, if you write a post on “How to fix a car”, then you will need to be specific and optimize your page for more specific keywords, such as “How to fix your car’s engine socket”. While this is a brief example, SEO also applies to the way that you link between your website’s content, and how often you link. If you don’t consider yourself knowledgeable in the area of SEO, then don’t worry – because a WordPress plugin exists that will help you out big time.  

How to import and display your latest tweets
Published on July 29th, 2011

If you are an active Twitter user, chances are that you want to share your latest tweets on your website or blog. To do that it’s quite easy, just use the following PHP snippet. <?php // import & display latest tweet $username = “perishable”; $feed = “http://search.twitter.com/search.atom?q=from:”.$username.”&rpp=2″; // $prefix = ‘<h3>Perishable Press</h3>’; // $suffix = ‘<p><a href=”http://twitter.com/’.$username.’”>Follow me on Twitter</a>’; function parse_feed( $feed ) { $stepOne = explode( ‘<content type=”html”>’, $feed ); $stepTwo = explode( ‘</content>’, $stepOne[1] ); $tweet = $stepTwo[0]; $tweet = str_replace( “&lt;”, “<”, $tweet ); $tweet = str_replace( “&gt;”, “>”, $tweet ); return $tweet; } $latest_tweet = file_get_contents( $feed ); // echo stripslashes( $prefix ) . parse_feed( $latest_tweet ) . stripslashes( $suffix ); echo parse_feed( $latest_tweet ); ?>

Display ads to Internet Explorer users only
Published on May 22nd, 2011

Internet Explorer users are often the ones that care the less about using a good browser or about the web designer’s development time. If you want to give them extra ads to punish them for using that browser, here is how to do it, insert the following code in your web page:

Use page templates for custom page layout in WordPress
Published on March 21st, 2010

Getting custom page layout in WordPress is not so hard, to do so proceed the following way: Check if your template includes a page-custom.php file, if it doesn’t you should create it by duplicating the page.php file. Copy the page-custom.php file, rename it to something relevant (for example: page-contact.php for a contact page with a custom layout). In the very beginning of the template file, add the following code: <?php /* Template Name: Contact */ ?> Customize your template. In your WordPress admin, under page editing, you should now have a drop-down listing all your pages in the “Template” box.