How to add a Pretty Pagination to your WordPress posts

Here’s a little bite that will add a nice looking numbered pagination to your blog feed. You can navigate by clicking, “Next” or the numerical page numbers. First you need to decide how many posts to show on your blog page, category page or archive page. You can adjust the number through the backend under, “settings > reading” then input the number of post you want to show. The pagination will only show if you have more posts to show than you just specified. So how do we do this?
Continue reading

How to add jQuery to your WordPress Theme. The right way???

No, below is wrong. See my new post on precisely the correct way of using jQuery on your WordPress site.

I’m not going to get into whether or not you should use the jQuery that comes with WordPress or the one that Google offers cause I don’t know and don’t care. I’ve heard many arguments both ways citing load time, automatic updates, what if Google goes down and maybe it’s already loaded because of the visitors browser history, so choose a side and take your pick. In my opinion they both work. Anyway, below is the Google method. I also included one other script to load enqueue to show you how to add more than one script. So, if you have other custom scripts you want to add, copy the “other scripts” block and add whatever your theme needs.

function ineedmyjava() {
if (!is_admin()) {

wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', false, '1.8.3', true);
wp_enqueue_script('jquery');

// other scripts...
wp_register_script(
'thumbslider',
get_bloginfo('template_directory') . '/js/jquery.easing.1.3.js',
array('jquery') );
wp_enqueue_script('thumbslider');

}
}

add_action('wp_enqueue_scripts', 'ineedmyjava');

How to query if is Page, Child of Page, or Grandchild of Page

Say you want to show a certain menu depending on what page you’re on. So if I have in my navigation a link that has Children and Grandchildren, this is how you check to see what page you’re on, if it’s a child or even a Grandchild of a certain page.

Do stuff if is page:

 if (is_page('products') ) {
//Do stuff
} 

Do stuff if is a child of a page: (My products page’s id=17 and I’m viewing, Products > “Cars”)

if ($post->post_parent == '17') {
//Do stuff
}

Do stuff if is a Grandchild of a page: (My products page’s id=17 and I’m viewing, Products > Cars > “Red Cars”)

global $post;
$ancs = get_ancestors($post->ID, 'page');
if ($ancs[1] == 17) {
//Do stuff
}

Do stuff if is a Page, or a Child of that page or a Grandchild of that page: (All together now)

global $post;
$ancs = get_ancestors($post->ID, 'page');
if ( $ancs[1] == 17 || $post->post_parent == '17' || is_page('products') ) {
//Do stuff
}

How to Change the Admin Menu Names in WordPress

The following will change, “Posts” to “Blog Posts” in the WordPress backend. I find this useful when creating sites for Clients. Sometimes the out-of-the-box naming convention for WordPress needs a little tweaking for the non power user. Simply add this function to your theme’s function.php file.

function change_post_menu_label() {
    global $menu;
    global $submenu;
    $menu[5][0] = 'Blog Posts';
    $submenu['edit.php'][5][0] = 'Blog Posts';
    $submenu['edit.php'][10][0] = 'Add a Blog Post';
    echo '';
}
add_action( 'admin_menu', 'change_post_menu_label' );