Advertisement
zero50x

Яндекс Турбо страницы

Apr 5th, 2018
1,183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. <?php
  2.  
  3. $metrika = '123456789';
  4. $rsya = 'R-A-123456-1';
  5.  
  6.  
  7. function get_thumbnail_url()
  8. {
  9.     global $post;
  10.     $image_id = @get_post_thumbnail_id($post->ID);  
  11.     $image_url = @wp_get_attachment_image_src($image_id, 'full');
  12.     return isset($image_url[0]) ? $image_url[0] : '';
  13. }
  14. function spec_chars($text)
  15. {
  16.  return htmlspecialchars($text, ENT_HTML5 | ENT_QUOTES);
  17. }
  18.  
  19. function delete_sc($text)
  20. {
  21.     return preg_replace('#\[[^\]]+\]#is', '', $text);
  22. }
  23.  
  24. header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
  25. echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
  26. ?>
  27. <rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
  28. <channel>
  29.     <title>RSS-фид для Яндекса с влюченным режимом "Турбо"</title>
  30.     <link>http://site.ru</link>
  31.     <description>Тестовое описание</description>   
  32.     <yandex:logo>http://site.ru/images/logo-100-100.png</yandex:logo>
  33.     <yandex:logo type="square">http://site.ru/images/logo-180-180.png</yandex:logo>
  34.     <yandex:analytics id="<?php echo $metrika; ?>" type="Yandex"></yandex:analytics>
  35.     <yandex:adNetwork type="Yandex" id="<?php echo $rsya; ?>"></yandex:adNetwork>
  36. <?php
  37.     query_posts("cat=5&showposts=25");
  38.     while( have_posts()) : the_post(); $category = get_the_category(); ?>
  39.     <item turbo="true">
  40.         <title><?php echo spec_chars($post->post_title) ?></title>
  41.         <link><?php the_permalink_rss() ?></link>
  42.         <pdalink><?php the_permalink_rss() ?></pdalink>
  43.         <author><?php the_author(); ?></author>
  44.         <category><? echo spec_chars($category[0]->cat_name); ?></category>
  45.         <pubDate><?php echo mysql2date('D, d M Y H:i:s +0300', get_post_time('Y-m-d H:i:s'), false); ?></pubDate>
  46.         <yandex:genre>message</yandex:genre>   
  47.         <yandex:full-text><?php echo spec_chars(strip_tags(delete_sc(apply_filters('the_content_rss', $post->post_content)), ENT_QUOTES))?></yandex:full-text>     
  48. <?php
  49.  
  50.     if($thumb = get_thumbnail_url()){
  51. ?>
  52.         <enclosure url="<?php echo $thumb ?>" type="image/jpeg" />             
  53. <?php }
  54.  
  55.  
  56.  
  57.     $tags = wp_get_post_tags($post->ID);
  58.    
  59.     foreach($tags as $tag)
  60.     { ?>
  61.         <yandex:tags><?php echo spec_chars($tag->name); ?></yandex:tags>
  62. <?php   }
  63.  
  64. ?>
  65.     <guid isPermaLink="false"><?php the_guid(); ?></guid>
  66.     </item>
  67.     <?php endwhile;
  68.     wp_reset_query();
  69.     ?>
  70. </channel>
  71. </rss>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement