【发布时间】:2022-11-14 03:55:05
【问题描述】:
我正在使用一个插件来显示每个类别的帖子数,但它不输出 CSS 类,所以我无法设置它的样式。
有谁知道我如何修改插件的代码以使其输出 CSS 类?
代码是:
<?php
/*
Plugin Name: Display Category Post Count
Description: This plugin useful for displaying post count for any post/product category (simply use shortcode [get-post-count-wpcpc category="your category name" post_type="post/product/etc"])
Author: Amit Maskare
Version: 1.1
Author URI: #
*/
class WPCPC{
public function getPostCount($atts){
global $wpdb;
extract( shortcode_atts( array (
'cat_name' => $atts['category'],
'post_type' => $atts['post_type'],
), $atts ) );
$get_query = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}terms terms INNER JOIN {$wpdb->prefix}term_relationships terms_rel ON terms.term_id = terms_rel.term_taxonomy_id INNER JOIN {$wpdb->prefix}posts post ON post.ID = terms_rel.object_id WHERE terms.name = '".$cat_name."' AND post.post_status = 'publish' AND post.post_type = '".$post_type."'");
$rowcount = $wpdb->num_rows;
return $rowcount;
}
}
function get_post_count_wpcpc($atts){
$WPCPC = new WPCPC;
return $WPCPC->getPostCount($atts);
}
add_shortcode( 'get-post-count-wpcpc' , 'get_post_count_wpcpc' );
【问题讨论】:
标签: wordpress wordpress-plugin-creation