WooCommerce选项卡中的自定​​义Shortcode Ajax分页

时间:2018-06-27 15:59:52

标签: ajax wordpress woocommerce

我有一个自定义的简码,可以在WooCommerce单一产品页面的页面和自定义选项卡中显示配方。

简码可以正常工作,但是分页符却不能,它只是重新加载了前3个项目。

在此处https://dizzydev8.co.uk/product/steviol-sweetener/查看食谱标签

如果我在普通页面https://dizzydev8.co.uk/recipes-list/上使用简码 然后,即使稍微慢一点,ajax也会按预期工作。

我假设这是在WooCommerce中如何生成选项卡与分页如何工作之间的冲突。我有一个简单的方法吗?

jQuery(function($) {
$('#recipeswrapper').on('click', '#ajaxpagination a', function(e){
    e.preventDefault();
    var link = $(this).attr('href');
    $('#recipeswrapper').fadeOut(50, function(){
        $(this).load(link + ' #recipeswrapper', function() {
            $(this).fadeIn(50);
        });
    });
});
});



function link_recipesgrid( $atts ) {
extract(shortcode_atts(array(
    'number' => '6',
    'recipegroup' => '',
'id' => $post ? $post->ID : 0,
), $atts));


$paged = get_query_var('paged') ? get_query_var('paged') : 1; 



//Setup the query to retrieve the posts that exist under each term

query_posts(  array ( 
          'post_type' => 'recipes',
          'orderby' => 'date',
          'order' =>  'DESC',
          'post_status' => 'publish',
          'posts_per_page' => $number,
          'paged' => $paged,
          'recipegroup' => $recipegroup,
          'include' => $id,
          ));


$list = ' ';   
while ( have_posts() ) { the_post();                            
$featuredimage = get_the_post_thumbnail($post->ID, $size = 'snippets') ;


$list .=  '<li class="recipesbox"> 

<div class="recipesIcon">
<h4 class="recipesGridTitle"><a href="'. get_permalink($post->ID) .'">'. get_the_title($post->ID) .'</a></h4>
<a href="'. get_permalink($post->ID) .'">' . $featuredimage . '<a></div>


</li>';

}


return 
'<div class="recipeswrapper" id="recipeswrapper"><ul class="recipesgrid">'
. $list 
. '</ul>'.
'<div class="pagination" id="ajaxpagination"><div class="nav-previous">' . get_next_posts_link( __( '<span class="meta-nav">>></span> Next' ) ) . '</div>'
. '<div class="nav-next">' . get_previous_posts_link( __( '<span class="meta-nav"><<</span> Previous' ) ) . '</div></div></div>'.

wp_reset_query();
}

add_shortcode( 'recipesgrid', 'link_recipesgrid' );

0 个答案:

没有答案