Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Register post type
- add_action( 'init', 'cw_create_ci_ads' );
- function cw_create_ci_ads() {
- register_post_type( 'ci_ads',
- array(
- 'labels' => array(
- 'name' => 'Ads',
- 'singular_name' => 'Ad',
- 'add_new' => 'Add New',
- 'add_new_item' => 'Add New Ad',
- 'edit' => 'Edit',
- 'edit_item' => 'Edit Ad',
- 'new_item' => 'New Ad',
- 'view' => 'View',
- 'view_item' => 'View Ad',
- 'search_items' => 'Search Ads',
- 'not_found' => 'No Ads found',
- 'not_found_in_trash' => 'No Ads found in Trash'
- ),
- 'hierarchical' => true,
- 'public' => true,
- 'exclude_from_search' => true,
- 'menu_position' => 30,
- 'supports' => array( 'title','thumbnail','page-attributes' ),
- 'taxonomies' => array( '' ),
- 'menu_icon' => plugins_url( 'images/icon-ci_ads.png', __FILE__ ),
- 'has_archive' => true,
- 'rewrite' => array('slug' => 'ads'),
- )
- );
- }
- // Add columns to the overview page for a cpt
- function cw_add_custom_columns( $cols ) {
- $cols = array(
- 'cb' => '<input type="checkbox" />',// leave this here or mass edit/delete will not work
- 'title' => __( 'Title' ),
- 'ci_ad_size' => __( 'Size' ),
- 'ci_ad_url' => __( 'URL' ), );
- return $cols;
- }
- add_filter( "manage_ci_ads_posts_columns", "cw_add_custom_columns" );
- // Populate the columns
- function cw_populate_custom_columns( $column, $post_id ) {
- switch ( $column ) {
- case "ci_ad_size":
- $ad_size = get_post_meta( $post_id, 'ci_ad_size', true);
- echo '<a style="text-transform:capitalize;" href="' . $ad_size . '">' . $ad_size. '</a>';
- break;
- case "ci_ad_url":
- $ad_url = get_post_meta( $post_id, 'ci_ad_url', true);
- echo '<a href="' . $ad_url . '">' . $ad_url. '</a>';
- break;
- case "ci_ad_image":
- $ad_image = get_post_meta( $post_id, the_post_thumbnail(), true);
- echo '<a href="' . $ad_image . '">' . $ad_image. '</a>';
- break;
- }
- }
- add_action( "manage_posts_custom_column", "cw_populate_custom_columns", 10, 2 ); // what are the 10 and 2?
- // Make the new columns sortable
- function cw_sortable_custom_columns() {
- return array(
- 'ci_ad_url' => 'ci_ad_url',
- 'ci_ad_size' => 'ci_ad_size'
- );
- }
- add_filter( "manage_edit-ci_ads_sortable_columns", "cw_sortable_custom_columns" );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement