Vuoi creare un nuovo widget della dashboard in WordPress che mostri i cinque post più recenti? Sebbene esista probabilmente un plugin per questo, abbiamo creato uno snippet di codice rapido che puoi utilizzare per creare il widget della dashboard dei post più recenti in WordPress.
Istruzioni:
Tutto quello che devi fare è aggiungere questo codice al file functions.php del tuo tema o in un plugin specifico per il sito:
function wps_recent_posts_dw() {
?>
<ol>
<?php
global $post;
$args = array( 'numberposts' => 5 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li> (<? the_date('Y / n / d'); ?>) <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ol>
<?php
}
function add_wps_recent_posts_dw() {
wp_add_dashboard_widget( 'wps_recent_posts_dw', __( 'Recent Posts' ), 'wps_recent_posts_dw' );
}
add_action('wp_dashboard_setup', 'add_wps_recent_posts_dw' );
Nota: Se questa è la prima volta che aggiungi snippet di codice in WordPress, consulta la nostra guida su come copiare / incollare correttamente snippet di codice in WordPress, in modo da non rompere accidentalmente il tuo sito.
Se ti è piaciuto questo snippet di codice, prendi in considerazione la lettura dei nostri altri articoli sul sito come: Oltre 50 migliori temi WooCommerce per il tuo negozio online e come creare un modulo di donazione WordPress.
aggiungi alla categoria: dashboard
questo è quello che sto cercando,
grazie