✅ Notizie, temi, plugin WEB e WordPress. Qui condividiamo suggerimenti e le migliori soluzioni per siti web.

Come mostrare i post di “Oggi” storici in WordPress?

25

Potresti mostrare post "correlati" (utilizzando tag, categorie o altre parole chiave) per attirare più visualizzazioni di pagina. In alternativa, puoi mostrare i post storici di "Oggi" in passato alla fine del contenuto del post. Copia il seguente codice PHP e mettilo alla fine del template della funzione wordpress functions.php, preferibilmente usando il tema figlio.

function today_in_histroy(){
    $today = getdate();
    $args = array(
        'date_query' => array(
            array(
                'year'      => $today['year'],
                'compare'   => '!=',
            ),
            array(
                'month' => $today['mon'],
                'day'   => $today['mday'],
            ),
        ),
    );
    $postlist = get_posts($args);
    $html = '<h3 class="tih-title">Posts of Historic Today</h3><ul class="tih-title-list">';
    if(!empty($postlist)){
        foreach ($postlist as $key => $post) {
            $html .= '<li class="tih-title-item"><a href="'. get_permalink($post->ID). '" title="'. $post->post_title. '">'. $post->post_title. '</a></li>';
        }
        $html .= '</ul>';
        return $html;
    }
    return "";
}
 
function add_today_in_histroy($content){
    global $post;
    return  $content. today_in_histroy(); 
}
add_filter('the_content','add_today_in_histroy');

L’idea è di avere una query che cerchi i post e utilizzi add_filter per aggiungere a the_content.

wordpress

Fonte di registrazione: helloacm.com

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More