php 面向Enfold和WooCommerce的FacetWP分页
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 面向Enfold和WooCommerce的FacetWP分页相关的知识,希望对你有一定的参考价值。
.yanco-fwp-pagination {
padding-top: 20px !important;
padding-bottom: 20px !important;
}
.facetwp-pager span.dots {
display: none;
}
.pagination {
a.facetwp-page {
color: $color-black-soft;
}
}
nav.pagination {
display: none;
}
<?php
add_action( 'after_setup_theme', 'enfold_woocommerce_child_theme_code' );
function enfold_woocommerce_child_theme_code() {
remove_action( 'woocommerce_after_shop_loop', 'avia_woocommerce_after_shop_loop', 10);
add_action( 'woocommerce_after_shop_loop', 'yanco_avia_woocommerce_after_shop_loop', 10);
add_action( 'woocommerce_after_shop_loop', 'yanco_avia_woocommerce_after_shop_loop', 10);
}
/**
* Facet WP Modifications to Pagination
*/
function custom_facetwp_pager( $output, $params ) {
$output = '';
$page = (int) $params['page'];
$total_pages = (int) $params['total_pages'];
// Only show pagination when > 1 page
if ( 1 < $total_pages ) {
if ( 1 < $page ) {
$output .= '<a class="facetwp-page" data-page="' . ( $page - 1 ) . '">«</a>';
}
if ( 3 < $page ) {
$output .= '<a class="facetwp-page first-page" data-page="1">1</a>';
// $output .= ' <span class="dots">…</span> ';
}
for ( $i = 2; $i > 0; $i-- ) {
if ( 0 < ( $page - $i ) ) {
$output .= '<a class="facetwp-page" data-page="' . ($page - $i) . '">' . ($page - $i) . '</a>';
}
}
// Current page
$output .= '<a class="facetwp-page active" data-page="' . $page . '">' . $page . '</a>';
for ( $i = 1; $i <= 2; $i++ ) {
if ( $total_pages >= ( $page + $i ) ) {
$output .= '<a class="facetwp-page" data-page="' . ($page + $i) . '">' . ($page + $i) . '</a>';
}
}
if ( $total_pages > ( $page + 2 ) ) {
$output .= ' <span class="dots">…</span> ';
$output .= '<a class="facetwp-page last-page" data-page="' . $total_pages . '">' . $total_pages . '</a>';
}
if ( $page < $total_pages ) {
$output .= '<a class="facetwp-page" data-page="' . ( $page + 1 ) . '">»</a>';
}
}
return $output;
}
add_filter( 'facetwp_pager_html', 'custom_facetwp_pager', 10, 2 );
function yanco_facetwp_cache_lifetime( $seconds ) {
return 60*60*6; // one day
}
//add_filter( 'facetwp_cache_lifetime', 'yanco_facetwp_cache_lifetime' );
/**
* Remove Avia pagination on top of Product Archives
* Remove Avia pagination on bottom of Product Archives
*/
add_action( 'woocommerce_before_shop_loop', 'yanco_woocommerce_before_shop_loop', 21);
function yanco_woocommerce_before_shop_loop() {
$current_tax = get_query_var( 'product_cat' );
$term = get_term_by( 'slug', $current_tax, 'product_cat');
$term_meta = get_term_meta($term->term_id, 'display_type', true);
global $avia_config;
$pagination = '';
if( isset($avia_config['dynamic_template']) ) {
return;
}
if( isset($avia_config['overview'] ) ) {
//$pagination = '<div class="pagination">'.do_shortcode('[facetwp pager="true"]').'</div>';
}
switch( $term_meta ) {
case 'products':
case 'both':
case '':
//echo $pagination;
break;
case 'subcategories':
break;
default:
//echo $pagination;
break;
}
return;
}
function yanco_avia_woocommerce_after_shop_loop() {
// global $avia_config;
// if(isset($avia_config['dynamic_template'])) return;
// if(isset($avia_config['overview'] )) echo '<div class="pagination">'.do_shortcode('[facetwp pager="true"]').'</div>';
echo "</div></main>"; //end content
}
<?php
/**
* The Template for displaying product archives, including the main shop page which is a post type archive.
*
* Override this template by copying it to yourtheme/woocommerce/archive-product.php
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
get_header( 'shop' ); ?>
<?php
/**
* woocommerce_before_main_content hook
*
* @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* @hooked woocommerce_breadcrumb - 20
*/
do_action( 'woocommerce_before_main_content' );
?>
<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
<?php endif; ?>
<?php
/**
* woocommerce_archive_description hook
*
* @hooked woocommerce_taxonomy_archive_description - 10
* @hooked woocommerce_product_archive_description - 10
*/
do_action( 'woocommerce_archive_description' );
?>
<?php if ( have_posts() ) : ?>
<?php
/**
* woocommerce_before_shop_loop hook
*
* @hooked woocommerce_result_count - 20
* @hooked woocommerce_catalog_ordering - 30
*/
do_action( 'woocommerce_before_shop_loop' );
?>
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<div class="facetwp-template">
<div class="pagination yanco-fwp-pagination">
<?php echo do_shortcode('[facetwp pager="true"]'); ?>
</div>
<?php while ( have_posts() ) : the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<div class="pagination">
<?php echo do_shortcode('[facetwp pager="true"]'); ?>
</div>
</div>
<?php woocommerce_product_loop_end(); ?>
<?php
/**
* woocommerce_after_shop_loop hook
*
* @hooked woocommerce_pagination - 10
*/
do_action( 'woocommerce_after_shop_loop' );
?>
<?php elseif ( ! woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>
<?php wc_get_template( 'loop/no-products-found.php' ); ?>
<?php endif; ?>
<?php
/**
* woocommerce_after_main_content hook
*
* @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action( 'woocommerce_after_main_content' );
?>
<?php
/**
* woocommerce_sidebar hook
*
* @hooked woocommerce_get_sidebar - 10
*/
do_action( 'woocommerce_sidebar' );
?>
<?php get_footer( 'shop' ); ?>
以上是关于php 面向Enfold和WooCommerce的FacetWP分页的主要内容,如果未能解决你的问题,请参考以下文章
php 修改WooCommerce Shop图片大小#woocommerce #enfold
php Enfold主题 - WooCommerce - 查看所有产品
php Enfold主题 - WooCommerce - 查看所有产品
scss 使用Enfold进行WooCommerce的两列检查