Advertisement
Guest User

rss.php inside theme folder

a guest
Nov 19th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.61 KB | None | 0 0
  1. <?php
  2. /**
  3. * Template Name: Google News Feed RSS
  4. */
  5. //$postCount = 50;
  6. //$posts = query_posts('category__not_in=1,46&showposts=' . $postCount);
  7. $args_gnr = array(
  8. 'post_type' => 'post',
  9. 'post_status' => 'publish',
  10. 'category__not_in' => array(1),
  11. 'showposts' => 50,
  12. 'orderby' => 'date',
  13. 'order' => 'DESC',
  14. 'post_status' => 'publish',
  15. 'post_type'=>'post'
  16. );
  17. $query_gnr = new WP_Query( $args_gnr );
  18. header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
  19. echo '<?xml version="1.0" encoding="UTF-8"?>';
  20. ?>
  21. <rss version="2.0"
  22. xmlns:content="http://purl.org/rss/1.0/modules/content/"
  23. xmlns:media="http://search.yahoo.com/mrss/"
  24. xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  25. xmlns:dc="http://purl.org/dc/elements/1.1/"
  26. xmlns:atom="http://www.w3.org/2005/Atom"
  27. xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
  28. xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  29. <?php do_action('rss2_ns'); ?>>
  30. <channel>
  31. <title>Website.com</title>
  32. <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
  33. <link>https://www.website.com</link>
  34. <description>Website description</description>
  35. <lastBuildDate><?php echo get_feed_build_date( 'r' ); ?></lastBuildDate>
  36. <language>hr</language>
  37. <sy:updatePeriod>hourly</sy:updatePeriod>
  38. <sy:updateFrequency>1</sy:updateFrequency>
  39. <image><title>Racunalo.com</title><url>https://www.website.com/logo_rss.png</url><link>https://www.website.com</link><width>125</width><height>40</height><description>Publikacije i vijesti iz svijeta poslovanja i tehnologije</description></image>
  40. <?php if($query_gnr->have_posts()): while($query_gnr->have_posts()): $query_gnr->the_post(); ?>
  41. <item>
  42. <title><?php the_title_rss(); ?></title>
  43. <link><?php the_permalink_rss(); ?></link>
  44. <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
  45. <dc:creator><?php the_author(); ?></dc:creator>
  46. <?php
  47. $thumbnail_ID = get_post_thumbnail_id($post->ID);
  48. $thumbnail = wp_get_attachment_image_src($thumbnail_ID, 'thumb');
  49. $mime_vrsta =  get_post_mime_type( $thumbnail_ID );
  50. ?>
  51. <media:content url="<?php echo $thumbnail[0]; ?>" type="<?php echo $mime_vrsta; ?>" expression="full" width="1200" height="675">
  52. <media:description type="plain">
  53. <![CDATA[Photo desc - <?php the_title_rss(); ?>]]>
  54. </media:description>
  55. <media:credit role="author" scheme="urn:ebu">
  56. <![CDATA[Website.com - <?php the_author(); ?>]]>
  57. </media:credit>
  58. </media:content>
  59. <?php the_category_rss( 'rss2' ); ?>
  60. <guid isPermaLink="false"><?php the_guid(); ?></guid>
  61. <description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
  62. <?php
  63. //$content = get_the_content_feed( 'rss2' );
  64. //$content = apply_filters( 'the_content', get_the_content() );
  65. //$content = str_replace( ']]>', ']]&gt;', $content );
  66. // code for spliting content after <h2>...</h2> to insert "AD block", which not parsed and displayed here
  67. $sadrzaj = get_extended($post->post_content);
  68. $sadrzaj['main'] = $sadrzaj['main'].'</h2>';
  69. $prvi = apply_filters('the_content', $sadrzaj['main']);$sadrzaj['extended'] = $sadrzaj['extended'];
  70. $sadrzaj['extended'] = str_replace('</h2>','',$sadrzaj['extended']);
  71. $drugi = apply_filters('the_content', $sadrzaj['extended']);
  72. $prvi_skoro = str_replace("</h2>\n</h2>","</h2>",$prvi);
  73. //echo str_replace(".</p>","",$prvi_skoro);
  74. $procisceni = str_replace('</h2><p>','<p>',$drugi);
  75. ?>
  76. <content:encoded><![CDATA[<?php echo str_replace(".</p>","",$prvi_skoro); echo $procisceni; ?>]]></content:encoded>
  77. <?php rss_enclosure(); ?>
  78. <?php do_action('rss2_item'); ?>
  79. </item>
  80. <?php endwhile; endif; wp_reset_postdata(); ?>
  81. </channel>
  82. </rss>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement