【问题标题】:Add site visit counter widget programmatically in wordpress在 wordpress 中以编程方式添加站点访问计数器小部件
【发布时间】:2016-03-15 17:37:54
【问题描述】:

我想使用以下代码添加访问计数器小部件

VISITOR No.: <?php the_widget( "ADS-WpSiteCount" ); ?> 

但是什么都没有出现,

我使用的小部件是https://wordpress.org/plugins/ads-wp-site-count/

【问题讨论】:

  • 你试过呼应吗? VISITOR No.: &lt;?php echo the_widget( "ADS-WpSiteCount" ); ?&gt;
  • 我试过了,但没用
  • 然后用单引号 ' 替换双引号 "(这应该不会影响它,但你永远不知道)?
  • 太模糊了,你在哪里添加代码? html 至少出现了吗?
  • 我假设我们可以在模板编辑器中的任何位置添加此代码,但为了回答您的问题,我将其添加到 wordpress 引导模板的 header.php 中

标签: wordpress widget


【解决方案1】:

根据文档the_widget() WordPress Code Reference

参数定义为

$widget
  (string) (Required) The widget's PHP class name (see class-wp-widget.php).

可以在任何 php 文件中找到 PHP 类名。在您的情况下,有一个文件 includes/ads_widgets.php 您可以找到以下代码

class adswsc_clsWidget extends WP_Widget {
...
}

因此你的PHP类名是adswsc_clsWidget,你可以使用下面的代码。

&lt;?php the_widget('adswsc_clsWidget'); ?&gt;

重要提示:ADS-WpSiteCount有一些参数需要传递,否则可能无法正常显示,因此需要将参数作为第二个参数传递给the_widget() 方法

例子:

the_widget('adswsc_clsWidget',array("text"=&gt; "on","block"=&gt; "p"));

将仅显示文本访问者计数

【讨论】:

    猜你喜欢
    • 2012-04-15
    • 2012-07-10
    • 2023-02-03
    • 1970-01-01
    • 1970-01-01
    • 2016-07-10
    • 1970-01-01
    • 1970-01-01
    • 2015-08-23
    相关资源
    最近更新 更多