Entries tagged WordPress

wp_list_pages() for Custom Post Types

Posted on 2012/02/19 Comments

wp_list_pages() is a handy little function for displaying a list of hierarchical post type, and it works with custom post types too. Unfortunately, when used for a custom post type, the list items don’t have the necessary CSS classes for current page item/ancestors. Here’s a quick fix for this particular problem.

function kct_page_css_class( $css_class, $page, $depth, $args, $current_page ) {
  if ( !is_singular($args['post_type']) )
    return $css_class;

  global $post;
  $current_page  = $post->ID;
  $_current_page = $post;
  _get_post_ancestors($_current_page);

  if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) )
    $css_class[] = 'current_page_ancestor';
  if ( $page->ID == $current_page )
    $css_class[] = 'current_page_item';
  elseif ( $_current_page && $page->ID == $_current_page->post_parent )
    $css_class[] = 'current_page_parent';

  return $css_class;
}
add_filter( 'page_css_class', 'kct_page_css_class', 10, 5 );

KC DropBox

Posted on 2012/02/06 Comments

Here’s a simple plugin for uploading files from your WordPress site front-end. It uses Jaka Jancar’s DropBox Uploader and inspired by a tutorial on WP Tuts+ (although I took a slightly different approach). It’s pretty easy to use and you can integrate it in your contact forms.

Clone/download it from GitHub and feel free to let me know if you have any problem.

Using Built-in Post Finder in Plugins

Posted on 2012/01/20 Comments

I was making some improvements to the KC Posts widget module in my KC Essentials plugin, and I wanted to make it easy for the users to find post IDs they want to include/exclude from the query. As you may already know, in the Media admin page, we can ‘attach’ an attachment to a post. It uses a neat jQuery UI dialog box to find posts. Here’s how I use it in KC Essentials.
Continue…

jQuery in Widgets Admin Page

Posted on 2012/01/18 Comments

Here’s a quick tip. If you built a custom widget for your themes/plugins and you need jQuery for the configuration form, you’ll need to call it when the ajax process is done, that is when a widget was just dropped to a sidebar/widget area, or the user just saved the configuration.

jQuery(document).ready(function($) {
  $('.widgets-sortables').ajaxSuccess(function() {
    // do your thing
  });
});

Hacking Term List Table

Posted on 2012/01/11 Comments

Term list table, unlike post list table, is not very customizable. What I needed was to display the thumbnail/icon of each term, to make it easier for the content editors to distinguish one term from another.

Continue…