Last active
August 29, 2015 14:00
-
-
Save FlorianPalme/11234568 to your computer and use it in GitHub Desktop.
WordPress Custom Columns Tutorial Teil 1
This file contains 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 | |
// Spalten-Überschriften registrieren | |
add_filter( 'manage_{$posttype}_posts_columns', 'custom_manage_{$posttype}_posts_columns' ); | |
/** | |
* Hinzufügen der Spalten-Überschriften | |
* | |
* @param array $aColumns | |
* | |
* @return array $aColumns | |
*/ | |
function custom_manage_{$posttype}_posts_columns( $aColumns ) | |
{ | |
return $aColumns; | |
} |
This file contains 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 | |
function custom_manage_{$posttype}_posts_columns( $aColumns ) | |
{ | |
$aColumns[ 'my_slug' ] = __( 'Slug', 'my-theme' ); | |
$aColumns[ 'my_metavalue' ] = __( 'A Meta Value', 'my-theme' ); | |
return $aColumns; | |
} |
This file contains 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 | |
$aColumns = array(); | |
// Checkbox | |
$aColumns[ 'cb' ] = '<input type="checkbox" />'; | |
// Titel | |
$aColumns[ 'title' ] = __( 'My custom title', 'my-theme' ); |
This file contains 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 | |
// Ausgabe der Spalten-Werte registrieren | |
add_filter( 'manage_{$posttype}_posts_custom_column', 'manage_{$posttype}_posts_custom_column', 10, 2 ); | |
/** | |
* Ausgabe der Spalten-Werte | |
* | |
* @param string $sColumn | |
* @param integer $iPostID | |
*/ | |
function manage_{$posttype}_posts_custom_column( $sColumn, $iPostID ) | |
{ | |
} |
This file contains 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 | |
function manage_{$posttype}_posts_custom_column( $sColumn, $iPostID ) | |
{ | |
switch( $sColumn ){ | |
case 'my_slug': | |
// Ausgabe für Spalte "Slug" | |
break; | |
case 'my_metavalue': | |
// Ausgabe für Spalte "A Meta Value" | |
break; | |
} | |
} |
This file contains 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
<?ph | |
function manage_{$posttype}_posts_custom_column( $sColumn, $iPostID ) | |
{ | |
switch( $sColumn ){ | |
case 'my_slug': | |
// Ausgabe für Spalte "Slug" | |
global $post; | |
echo $post->post_name; | |
break; | |
case 'my_metavalue': | |
// Ausgabe für Spalte "A Meta Value" | |
echo get_post_meta( $iPostID, '_edit_lock', true ); | |
break; | |
} | |
} |
This file contains 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 | |
// Spalten-Überschriften registrieren | |
add_filter( 'manage_post_posts_columns', 'custom_manage_post_posts_columns' ); | |
/** | |
* Hinzufügen der Spalten-Überschriften | |
* | |
* @param array $aColumns | |
* | |
* @return array $aColumns | |
*/ | |
function custom_manage_post_posts_columns( $aColumns ) | |
{ | |
$aColumns[ 'my_slug' ] = __( 'Slug', 'my-theme' ); | |
$aColumns[ 'my_metavalue' ] = __( 'A Meta Value', 'my-theme' ); | |
return $aColumns; | |
} | |
// Ausgabe der Spalten-Werte registrieren | |
add_filter( 'manage_post_posts_custom_column', 'manage_post_posts_custom_column', 10, 2 ); | |
/** | |
* Ausgabe der Spalten-Werte | |
* | |
* @param string $sColumn | |
* @param integer $iPostID | |
*/ | |
function manage_post_posts_custom_column( $sColumn, $iPostID ) | |
{ | |
switch( $sColumn ){ | |
case 'my_slug': | |
// Ausgabe für Spalte "Slug" | |
global $post; | |
echo $post->post_name; | |
break; | |
case 'my_metavalue': | |
// Ausgabe für Spalte "A Meta Value" | |
echo get_post_meta( $iPostID, '_edit_lock', true ); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment