Birkaç gündür bir proje üzerinde epey çalıştığım bir konu.
Temanızın ana dizininde öncelikle feed isimli bir klasor oluşturun sonrasında functions.php dosyasına kodları ekleyin:
add_action('init', 'aaaFeed');
function aaaFeed(){
add_feed('xxx', 'aaaFeedFunc');
}
function aaaFeedFunc(){
get_template_part('feed/rss', 'xxx');
}Bu işlemi yaptıktan sonra rss-xxx.php isimli bir php sayfası oluşturup feed klasorunun içine atın.
<?php
$posts = query_posts('cat=1&showposts=1'); // kategori idsine göre kaç adet yazı cekecekseniz burayı düzenleyin
header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
?>
<rss version="2.0"
xmlns:g="http://base.google.com/ns/1.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
<?php do_action('rss2_ns'); ?>>
<channel>
<title><?php bloginfo_rss('name'); ?> - Feed</title>
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss('url') ?></link>
<description><?php bloginfo_rss('description') ?></description>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
<language><?php echo get_option('rss_language'); ?></language>
<sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
<sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
<?php do_action('rss2_head'); ?>
<?php while(have_posts()) : the_post(); ?>
<item>
<g:id><?php echo get_the_ID(); ?></g:id>
<g:title><?php echo (get_post_meta($post->ID, "title", true)); ?></g:title>
<g:description><?php echo (get_post_meta($post->ID, "description", true)); ?></g:description>
<g:link><?php the_permalink() ?></g:link>
<g:image_link><?php if ( has_post_thumbnail() ) { the_post_thumbnail_url();} ?></g:image_link>
<g:condition>Yeni</g:condition>
<g:availability>Stokta</g:availability>
<g:price><?php echo (get_post_meta($post->ID, "fiyat", true)); ?> TRY</g:price>
<g:brand><?php echo (get_post_meta($post->ID, "marka", true)); ?></g:brand>
</item>
<?php endwhile; ?>
</channel>
</rss>Daha sonra tarayıcınızda "siteadi.com/feed/xxx" adresine gidin, direk xml çıktısı göreceksiniz.
Ben bunu Google Merchant Center için yaptım siz ihtiyacınıza göre düzenleyin.