• Resolved wallacelin

    (@wallacelin)


    Hello, I am building a website with X Theme Pro which comes with the custom post type “Portfolio” (x-portfolio). I have successfully applied Jetpack’s infinite scroll to the blog. I would like to apply the infinite scroll to the portfolio archive page.

    I have seen this issue scantly discussed and someone on Github confirming it was possible, but I have not found any direction on editing this module to extend it to other custom post types.

    I’m under the impression I have to copy the theme’s code to render the CPT in the function jetpack_infinite_scroll_render. I added the code but it’s not working.

    Are there additional steps to applying infinite scroll to custom post types? Would appreciate it if someone can shed some light on this or point me in the right direction. Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support KokkieH

    (@kokkieh)

    Hi there,

    You should be able to use this filter to enable infinite scroll on any archive page on your site, like the portfolio archive:

    https://developer.jetpack.com/hooks/infinite_scroll_archive_supported/

    There’s an example on that page of using this hook to enable infinite scroll on the Search and WooCommerce shop archive pages. Also see: https://jetpack.com/2013/06/28/infinite-scroll-search/

    Thread Starter wallacelin

    (@wallacelin)

    Hello @kokkieh,

    Thank you, I have modified and added this filter to my child theme. While I can confirm this added support for my post types (posts and the portfolio), I still can’t get infinite scroll to work on the portfolio archives.

    This is my filter:

    
    /* Add inifinite scroll support for blog and portfolio */
    function jetpack_infinite_scroll_support() {
        $supported = current_theme_supports( 'infinite-scroll' ) && ( is_home() || is_post_type_archive('post') || is_post_type_archive('x-portfolio') );
    
        return $supported;
    }
    add_filter( 'infinite_scroll_archive_supported', 'jetpack_infinite_scroll_support' );
    

    Getting desperate here, so I’m going to share the rest of my code:

    
    /* Enable infinite scroll by Jetpack */
    function jetpack_infinite_scroll_init() {
      add_theme_support( 'infinite-scroll', array(
        'type'            => 'click',
        'container'       => 'content',
        'render'          => 'jetpack_infinite_scroll_render',
        'posts_per_page'  => get_option('posts_per_page'),
        'footer'          => 'global-footer',
        'footer_widgets'  => true,
        'footer_callback' => 'no_jetpack_footer',
      ) );
    }
    add_action('after_setup_theme', 'jetpack_infinite_scroll_init');
    

    and for my render function adapted for X Theme:

    
    /* Render posts on infinite scroll */
    function jetpack_infinite_scroll_render() {
      $is_filterable_index = is_home() && x_get_option( 'x_ethos_filterable_index_enable' ) == '1';
      if (get_post_type() == 'post') {
        if ( $is_filterable_index ) :
          x_get_view( 'ethos', '_index' );
        else :
          x_get_view( 'global', '_index' );
        endif;
      } else if (get_post_type() == 'x-portfolio') {
        x_get_view( 'global', '_portfolio');
      }
    }
    

    By all means this should be able to render the portfolio posts, but nothing different occurs. Either my render code is wrong or I am missing some other settings?

    Plugin Contributor James Huff

    (@macmanx)

    It looks proper to me, yes, but the theme could always override it.

    Have you checked with the theme’s support on this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Infinite Scroll on Portfolio (CPT)?’ is closed to new replies.