【问题标题】:How to amend Plugin code to output a CSS class如何修改插件代码以输出 CSS 类
【发布时间】: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


    【解决方案1】:

    通常,您不应修改插件代码。此外,您使用的代码不是理想的方式。我们必须使用Wp_query

    你可以改变:

    return $WPCPC->getPostCount($atts);
    
    to 
    
    return '<span class="postcount">'.$WPCPC->getPostCount($atts).'</span>';
    

    然后你可以在你的 CSS 中使用.postcount

    【讨论】:

      猜你喜欢
      • 2018-04-28
      • 2016-01-22
      • 2017-12-21
      • 2017-12-13
      • 2023-02-08
      • 2022-08-07
      • 1970-01-01
      • 1970-01-01
      • 2019-07-12
      相关资源
      最近更新 更多