new rss channel

This commit is contained in:
arlemp@selectel.ru
2022-02-21 13:53:43 +03:00
parent 9f2f3e0805
commit 3727594359
3 changed files with 81 additions and 0 deletions

View File

@@ -636,3 +636,15 @@ add_action( 'pre_get_posts', function ($query) {
}); });
function add_text_to_the_feed_end( $content ){
$content .= '
<p>
Источник: <a href="'. get_bloginfo('url') .'">'. get_bloginfo('name') .'</a>.
</p>
';
return $content;
}
add_filter( 'the_excerpt_rss', 'add_text_to_the_feed_end' );

View File

@@ -27,6 +27,17 @@ $posts = get_posts( array(
'suppress_filters' => true, // подавление работы фильтров изменения SQL запроса 'suppress_filters' => true, // подавление работы фильтров изменения SQL запроса
)); ));
// Яндекс Новости
create_rss_file($posts, 'views/rss/yanews.php', '/vhosts/beta/rss/yanews.xml');
// Общая лента
create_rss_file($posts, 'views/rss/yanews.php', '/vhosts/beta/rss/news.xml');
exit;
if( $posts ){ if( $posts ){
@@ -44,6 +55,30 @@ if( $posts ){
} }
function create_rss_file($posts, $temp, $file){
if( $posts ){
ob_start();
include($temp);
$result = ob_get_contents();
ob_end_clean();
$result = trim($result);
if ($result !== ''){
file_put_contents($file, trim($result));
}
}
}

34
views/rss/rssnews.php Normal file
View File

@@ -0,0 +1,34 @@
<?echo '<?xml version="1.0" encoding="UTF-8"?>';?>
<rss version="2.0">
<channel>
<language>ru</language>
<copyright><?=date('Y')?>, Ветеринария и жизнь</copyright>
<title>Новости с сайта www.vetandlife.ru</title>
<link>https://www.vetandlife.ru</link>
<lastBuildDate><?=_U2RFC822(date('Y-m-d h:i:s'))?></lastBuildDate>
<description>Новости с сайта www.vetandlife.ru</description>
<image>
<url>https://vetandlife.ru/wp-content/themes/vij/pub/vij.png</url>
<title>Ветеринария и жизнь</title>
<link>https://www.vetandlife.ru</link>
</image>
<?foreach($posts as $post):?>
<item>
<title><?=htmlspecialchars($post->post_title)?></title>
<guid><?=get_permalink($post->ID);?></guid>
<description><?=htmlspecialchars($post->post_excerpt);?></description>
<?$category=get_the_category($post->ID);?>
<category><?=$category?></category>
<?$author = get_the_author($post->ID);?>
<?if (isset($author) and $author !== ''):?>
<author><?=$author?></author>
<?endif?>
<?if (has_post_thumbnail($post->ID)):?>
<enclosure url="<?=get_the_post_thumbnail_url($post->ID)?>" type="image/jpeg"/>
<?endif?>
<pubDate><?=_U2RFC822($post->post_date)?></pubDate>
<description><![CDATA[<?=strip_tags($post->post_content)?>]]></description>
</item>
<?endforeach?>
</channel>
</rss>