luni, 15 noiembrie 2010

Vancouver WordPress Meetup Talk: Simple Yet Powerful WordPress Hacks

Below you’ll find the code examples for my Vancouver WordPress Meetup group talk Simple Yet Powerful WordPress Hacks held on August 12, 2010. This article will be expanded after the talk but for now it consists only of the code examples themselves.


One of my top 10 pet peeves is sites where you can’t click the logo to get to the home page but have to click the “Home” button. This code block can be inserted in the header.php file and it will insert an image (logo) that links back to the home page and also has the alternate text and link title set to the name of the site.



To add WP 3.0 menus to themes that were built before the new version of WordPress or don’t have them built in you need to activate the menu function in functions.php and then add a call to the menu in your template file.


Add to functions.php:

register_nav_menus(array('menuName' =>__('Menu Name'),'2ndMenu' =>__('2nd Menu'),));

Add to template file:

'primary')); ?>

Note that the theme_location call points to the name of the menu as set in functions.php. To target the menu name set inside WordPress use this code instead:

'Menu Name')); ?>

I’ve already written an extensive article on this subject that can be found here. The core of the CSS code is this style:

.current-menu-item,.current-page-ancestor,.current-post-ancestor {... style info goes here ...}

To create a custom page template simply insert the following 5 lines of code at the top of your template file and give it a name other than “whatever”. Once saved (as something other than page.php) it will appear as one of your template options inside WordPress.


To activate the Featured Image panel in WordPress admin an enable the function you need to add a small piece of code to the functions.php file. Once this is done and Featured Images have been defined you can call them from within any template file using one of the calls below.


In functions.php:

add_theme_support( 'post-thumbnails' );

In theme file:


The above call will produce the thumbnail in the size defined inside WordPress admin under Settings -> Media. To call a different size use one of the following:

the_post_thumbnail('thumbnail');the_post_thumbnail('medium');the_post_thumbnail('large');the_post_thumbnail(array(nnn,nnn));

For the last one replace ‘nnn’ with any pixel width and height.


WordPress Training Package, A Collection of Video Tutorials and WordPress Blogging Tools, Is An Extremely Easy To Understand And Most Complete Series You Can Ever Find On The Internet That Takes You From Learning The Basics To Becoming A WordPress Experts


Check it out!

Niciun comentariu:

Trimiteți un comentariu