- Home
- Categorie
- Coding e Sistemistica
- WordPress
- Codice che mette le anteprime nella bacheca
-
Codice che mette le anteprime nella bacheca
Questo codice mette le anteprime come si può vedere, ma solo negli articoli, nelle pagine no, come lo modifico?
[PHP]function mini_featured_image($post_ID) {
$post_thumbnail_id = get_post_thumbnail_id($post_ID);
if ($post_thumbnail_id) {
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'thumb-admin');
return $post_thumbnail_img[0];
}
}/**
- Insert the new column
*/
function mini_columns($defaults) {
$defaults['featured_image'] = __('Anteprima','mini_admin');
return $defaults;
}
/**
- Show the thumb in admin column
*/
function mini_columns_content($column_name, $post_ID) {
if ($column_name == 'featured_image') {
$post_featured_image = mini_featured_image($post_ID);
if ($post_featured_image) {
// when there is an image
echo '<img width="60" height="60" src="' . $post_featured_image . '" alt="">';
}
else {
// when there is not image
echo '<img src="http://placehold.it/60/ffffff/999999?text=No+Thumb" alt="">';
}
}
}
/**
- Filter for the column
*/
add_filter('manage_posts_columns', 'mini_columns');
add_action('manage_posts_custom_column', 'mini_columns_content', 10, 2);[/PHP]
- Insert the new column
-
Ciao Apthu,
vado a memoria, il nome dell'hook dovrebbe essere generato in base al post type, invece di posts prova page -> 'manage_posts_columns' e 'manage_posts_custom_column'
-
Così è peggio, non le mostra più neanche negli articoli
[PHP]/* Filter for the column */
add_filter('manage_page_columns', 'mini_columns');
add_action('manage_page_custom_column', 'mini_columns_content', 10, 2);[/PHP]
-
Ho scritto male sopra con la fretta, il post type è pages plurale, ovviamente devi aggiungere filtri e azioni per tutti i post type in cui devi mostrare la miniatura, nel tuo caso posts e pages.
-
Funziona, in pratica ci ho aggiunto solo 2 filtri in fondo
[PHP]/----------------- Mette le anteprime nella Bacheca ->Articoli/Pagine -----------------/
function mini_featured_image($post_ID) {
$post_thumbnail_id = get_post_thumbnail_id($post_ID);
if ($post_thumbnail_id) {
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'thumb-admin');
return $post_thumbnail_img[0];
}
}/**
- Insert the new column
*/
function mini_columns($defaults) {
$defaults['featured_image'] = __('Anteprima','mini_admin');
return $defaults;
}
/**
- Show the thumb in admin column
*/
function mini_columns_content($column_name, $post_ID) {
if ($column_name == 'featured_image') {
$post_featured_image = mini_featured_image($post_ID);
if ($post_featured_image) {
// when there is an image
echo '<img width="60" height="60" src="' . $post_featured_image . '" alt="">';
}
else {
// when there is not image
echo '<img src="http://placehold.it/60/ffffff/999999?text=No+Thumb" alt="">';
}
}
}
/**
- Filter for the column
*/
add_filter('manage_posts_columns', 'mini_columns');
add_action('manage_posts_custom_column', 'mini_columns_content', 10, 2);
add_filter('manage_pages_columns', 'mini_columns');
add_action('manage_pages_custom_column', 'mini_columns_content', 10, 2);
[/PHP]
- Insert the new column
-
Ottimo.