mailchimp教程_如何在WordPress中显示您的MailChimp订阅者数量

mailchimp教程

Do you want to display your MailChimp subscriber count? Recently one of our users asked us how they can show their MailChimp subscriber count in WordPress. Displaying social proof encourages other users to join your newsletter. In this article, we will show you how to show your MailChimp subscriber count in WordPress.

您要显示您的MailChimp订阅者数量吗? 最近,我们的一位用户问我们如何在WordPress中显示其MailChimp订阅者人数。 显示社交证明会鼓励其他用户加入您的新闻通讯。 在本文中,我们将向您展示如何在WordPress中显示MailChimp订阅者人数。

MailChimp is one of the most beginner friendly email marketing service provider. If you are not already using MailChimp, then check out our guide on using MailChimp with WordPress.

MailChimp是最适合初学者的电子邮件营销服务提供商之一。 如果您尚未使用MailChimp,请查看有关将MailChimp与WordPress结合使用的指南。

We will be showing two different methods to display MailChimp subscribers count. The first method is easier and requires you to install a WordPress plugin. The second method is more advanced where you will need to create a plugin based on different source files. If you are not comfortable with editing code snippets, then we will recommend you to use the first method instead.

我们将展示两种不同的方法来显示MailChimp订阅者人数。 第一种方法比较简单,需要您安装WordPress插件。 第二种方法更高级,您将需要根据不同的源文件创建一个插件。 如果您不喜欢编辑代码段,那么我们建议您改用第一种方法。

方法1:使用MailChimp订阅服务器Chiclet插件 (Method 1: Using MailChimp Subscriber Chiclet Plugin)

First thing you need to do is install and activate the MailChimp Subscriber Chiclet plugin. Upon activation, visit Settings » MailChimp Subscriber Chiclet to configure the plugin.

您需要做的第一件事是安装并激活MailChimp Subscriber Chiclet插件。 激活后,访问设置»MailChimp订户Chiclet来配置插件。

MailChimp Subscriber Chiclet Settings

First you will need to enter your MailChimp API key. If you haven’t created one, then you can login to your MailChimp account dashboard and get one.

首先,您需要输入MailChimp API密钥。 如果尚未创建一个,则可以登录到MailChimp帐户仪表板并获取一个。

Getting API Keys for your MailChimp account

After entering your API key click on the Save Changes button. The plugin will then load your email list from your MailChimp account. Select your email list and configure the plugin settings.

输入API密钥后,单击“保存更改”按钮。 然后,该插件将从您的MailChimp帐户加载您的电子邮件列表。 选择您的电子邮件列表并配置插件设置。

Once you are done, simply copy the shortcode from the bottom of the plugin and add it to any post, page, or text widget where you want to show your subscriber count.

完成后,只需从插件底部复制简码,然后将其添加到要显示订阅者人数的任何帖子,页面或文本小部件即可。

Preview of Mailchimp subscriber chiclet plugin
方法2:使用MailChimp API获取订阅者计数 (Method 2: Getting Subscriber Count Using MailChimp API)

As you would notice that using the plugin method you get your subscriber count with a powered by MailChimp logo. Many users would just want to get the number so that they can use it with their own email signup forms.

正如您会注意到的那样,使用插件方法可以通过MailChimp徽标获得订阅者数量。 许多用户只想获取该号码,以便他们可以将其与自己的电子邮件注册表单一起使用。

In this method we will be creating a plugin. This plugin will use MailChimp’s API to get subscriber count. You will be able to display the subscriber count anywhere you want using a shortcode.

在这种方法中,我们将创建一个插件。 该插件将使用MailChimp的API来获取订户数量。 您将可以使用简码在任意位置显示订户数量。

Step 1: First thing you need to do is to create a folder on your desktop and name it mc-subscriber-count.

步骤1:首先,您需要在桌面上创建一个文件夹,并将其命名为mc-subscriber-count。

Step 2 Inside the folder create a new file and name it mc-subscriber-count.php and paste this code inside it.

步骤2在文件夹中创建一个新文件,并将其命名为mc-subscriber-count.php并将此代码粘贴到其中。

Important: Don’t forget to replace Your_MailChimp_API_Key with your actual MailChimp API Key.

重要提示:不要忘记用实际的MailChimp API密钥替换Your_MailChimp_API_Key。


<?php
/*
Plugin Name: MailChimp Subscriber Count
Plugin URI:  https://www.wpbeginner.com
Description: Retrieves MailChimp subscriber count and displays it as a text
Version:     1.0
Author:      WPBeginner
Author URI:  https://www.wpbeginner.com
 */
 
function wpb_mc_sub_count() {  
include "Mailchimp.php";
$lastRunLog = 'logs/lastrun.log';
$subfile = 'logs/subcount.log';
$lastRun = file_get_contents($lastRunLog);

if (time() - $lastRun >= 86400) {

$MailChimp = new MailChimp('Your_MailChimp_API_Key');
$mc = $MailChimp->call('lists/list');
$subscriber_count .= $mc[data][0][stats][member_count];
file_put_contents($lastRunLog, time());
file_put_contents($subfile, $subscriber_count);

} else {

$subscriber_count .= file_get_contents($subfile);

}

return number_format($subscriber_count);

 } 

add_shortcode('mc-subscribers', 'wpb_mc_sub_count');
add_filter('widget_text', 'do_shortcode'); 

 ?>


Step 3: Inside mc-subscriber-count folder create another folder and name it logs. Inside the logs folder create two blank files using a plain text editor like Notepad. Name one file lastrun.log and the other subcount.log.

步骤3:在mc-subscriber-count文件夹中,创建另一个文件夹并命名为log。 在日志文件夹内,使用纯文本编辑器(如记事本)创建两个空白文件。 将一个文件命名为lastrun.log,将另一个命名为subcount.log。

Creating log files

Step 4: Download the MailChimp PHP Wrapper source code from MailChimp repository. Download link is located at the bottom in the right hand column.

步骤4:MailChimp存储库下载MailChimp PHP Wrapper源代码。 下载链接位于右列的底部。

After downloading, you need to extract the zip file. Inside the extracted folder, you will see a folder src containing Mailchimp.php file and Mailchimp folder.

下载后,您需要解压缩zip文件。 在解压缩的文件夹内,您将看到一个包含Mailchimp.php文件和Mailchimp文件夹的src文件夹。

MailChimp API Files

Step 5: Copy and paste Mailchimp.php file and Mailchimp folder to your plugin folder.

步骤5:复制Mailchimp.php文件和Mailchimp文件夹并将其粘贴到您的插件文件夹中。

Final plugin file structure

Step 6: Upload mc-subscriber-count folder to /wp-content/plugins/ folder on your website using an FTP client.

步骤6:使用FTP客户端将mc-subscriber-count文件夹上传到您网站上的/ wp-content / plugins /文件夹。

Step 7: Visit the Plugins page on your WordPress admin area and activate MailChimp Subscriber Count plugin.

第7步:访问WordPress管理区域上的“插件”页面,然后激活MailChimp订户计数插件。

Step 8: Use shortcode [mc-subscribers] to display MailChimp subscriber count in any post, page, or text widget in WordPress.

步骤8:使用简码[mc-subscribers]在WordPress中的任何帖子,页面或文本小部件中显示MailChimp订阅者计数。

We hope this article helped you show MailChimp subscriber count as text on your WordPress site.

我们希望本文能帮助您在WordPress网站上将MailChimp订阅者数量显示为文本。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-show-your-mailchimp-subscriber-count-in-wordpress/

mailchimp教程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值