• I’ve been using an added function to load a modified rss template. Works fine, but now I need to add a custom template for a CPT.

    I have code for each,which works ok, but can’t be used together because one over-rides the other.

    I don’t know enough php to modify.

    Here’s the code I’m using…

    
    remove_all_actions( 'do_feed_rss2' );
    add_action( 'do_feed_rss2', function() {
    if ( $rss_template = locate_template( '/feeds/notes-feed.php' ) )
    load_template( $rss_template );
    else
    do_feed_rss2(); // Call default function
    }, 10, 1 );
    

    and

    
    remove_all_actions( 'do_feed_rss2' );
    add_action( 'do_feed_rss2', 'item_feed_rss2', 10, 1 );
    function item_feed_rss2() {
    $rss_template = get_template_directory() . '/feeds/item-feed.php';
    if( get_query_var( 'post_type' ) == 'item' and file_exists(      $rss_template ) )
    load_template( $rss_template );
    else
    do_feed_rss2(); // Call default function
    
    • This topic was modified 9 years, 9 months ago by gulliver.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter gulliver

    (@gulliver)

    UPDATE…

    With relatively little php knowledge, I’m wondering if I can use this…

    
    remove_all_actions( 'do_feed_rss2' );
    add_action( 'do_feed_rss2', 'item_feed_rss2', 10, 1 );
    function item_feed_rss2() {
    $rss_template = get_template_directory() . '/feeds/item-feed.php';
    $rss_template_notes = get_template_directory() . '/feeds/notes-feed.php';
    if( get_query_var( 'post_type' ) == 'item' and file_exists( $rss_template ) )
    load_template( $rss_template );
    elseif( get_query_var( 'post' ) and file_exists( $rss_template_notes ) )
    load_template( $rss_template_notes );
    else
    do_feed_rss2(); // Call default function
    }
    
    
    Thread Starter gulliver

    (@gulliver)

    FURTHER UPDATE…

    I’ll add this in case it’s of use to someone.

    It seems to work ok with…

    
    // This delivers valid feeds, with the correct templates.
    remove_all_actions( 'do_feed_rss2' );
    add_action( 'do_feed_rss2', function() {
    $rss_template = get_template_directory() . '/feeds/item-feed.php';
    $rss_template2 = get_template_directory() . '/feeds/notes-feed.php';
    //if ( $post_type = 'item'  )
    if( get_query_var( 'post_type' ) == 'item' and file_exists( $rss_template ) )
    load_template($rss_template);
    elseif ( $post_type = 'post' )
    load_template($rss_template2);
    else
    do_feed_rss2(); // Call default function
    }, 10, 1 );
    

    This enables use of a custom template for the feed of normal posts, and use of a different custom template for the feed of the CPT ‘item’.

    The feeds differ in channel title/link/description.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Using 2 modified feed templates.’ is closed to new replies.