|
<?php
|
|
//////////////////
|
|
//
|
|
// GENERATION DU SITE MAP GOOGLE ACTUS FR LAST
|
|
//
|
|
//////////////////
|
|
|
|
|
|
// J'ai supprimé pas mal de bouts de code qui géraient la langue.
|
|
|
|
|
|
|
|
add_action("publish_post", "eg_create_sitemap_actus_last_fr"); // on lance la fonction à chaque publication
|
|
add_action("flux_actus_last_fr", "eg_create_sitemap_actus_last_fr"); // la fonction lancée
|
|
|
|
function eg_create_sitemap_actus_last_fr() { // notre fonction
|
|
|
|
$postsForSitemap = get_posts(array( // récupéation du dernier post
|
|
'numberposts' => 1,
|
|
'post_type' => array('post'),
|
|
'order' => 'DESC',
|
|
'category' => '34'
|
|
));
|
|
|
|
|
|
|
|
$sitemap = '<?xml version="1.0"?>'."\n";
|
|
$sitemap .= '<rss version="2.0">'."\n";
|
|
$sitemap .= "\t".'<channel>'."\n";
|
|
|
|
|
|
|
|
$ins_con = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
|
|
|
|
|
|
foreach($postsForSitemap as $post) { // on applique des traitements spécifiques à la salle de presse
|
|
|
|
setup_postdata($post);
|
|
$postdate = explode(" ", $post->post_date);
|
|
$rfcdate = new DateTime($postdate[0]);
|
|
$post_date = $rfcdate->format(DateTime::RFC822);
|
|
$post_date = str_replace('21 00:00:00 +0000','2021 13:00:00 GMT',$post_date);
|
|
|
|
|
|
|
|
// TRAITEMENT TITRE
|
|
$sql_post = "SELECT * FROM `wp_ins_posts` WHERE `ID` = ".$post->ID;
|
|
$query_post = mysqli_query($ins_con,$sql_post);
|
|
while($data = mysqli_fetch_assoc($query_post)){
|
|
$post_title = $data['post_title'];
|
|
}
|
|
|
|
$post_title = $post_title[0];
|
|
|
|
|
|
|
|
|
|
|
|
$link_post = get_bloginfo('wpurl').'/'.$metaArray['_qts_slug_fr'].'/'.$post->ID;
|
|
|
|
$thumb = get_post_thumbnail_id($post->ID);
|
|
$img_url = wp_get_attachment_url( $thumb,'full'); // Get img URL
|
|
$image = aq_resize( $img_url, 820, 432, true );
|
|
$image_url_820 = esc_url( $image );
|
|
|
|
if(empty($image_url_820)){
|
|
$image_url_820 = $img_url;
|
|
}
|
|
|
|
|
|
|
|
|
|
$excerpt = get_the_excerpt($post->ID);
|
|
|
|
|
|
|
|
|
|
$sitemap .= "\t\t\t"."<language>fr-fr</language>".
|
|
"\n\t\t\t"."<pubDate> ".$post_date." </pubDate>".
|
|
"\n\t\t\t"."<title>INSERM (Salle de presse)</title>".
|
|
"\n\t\t\t"."<description>Salle de presse INSERM</description>".
|
|
"\n\t\t\t"."<link>https://presse.inserm.fr/</link>".
|
|
"\n\t\t\t\t"."<item>".
|
|
"\n\t\t\t\t\t"."<title>".$post_title."</title>".
|
|
"\n\t\t\t\t\t"."<description>".$excerpt."</description>".
|
|
"\n\t\t\t\t\t"."<link>".$link_post."</link>".
|
|
"\n\t\t\t\t\t"."<guid>".$link_post."</guid>".
|
|
"\n\t\t\t\t"."</item>".
|
|
"\n\t\t\t\t"."<image>".
|
|
"\n\t\t\t\t\t"."<title>".$post_title."</title>".
|
|
"\n\t\t\t\t\t"."<url>".$image_url_820."</url>".
|
|
"\n\t\t\t\t\t"."<link>".$image_url_820."</link>".
|
|
"\n\t\t\t\t"."</image>".
|
|
"\n\t"."</channel>";
|
|
|
|
|
|
}
|
|
|
|
$sitemap .= "\n".'</rss>';
|
|
//echo ABSPATH;
|
|
$fp = fopen(ABSPATH . "rss_actus_last_fr.xml", 'w');
|
|
fwrite($fp, $sitemap);
|
|
fclose($fp);
|
|
|
|
}
|
|
|
|
?>
|