2

I am currently working on a theme which has two post types - one is the normal "posts" post type, and the other is for portfolio posts - "mytheme_portfolio".

I am using JetPack's infinite scroll to render new posts, as follows:

function mytheme_render_infinite_scroll() {
    while ( have_posts() ) : the_post();

        get_template_part( 'content', 'archive-portfolio' );

    endwhile;
}

function mytheme_jetpack_setup() {
    add_theme_support( 'infinite-scroll', array(
        'container' => 'content',
        'type'  =>  'click',
        'render' => 'mytheme_render_infinite_scroll',
    ) );
}
add_action( 'after_setup_theme', 'mytheme_jetpack_setup' );

This is working fine but I am wondering how I can specify different content- template files to render depending on the which post type's archive/category/tag page you are currently viewing. As it happens now I am calling content-archive-portfolio.php when the infinite scroll is triggered, what I would like is to call content-archive-portfolio.php if portfolio posts are being viewed, but content.php if the blog is being viewed.

Any help would be greatly appreciated, thanks!

0

1 Answer 1

5

Replace the above mytheme_render_infinite_scroll function with this:

function mytheme_render_infinite_scroll() {
    while ( have_posts() ) : the_post();
        if ('mytheme_portfolio' == get_post_type()) :
            get_template_part( 'content', 'archive-portfolio' );
        else :
            get_template_part( 'content', get_post_format() );
        endif;
    endwhile;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.