[ WordPress技術類 ] Wordpress Customized feeds

行動版 for , 瀏覽人次: 675  , SSL Connection SSL
  • Wordpress Custom RSS

    1.  關於Custom RSS :

    Customized feeds 可以提供特定的內容與使用目的。

    2.  如何套用自訂 template:

    將 feed-atom.php  拿來客制化 (manually changing the feed templates to meet your needs),接下來確定放置的路徑,確定後需要add_action do_feed 並 load_template,讓 Wordpress 知道位置。
    function create_my_custom_posts() {
    load_template(plugin_dir_path(__FILE__).'/custom_rss/custom_atom.php');
    }
    add_action('do_feed_custom-posts', 'create_my_custom_posts', 10, 1);

    3.  如何只列特定條件的文章,例如某個分類、某個標籤:

    客制化的過程中,可以取某個分類或某個標籤。 自己寫sql 來取資料 (兩個TABLE取資料):
    $wp_query->request = "SELECT * FROM 
    ( SELECT * FROM posts-1 WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 10 ) A 
    UNION ALL 
    SELECT * FROM 
    ( SELECT * FROM posts-2 WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 10 ) B 
    ORDER BY post_date DESC LIMIT 10";
    $pageposts = $wpdb->get_results($wp_query->request, OBJECT);
    query_posts 的方式:
    query_posts( array ( 'category_name' => 'funny-game', 'posts_per_page' => -1, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) );

    4.  如何產生較美觀的網址:

    Custom RSS測試完成後,我們可以給它一個新家,利用rewrite rules來產生美觀的網址。
    add_action( 'init', 'custom_my_rss_url' );
    function custom_my_rss_url()
    {
        add_rewrite_rule( 'custom_rss/?([^/]*)','index.php?feed=$matches[1]', 'top' );
    }
    最後就會有一個這樣的RSS了, 裡面的文章是符合特定條件的 (可依需求自己設定條件) :    http://xxxxxx.xxxx.xxxxx/custom_rss/custom-posts
回 文章列表頁