Come mostrare i post di “Oggi” storici in WordPress?
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