Template Monster giveaway: 3 WordPress themes to win!

A word about Template Monster

Template Monster is a world leader in the web template business, with over 20,000 templates available. They provide HTML templates as well as theme for CMS such as WordPress, Joomla, and others.
To learn more about Template Monster or browse available themes, just have a look to their website.

How to join the giveaway?

Joining the giveaway is free and easy. First, have a look to Template Monster themes and find the theme you’d like to win. Then, simply leave a comment below to let me know which theme you’d like to win.

In one week I’ll randomly pick 3 winners. They’ll receive the chosen theme directly from TemplateMonster.

Good luck everyone!

Log in a WordPress user programmatically

Here is the function, drop it in your functions.php file:

function auto_login( $user ) {
    $username = $user;
    if ( !is_user_logged_in() ) {
        $user = get_userdatabylogin( $username );
        $user_id = $user->ID;
        wp_set_current_user( $user_id, $user_login );
        wp_set_auth_cookie( $user_id );
        do_action( 'wp_login', $user_login );
    }     
}

Then, to log in a user, do the following:

auto_login( 'admin' )

Thanks evilsocket for the code!

Speeding up your WordPress blog: 7 effective solutions

“Smush” your images


If you’re using Adobe Photoshop, you can use the “Save for web” option that allow you to easily find the best compromise between quality and image size. Another option is to use a free online service to reduce image size while keeping its quality high. This service is called Smush It and I can’t stop using it to optimize my images.

There’s also a free WordPress plugin available. Install it, and it will automatically optimize any image you’ll upload to your WordPress site using the uploader. Cool, isn’t it?

Use a caching plugin

If your WordPress site is slow, make sure you’re using a caching plugin. There’s lot of options available, however I recommend W3 Total Cache which is free and really efficient.

W3 Total Cache minify static files (CSS, JavaScript), cache .php files, and add easy CDN support.

Reduce database queries

It is important to reduce unecessary queries to your database as each query take a few milliseconds to execute. First, you might want to know how many queries your blog execute in order to display a page. To do so, paste the code below in your functions.php file. Once done, just have a look to your site footer to know how many queries has been executed and how many time it took to completely load the page.

add_action( 'wp_footer', 'tcb_note_server_side_page_speed' );
function tcb_note_server_side_page_speed() {
  date_default_timezone_set( get_option( 'timezone_string' ) );
  $content  = '[ ' . date( 'Y-m-d H:i:s T' ) . ' ] ';
  $content .= 'Page created in ';
  $content .= timer_stop( $display = 0, $precision = 2 );
  $content .= ' seconds from ';
  $content .= get_num_queries();
  $content .= ' queries';
  if( ! current_user_can( 'administrator' ) ) $content = "<!-- $content -->";
  echo $content;
}

Then, you have to remove useless queries from your blog. Start by making sure that you are not using too many plugins, as most plugins are making database queries. Then you can remove theme-related queries that are not useful to your blog.

Speed up your site with .htaccess caching

If you can’t or don’t want to use a caching plugin on your WordPress site, this code snippet might be very helpful for you.

By using some simple .htaccess file caching, you can dramatically increase your website speed. This snippet must be pasted in your .htaccess file, located at the root of your WordPress install.

# 1 YEAR
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 2 DAYS
<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=172800, proxy-revalidate"
</FilesMatch>
# 1 MIN
<FilesMatch "\.(html|htm|php)$">
Header set Cache-Control "max-age=60, private, proxy-revalidate"
</FilesMatch>

Source: http://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching.html

Use a Content Delivery Network

Do you know that 80 to 90% of the end-user response time is spent downloading all the components in the page? Images, scripts or stylesheets can take a while to be downloaded on the client machine.

A content delivery network (CDN) is a collection of web servers distributed across multiple locations to deliver content more efficiently to users. Although CDNs are pricey for small or non-profit websites, using this solution can really make your site 20% faster. Most well known CDNs are MaxCDN, Amazon CloudFront, CloudFlare and NetDNA.

Minimize HTTP requests

In order to reduce page loading time, you have to reduce the number of HTTP requests. To do so, you have to:

  • Reduce the number of JavaScript files
  • Reduce the number of CSS files
  • Reduce the number of images

If you’re using W3 Total Cache as I recommended, you don’t have to worry much about JavaScript and CSS files, as the plugin minify those files in order to reduce the number of HTTP requests.

Regarding images, one of the best thing to do is to using the “CSS sprites” technique. This technique basically consists of grouping many small images on one big image in order to do a single HTTP request all for images, instead of one request per image. The easiest way to combine your images on a single image file and automatically generate the corresponding .css code is to use a service named Sprite Me.

Use a reliable web hosting

At last but not least, it is obvious that you should use a reliable web host if you want your website to be fast. I’ve used lots of web hosts and some are really good and some other sucks. For example, you should definitely avoid Phpnet.org and Maven Hosting, both of them shut my websites down just because they were receiving too many visits.

On the other hand, I was pleased with WP Web Host, which is really good if you’re hosting a small or medium WordPress site or blog. If you have a popular and/or large website, I definitely recommend Vidahost, which is CatsWhoCode webhost. My site is still fast although I receive lots of traffic. If you want to get some hosting from Vidahost, don’t forget to use my custom coupon CATSWHOCODE to get 10% off anything.

Btw, if you need any help with your website, I can help you at avery reasonable rate. Have a look at my site WPCAT to get in touch!

Template Monster giveaway: 3 WordPress themes to win!

A word about Template Monster

Template Monster is a world leader in the web template business, with over 20,000 templates available. They provide HTML templates as well as theme for CMS such as WordPress, Joomla, and others.
To learn more about Template Monster or browse available themes, just have a look to their website.

How to join the giveaway?

Joining the giveaway is free and easy. First, have a look to Template Monster themes and find the theme you’d like to win. Then, simply leave a comment below to let me know which theme you’d like to win.

In one week I’ll randomly pick 3 winners. They’ll receive the chosen theme directly from TemplateMonster.

Good luck everyone!

WordPress tip: Add a custom message to the editing pane

Copy the following snippet and edit the message on line 5. Once done, paste it on your functions.php file and save.

function wptutsplus_text_after_title( $post_type ) { ?>
    <div class="after-title-help postbox">
        <h3>Using this screen</h3>
        <div class="inside">
            <p>Use this screen to add new articles or edit existing ones. Make sure you click 'Publish' to publish a new article once you've added it, or 'Update' to save any changes.</p>
        </div><!-- .inside -->
    </div><!-- .postbox -->
<?php }
add_action( 'edit_form_after_title', 'wptutsplus_text_after_title' );

Thanks to WP Tuts for this great tip!

How to order posts by two meta values

Paste the code below in your template file where you need to sort the results of the query.

<?php 

$query = "SELECT wposts.*, wpostmeta1.*, wpostmeta2.* 
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta1, $wpdb->postmeta wpostmeta2
WHERE wposts.ID = wpostmeta1.post_id
AND wposts.ID = wpostmeta2.post_id
AND wpostmeta1.meta_key = 'date'
AND wpostmeta2.meta_key = 'time'
ORDER BY wpostmeta1.meta_value ASC,
         wpostmeta2.meta_value ASC";

$results = $wpdb->get_results($query);

foreach ( $results as $result ) {
         //output results as desired
} ?>

Please note that this query is given as an example and might need to be adapted to fit your specific needs. If you need help at a cheap rate, contact WPCAT.

Zero Bundle: Free resources for designers and front-end coders

Zero Bundle is a big bundle for web designers and front-end web developers. It contains Photoshop actions, fonts, icons, .psd templates and .html templates.

The bundle is 100% free. In order to download it, you only need to enter your email address. Please keep in mind that the bundle is available only for 30 days, so don’t wait to much before grabbing yours.
Let’s have a closer look at what you’ll find in Zero Bundle :

198 Vector Icons

A great mix of icons that includes everything from trophies, to keys to anchors. Forget your same-old boring smiley face and thumbs-up icons; you’ve got 198 scalable icons to play with here. Keep the quality intact while changing the color, shape or orientation. All icons include PSD, AI, PNG and CSH formats. Also included are 9 Killer Photoshop Actions that can easily be applied with just one simple click.

Metrize Icons

collection of 300 Metro-style icons for designers and developers. Available in PSD (single shape layer), SVG (single icon 512 x 512), EPS, PDF and AI formats. The set also includes Metrize Fonts Icons so you can utilize the icons in your web projects using @font-face, freeing you up to scale and color them on the fly. A simple how-to guide is included as is the necessary scripts for IE7 compatibility.

20 Photoshop Actions

The Clean & Crisp Action bundle was devised a to help you keep your shots professional, clean, and crisp. They instantly enhance your photography in a click, so you don’t have to waste time fussing with layers and exposures. Created specifically to be combined to enable your own unique creative approach. 20 professional actions included in the set, free for personal and commercial use.

Long Shadow Icons

Make sure your icons are right on trend with this sensational set of long-shadow icons. Delivered as 10 PSDs containing vector artwork, the set can be rescaled and recolored to suit your branding scheme. Highlights include the paper airplane, the chunky padlock, the energetic lighting bolt and the bulging battery, but really they’re all winners. Hook them up to your project and see how they update your look.

Enjoy those freebies? Click here to go to Zero Bundle site and download! Don’t wait to much because the bundle is only available for free for the 30 next days.

Amazing free and premium “flat” WordPress Themes

Kite


Link: Kite

Photo


Link: Photo

Cat Planet


Link: Cat Planet

Gridster


Link: Gridster

Hayden


Link: Hayden

Showy


Link: Showy

Forest


Link: Forest

Head


Link: Head

Nordic


Link: Nordic

Mastery


Link: Mastery

Acute


Link: Acute

By the way, I just created a new service called WPCAT, where I offer my help to fix or enhance your WordPress site for a cheap rate. Don’t wait and contact me right now if you need any help with WordPress!

WordPress tip: How to get the first link in post

Put the function below in your functions.php file, then use it inside the loop in your template files.

function get_link_url() {
    $content = get_the_content();
    $has_url = get_url_in_content( $content );

    return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
}

Thanks to Filip Stefansson for the tip!

By the way, I just created a new service called WPCAT, where I offer my help to fix or enhance your WordPress site for a cheap rate. Don’t wait and contact me right now if you need any help with WordPress!

How to change author url base on your WordPress site

Pasting the following code on your functions.php file will change the default yoursite.com/author/name to yoursite.com/profile/name.
Replace profile on line 4 by any slug you want.

add_action('init', 'cng_author_base');
function cng_author_base() {
    global $wp_rewrite;
    $author_slug = 'profile'; // change slug name
    $wp_rewrite->author_base = $author_slug;
}

Thanks to Kevin Chard for the cool tip!

Awesome tutorials to master CodeIgniter

CodeIgniter for the absolute beginner


New to CodeIgniter? Here is an awesome place to start and get the most out of this powerful framework.
» Read tutorial

CodeIgniter basic tutorial


A basic tutorial to start or consolidate your skills. Recommended for beginners!
» Read tutorial

Getting started with CodeIgniter


Another very good tutorial for CI newcomers. Learn to install, configure the framework, prepare databases, work with POST and GET data…
» Read tutorial

Fetch data from database with CodeIgniter


In order to use CodeIgniter in a production environment, knowing how to work with database data is a must. This handy tutorial is here to help.
» Read tutorial

Build a RSS 2.0 feed with CodeIgniter


In this tutorial, we will build a RSS 2.0 Feed with the PHP framework CodeIgniter. After this tutorial, you will be able to build a feed for any custom website in no time at all.
» Read tutorial

Validating web forms with CodeIgniter


If you’re a web developer, you’ve probably written any number of scripts designed to validate the input entered into a web form. In this tutorial, you’ll learn how to validate web forms quickly and easily using CodeIgniter.
» Read tutorial

Generating PDF files using CodeIgniter


In many situations, it is very useful to be able to generate .pdf files. Of course you can do so with CodeIgniter, and it’s pretty easy with this helpful article.
» Read tutorial

Build a cache with CodeIgniter


For websites/web applications, caching plays a very important role. This tutorial explains how you can start using CodeIgniter caching techniques for improving your web application to a new level.
» Read tutorial

Build a pagination with CodeIgniter


Pagination is a very common feature of blogs, news websites, and internal search engines. Here’s an useful tutorial to learn how to paginate items with CI.
» Read tutorial

Reading CSV files in CodeIgniter


Here is an interesting article to learn how you can easily read .csv files using CodeIgniter.
» Read tutorial

Setting up multiple sites on one install


Let’s finish this post with a very handy tutorial, which will show you how to set up multiple sites using a single CI install. A must read!
» Read tutorial

WordPress tip: author bio excerpt

Let’s start by creating the function. The code below have to be pasted into your functions.php file.

<?php
	function author_excerpt (){	                     					
		$word_limit = 20; // Limit the number of words
		$more_txt = 'read more about:'; // The read more text
		$txt_end = '...'; // Display text end 
		$authorName = get_the_author();
		$authorUrl = get_author_posts_url( get_the_author_meta('ID'));
		$authorDescriptionShort = wp_trim_words(strip_tags(get_the_author_meta('description')), $word_limit, $txt_end.'<br /> '.$more_txt.' <a href="'.$authorUrl.'">'.$authorName.'</a>');
		return $authorDescriptionShort; 		
	}
?>

Once done, you can use the function. To do so, use the code below where you’d like to display an author bio excerpt:

<?php  if (function_exists('author_excerpt')){echo author_excerpt();} ?>

Thanks to Tim Marcher for submitting this recipe!

How to paginate WordPress like Dribbble

Just paste the code below on your single.php file, where you want to display the dribbble-like pagination:

<?php $prev = get_previous_post(); $next = get_next_post();
						
	<div class="float--left folio">
		<a href="<?php echo get_permalink($prev->ID); ?>" title="<?php echo esc_attr($prev->post_title); ?>">
			<?php echo get_the_post_thumbnail($prev->ID, 'thumbnail'); ?>
		</a>
	</div>
						
	<div class="float--right folio">
		<a href="<?php echo get_permalink($next->ID); ?>" title="<?php echo esc_attr($next->post_title); ?>">
			<?php echo get_the_post_thumbnail($next->ID, 'thumbnail'); ?>
		</a>
	</div>

This recipe has been submitted by Elliott Richmond. Thanks!