Created
July 25, 2018 12:55
-
-
Save Gkiokan/3c5b7ca92dc4a78104ff63327e23dad3 to your computer and use it in GitHub Desktop.
WP CPT Custom Columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
File: WP Custom Columns Extension | |
Author: Gkiokan Sali | |
Date: 25.07.2018 | |
*/ | |
class CustomColumn { | |
public static $post_type = 'Foo'; | |
public function __construct(){ | |
add_filter('manage_'. self::$post_type . '_posts_columns', [$this, 'posts_columns'], 15); | |
add_action('manage_'. self::$post_type . '_posts_custom_column', [$this, 'posts_custom_columns'], 1, 2); | |
add_filter('manage_edit-'. self::$post_type . '_sortable_columns', [$this, 'sortable_columns'], 5, 2); | |
} | |
/* | |
Adds Thumbs to the Admin | |
*/ | |
public function posts_columns($defaults){ | |
$defaults['wps_post_thumbs'] = __('Company Logo'); | |
$defaults['menu_order'] = "Reihenfolge"; | |
return $defaults; | |
} | |
public function posts_custom_columns($column_name, $id){ | |
$c = $column_name; | |
$post = get_post($id); | |
if($column_name === 'wps_post_thumbs'){ | |
echo the_post_thumbnail( array(125,80) ); | |
// $image = (get_post_meta($id, '_slider_image', true)); | |
// echo "<img src='$image' width=125px height=80px>"; | |
} | |
if($column_name == 'menu_order') | |
echo $post->menu_order; | |
} | |
public function sortable_columns($c){ | |
$c['menu_order'] = 'menu_order'; | |
return $c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment