我需要将此产品类别页面的布局更改为 4 列。
我希望它看起来像这个。
该网站在wordpress上,该主题的支持人员说我需要在下面编辑该代码。
所有的帮助将不胜感激,谢谢!
<?php
if( ! function_exists("rt_product_categories_shortcode") ){
/**
* Product Categories
* @param array $atts
* @param string $content
* @return output
*/
function rt_product_categories_shortcode( $atts = array(), $content = null ) {
global $rt_list_atts, $rt_category;
//defaults
$rt_list_atts = shortcode_atts( array(
"id" => '',
"class" => '',
"ids" => '',
"list_layout" => "1/3",
"display_titles" => "true",
"display_descriptions" => "true",
"display_thumbnails" => "true",
"image_max_height" => '',
"crop" => '',
'orderby' => 'name',
"order" => "ACS",
'parent' => 0,
'layout_style' => ''
), $atts );
extract( $rt_list_atts );
ob_start();
// Product Categories
$product_args = array(
'type' => 'post',
'orderby' => $orderby,
'order' => $order,
'hide_empty' => 0,
'hierarchical' => 1,
'taxonomy' => 'product_categories',
'pad_counts' => true,
'include' => $ids,
'parent' => empty( $parent ) ? 0 : $parent
);
$product_categories = get_categories($product_args);
//fix true false
$rt_list_atts["display_titles"] = ! empty( $display_titles ) && $display_titles !== "false" ? "true" : "false";
$rt_list_atts["display_descriptions"] = ! empty( $display_descriptions ) && $display_descriptions !== "false" ? "true" : "false";
$rt_list_atts["display_thumbnails"] = ! empty( $display_thumbnails ) && $display_thumbnails !== "false" ? "true" : "false";
$rt_list_atts["crop"] = ! empty( $crop ) && $crop !== "false" ? "true" : $crop;
//id attr
$id = ! empty( $id ) ? 'id="'.sanitize_html_class($id).'"' : "";
//item width percentage
$list_layout = ! empty( $list_layout ) ? $list_layout : "1/3";
//column count
$column_count = rt_column_count( $list_layout );
//category count
$post_count = count( $product_categories );
//layout style
$add_holder_class = $list_layout == "1/1" ? "" : ( $layout_style == "grid" ? " border_grid fixed_heights" : " masonry" ) ;
$add_holder_class .= " ".sanitize_html_class( $class );
//column class
$add_column_class = "product_item_holder ";
$add_column_class .= rt_column_class( $list_layout );
$add_column_class .= $layout_style == "masonry" ? " isotope-item" : "";
//open the wrapper
echo "'n".'<div '.$id.' class="product_holder product-showcase product-showcase-categories clearfix '.trim($add_holder_class).'" data-column-width="'. $column_count .'" >'."'n";
$counter = 1;
foreach ($product_categories as $key => $category ) {
$rt_category = $category;
//open row block
if( $layout_style != "masonry" && $list_layout != "1/1" && ( $counter % $column_count == 1 || $column_count == 1 ) ){
echo '<div class="row clearfix">'."'n";
}
echo $list_layout != "1/1" ? '<div class="col '.$add_column_class.'">'."'n" : "";
get_template_part( 'product-contents/category-shortcode-content');
echo $list_layout != "1/1" ? '</div>'."'n" : "";
//close row block
if( $layout_style != "masonry" && $list_layout != "1/1" && ( $counter % $column_count == 0 || $post_count == $counter ) ){
echo '</div>'."'n";
}
$counter++;
}
echo '</div>';
$output_string = ob_get_contents();
ob_end_clean();
return $output_string;
}
}
add_shortcode('rt_product_categories', 'rt_product_categories_shortcode');
类别-短代码-内容.php:
<?php
/**
* The template for displaying product categories within loops.
*
* @author RT-Themes
*
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $rt_list_atts, $rt_category;
extract( $rt_list_atts );
$tax_meta = get_option( "taxonomy_$rt_category->term_id" );
$cat_image_id = is_array( $tax_meta ) && isset( $tax_meta["product_category_image"] ) && ! empty( $tax_meta["product_category_image"] ) ? $tax_meta["product_category_image"] : "";
$cat_image_url = "";
if( $cat_image_id ){
$get_cat_image = wp_get_attachment_image_src( $cat_image_id );
$cat_image_url = is_array( $get_cat_image ) ? $get_cat_image[0] : "";
}
//image max height
$h = $crop == "true" ? $image_max_height : 10000;
//Thumbnail dimensions
$w = rt_get_min_resize_size( $list_layout );
// Resize Image
$image_output = get_resized_image_output( array( "image_url" => $cat_image_url , "image_id" => "", "w" => $w, "h" => $h, "crop" => $crop ) );
?>
<div class="product_item_holder product-showcase-category">
<?php if( ! empty( $image_output ) && $display_thumbnails == "true" ):?>
<!-- product image -->
<div class="featured_image">
<a href="<?php echo get_term_link( $rt_category ); ?>" title="<?php echo $rt_category->cat_name; ?>" rel="bookmark"><?php echo $image_output;?>
<?php if( $display_titles != "true" && $display_descriptions != "true" ) : ?><span class="category-name"><?php echo $rt_category->cat_name;?> (<?php echo $rt_category->count ?>)</span></a><?php endif;?>
</div>
<?php endif;?>
<?php if( $display_titles == "true" || $display_descriptions == "true" ) : ?>
<div class="product_info">
<?php if( $display_titles == "true" ) : ?>
<!-- title-->
<h5 class="clean_heading"><a href="<?php echo get_term_link( $rt_category ); ?>" title="<?php echo $rt_category->cat_name ?>" rel="bookmark"><?php echo $rt_category->cat_name ?><span><?php echo $rt_category->count ?></span></a></h5>
<?php endif;?>
<!-- text-->
<?php echo ! empty( $rt_category->description ) && $display_descriptions == "true" ? sprintf( '<p>%s</p>', $rt_category->description ) : "" ; ?>
</div>
<?php endif;?>
</div>
在调用此简码rt_product_categories
的位置,您可以在其中粘贴参数。
在参数列表中
$rt_list_atts = shortcode_atts( array(
"id" => '',
"class" => '',
"ids" => '',
"list_layout" => "1/3",
"display_titles" => "true",
"display_descriptions" => "true",
"display_thumbnails" => "true",
"image_max_height" => '',
"crop" => '',
'orderby' => 'name',
"order" => "ACS",
'parent' => 0,
'layout_style' => ''
), $atts );
此行"list_layout" => "1/3",
控制主题页面中将打印的列数。因此,如果您知道在哪里调用 scortcode rt_product_categories
就可以使用它,为此属性传递不同的值。
如果您不知道这是hapend的位置,则可以对更改此行的列号进行硬编码
$column_count = rt_column_count( $list_layout );
自
$column_count = 4;
我认为这也可以解决问题。