Latest from blog

How to Add Categories and Tags to WordPress pages

Web, Wordpress, work

No Comments

Share this post

Categories and Tags are not by default supported in WordPress themes, but if you want to support Categories and Tags in your WordPress theme, open up your functions.php file.

You can add categories and tags to your pages by using the add_meta_box() function. In your functions.php file, insert:

function add_category_box_on_page(){
//add meta box
add_meta_box(‘categorydiv’, __(‘Categories’), ‘post_categories_meta_box’, ‘page’, ‘side’, ‘low’);
add_meta_box(‘tagsdiv-post_tag’, __(‘Page Tags’), ‘post_tags_meta_box’, ‘page’, ‘side’, ‘low’);
add_action(‘save_post’, ‘page_cats_tags_save_postdata’);
}

This function adds both category and tags by using the same names (such as ‘tagsdiv-post_tag‘ and ‘categorydiv‘ ) that other WordPress functions use to make sure that the metaboxes that were created with the add_category_box_on_page() function that we created above. The ‘post_categories_meta_box‘ and ‘post_tags_meta_box‘ are used to render the meta boxes because they are native wordpress functions.

After inserting the add_category_box_on_page() function, insert:

add_action(‘admin_menu’, ‘add_category_box_on_page’);

This inserts the Category and Tag boxes onto the Page Editor. Next, add:

function page_cats_tags_save_postdata( $post_id ) {

$wpnj_post_type = $_POST['post_type'];

if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ){

}else{
// Check permissions
if ( ‘page’ == $wpnj_post_type ) {
if ( current_user_can( ‘edit_page’, $post_id ) ){

$wpnj_post_cats = array();

foreach($_REQUEST['post_category'] as $key=>$val){
$wpnj_post_cats[] = $val;
}
wp_set_post_categories( $post_id, $wpnj_post_cats );
}
}
}
}

The page_cats_tags_save_postdata( ) function saves the categories and tags selected with the $post_id.
Here is the entire code to insert into your functions.php to get categories and tags on your pages:

function add_category_box_on_page(){
//add meta box
add_meta_box(‘categorydiv’, __(‘Categories’), ‘post_categories_meta_box’, ‘page’, ‘side’, ‘low’);
add_meta_box(‘tagsdiv-post_tag’, __(‘Page Tags’), ‘post_tags_meta_box’, ‘page’, ‘side’, ‘low’);
add_action(‘save_post’, ‘page_cats_tags_save_postdata’);
}

add_action(‘admin_menu’, ‘add_category_box_on_page’);
function page_cats_tags_save_postdata( $post_id ) {

$wpnj_post_type = $_POST['post_type'];

if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ){

}else{
// Check permissions
if ( ‘page’ == $wpnj_post_type ) {
if ( current_user_can( ‘edit_page’, $post_id ) ){

$wpnj_post_cats = array();

foreach($_REQUEST['post_category'] as $key=>$val){
$wpnj_post_cats[] = $val;
}
wp_set_post_categories( $post_id, $wpnj_post_cats );
}
}
}
}

Read more

How to Get an Excerpt and Thumbnail from Child pages

Web, Wordpress

No Comments

Share this post

If you are looking to create a listing of childpages with excerpts and thumbnails (permalinks too!), look no further!

First step is to make sure that the page actually has children. You can do this by using:

<?php $children = get_pages(‘child_of=’.$post->ID); if( count( $children ) != 0 ) { ?>
Page has children
<?php } else { ?>
Page does not have children
<?php }; ?>

This would display “Page has Children” if the wordpress page had children, otherwise it would display “Page does not have children”.

Next, we need to set up arguments for getting the pages by using the post type, get the post parents id, and the number of posts. we then use the get_posts() function with the argument that we have created ($args) and we loop through each of the pages that can pass the is a child of the parent, using the $subpages variable that contains each page (or post).

<?php $children = get_pages(‘child_of=’.$post->ID);
if( count( $children ) != 0 ) { ?>
<?php
    // Set up the arguments for retrieving the pages
    $args = array(
        ‘post_type’ => ‘page’,
         ‘numberposts’ => 2,
         // $post->ID will get the ID of the current page
         ‘post_parent’ => $post->ID,
         ‘order’ => ASC,
         ‘orderby’ => title
    );
$subpages = get_posts($args);
// WordPress Loop
  foreach($subpages as $post) : setup_postdata($post);
?>

Items to be looped would go here

<?php endforeach; ?>
<?php } else { ?>
Page does not have children

<?php }; ?>

Next we grab the data that we want to be displayed with, using the the_title(), the_permalink(), the_post_thumbnail() and the_excerpt functions that are built into WordPress.

<?php $children = get_pages(‘child_of=’.$post->ID);
if( count( $children ) != 0 ) { ?>
<?php
// Set up the arguments for retrieving the pages
$args = array(
‘post_type’ => ‘page’,
‘numberposts’ => 2,
// $post->ID will get the ID of the current page
‘post_parent’ => $post->ID,
‘order’ => ASC,
‘orderby’ => title
);
$subpages = get_posts($args);
// Just another WordPress Loop
foreach($subpages as $post) : setup_postdata($post);
?>
   <div>
       <h1><?php the_title(); ?></h1>
       <div><a href=”<?php the_permalink() ?>”><?php the_post_thumbnail(‘thumbnail’); ?></a></div>
       <?php the_excerpt(); ?>
   </div>
<?php endforeach; ?>
<?php } else { ?>
Page does not have children

<?php }; ?>

That’s it! You can display what ever you want in the “Page does not have children” section if the page does not have any children. Enjoy!

Read more

How to add custom menuing to WordPress themes for WordPress 3.0

Wordpress

No Comments

Share this post

First off, I have had to scour the internet on multiple occasions to figure out how to actually build a WordPress theme with custom menus. The WordPress Codex has been pretty informative, but if you are just now adapting WordPress themes to WordPress 3.0, it can be a bit confusing.

In your theme folder in functions.php you have to register your menus. If you only want to one custom menu for your theme, use:

register_nav_menus( array( 'Menu_location' => 'Menu Description' ) );

( Replace Menu_location with your own name like Footer_menu etc… Replace Menu Description with whatever you want to call that menu. )

If you want to register more that one menu, you have to set up an array of menus using the register_nav_menus(); function. See the Example Below:

register_nav_menus(
array(
‘primary’=>’Primary Menu’,
‘linksidebar’=>’Link Sidebar’,
‘footer’=>’Footer Menu’
));

After your have registered either your menu or menus, open up the page in which you want to have the custom menu on. For my example, I am making the “primary” menu my main navigation, so I’m including it in header.php. Find where you want the custom menu to reside, and use the following to add the menu:

<?php wp_nav_menu( array( ‘theme_location’ => ‘primary’ ) ); ?>

In this example I am using the ‘primary’ menu. Replace ‘primary’ with whatever you have named your menu location.

Next, log into the WordPress Backend of your site and click on the Appearance tab on the left hand side of the Admin panel. In the Appearance group select Menus. On the Menus screen you will see the menus that you have registered in the functions.php file with drop downs. Below this box, you will find pages, posts, categories, and custom links that you can add to the menu on the right. Once you have added these, you can rename them or keep them the same

Read more

Cat Called Frisky – Free Vector

vectors

No Comments

Share this post

Another vector created spur of the moment. Free to use, just let me know!

cat

Click Here to Download “Cat Called Frisky”

Read more

Retro Flower – Free Vector

vectors

No Comments

Share this post

Sometimes I just let my brain go where it wants to while drawing. Rather than focus on drawing a certain object, I focus more on line and shape. In the end this is what I came up with! Free to use! just let me know!

retroflower
Click Here to Download “Retro Flower”

Read more

Happy Panda – Free Vector

vectors

No Comments

Share this post

For some reason while I was sketching around last night, I kept drawing a panda. The further that I went with the sketch, the more it began to develop into a fat Buddha. The Vector is Free to use, just let me know!

panda2

Click here to Download “Happy Panda”

Read more

For the Birds – Free Vector

vectors

No Comments

Share this post

In my spare time I decided to create some vectors out of some of my daily doodles. A while back in college I created a flash piece with a bird as one of the little movieclips. I used that bird as the inspiration as these doodles.  Here is the first set. I hope you enjoy!

birds

Click Here to download “For the Birds”

Read more

 
Share this post

© Jon Pierce Youngberg 2011. All Rights Reserved.