即将发布的WordPress博客预览可提高用户参与度

tech2022-12-06  94

WordPress started out as a blogging platform and has historically offered a range of tools and features to enhance your site, providing your users with easy ways to access your content.

WordPress最初是一个博客平台,过去一直提供各种工具和功能来增强您的网站,从而为用户提供访问内容的简便方法。

Your latest posts page (aka your latest articles or blogs page) once set up will let your users easily see all of your most recently published blogs.

设置完您的最新帖子页面(也就是您的最新文章或博客页面)后,您的用户就可以轻松查看您最近发布的所有博客。

Wouldn’t it be great if you could show your users a preview of some of your upcoming articles? Well we can build this in and that is what we’re going to look at today and how it can be used to improve your user engagement.

如果您可以向用户显示即将发布的一些文章的预览,那不是很好吗? 好吧,我们可以将其内置,这就是我们今天要探讨的内容,以及如何将其用于改善用户参与度。

建立未来的职位 (Creating Future Posts)

WordPress already comes with a really great utility for scheduling your posts to go live in the future feature known as the post scheduler. The scheduler lets you choose the date and time that your upcoming blog will go live.

WordPress已经提供了一个非常强大的实用程序,用于计划您的帖子在以后称为“ post scheduler的未来功能中上线。 通过计划程序,您可以选择即将发布的博客上线的日期和时间。

Given that WordPress already provides a way to automatically publish your upcoming articles, what we need to do is output a listing of upcoming scheduled posts that your readers can get a sample of to entice them to come back later.

鉴于WordPress已经提供了一种自动发布您即将发布的文章的方法,我们需要做的是输出即将发布的计划发布的列表,您的读者可以从中获得样本,以吸引他们稍后回来。

即将进行的博客预览与用户互动 (User Engagement with Upcoming Blog Preview)

Creating a post preview might seem simple but the overall point is to provide something different to your viewers experience.

创建帖子预览似乎很简单,但总的来说是要提供与观众体验不同的内容。

If your readers are able to see that you have an upcoming article and when it will be published they are more likely to engage with you and hopefully become solid regular traffic for your site.

如果您的读者能够看到您有一篇即将发表的文章,并且该文章何时发表,他们更有可能与您互动,并希望成为您网站的稳定常规访问量。

The example that we will be creating today shows an upcoming post preview and a simple action to get in contact, however you could extend this so that users are prompted to sign up to your newsletter or another type of traceable engagement.

我们今天将创建的示例显示了即将发布的帖子预览和一个简单的联系方式,但是您可以扩展此范围,以便提示用户注册您的新闻通讯或其他类型的可跟踪参与。

您需要知道什么 (What You Will Need to Know)

You should have a basic understanding of WordPress, Plugins Development and Object Oriented Design if you want to make the most of this lesson, we won’t be doing anything overly complicated however. If you’re keen on brushing up on your fundamentals, check out Object Orientated Development with WordPress.

如果您想充分利用本课程,则应该对WordPress,插件开发和面向对象设计有基本的了解,但是我们不会做任何过于复杂的事情。 如果您热衷于基础知识,请查看WordPress面向对象开发 。

将其开发为儿童主题功能还是插件? (Developing This as a Child Theme Function or a Plugin?)

Since we want to extend the way in which our site functions the first thought should be “lets make it a plugin!”. However since we are trying to extend the way in which our news feed works we are limited in what we can achieve using just actions and filters alone. That being the case we could define everything in our child theme; however that has it’s own drawbacks also, one of which is if we ever want to change the theme we will lose our functionality.

由于我们想扩展站点功能的方式,因此首先想到的应该是“让它成为插件!”。 但是,由于我们试图扩展新闻提要的工作方式,因此仅使用动作和过滤器就无法实现目标。 在这种情况下,我们可以在子主题中定义所有内容; 但是,这也有其自身的缺点,其中之一就是如果我们想要更改主题,我们将失去功能。

What we need to do is to use a hybrid approach where we create a plugin that defines all of our functionality using hooks and filters and then use shortcodes, widgets and display functions to handle the output of the upcoming previews in exactly the places we need (i.e on our blog archive page before our main list of articles).

我们需要做的是使用一种混合方法 ,即创建一个使用钩子和过滤器定义我们所有功能的插件,然后使用短代码 , 小部件和显示功能在我们需要的确切位置处理即将到来的预览的输出(即在我们的主要文章列表之前的博客存档页面上)。

While this is generally frowned upon (you should either add all your functionality to a plugin or to a theme), it’s one the more rare edge cases where we just don’t have the hooks or ability to output our plugin’s functionality in the right location so we need to modify our child theme to make it perfect.

尽管通常对此不屑一顾(您应该将所有功能都添加到插件或主题中),但这是最罕见的情况,其中我们只是没有挂钩或能力在正确的位置输出我们的插件功能因此我们需要修改子主题以使其完美。

哪个模板将显示我的博客? (Which Template Will Be Displaying My Blogs?)

This can be tricky to determine as WordPress can show your blog archive listing using several templates files.

由于WordPress可以使用多个模板文件显示您的博客档案列表,因此很难确定。

How your blog listing will be displayed will be dependent on what you have set for your ‘Reading Settings’ and also the design of your theme.

博客列表的显示方式取决于您为“阅读设置”设置的内容以及主题的设计。

Your website will most likely be displaying your posts archive using one your theme’s templates.

您的网站很可能会使用主题模板之一来显示帖子存档。

Depending on how you have your Reading Settings set up will determine which template gets used.

根据您的阅读设置方式 ,将确定使用哪个模板。

font-page.php

font-page.php

This template is used to display your blogs when you have set your front page reading settings to be Your latest posts. If you choose to use A static page and set it up that way you will use a different template for your blog listing.

当您将首页阅读设置设置为您的最新帖子时,此模板用于显示您的博客。 如果您选择使用静态页面并以这种方式进行设置,则将为博客列表使用其他模板。

This template has the highest priority

此模板具有最高优先级

home.php

home.php

This template will be shown when you have your reading settings to be either Your latest posts OR when you have selected A static page and are viewing the page assigned to be your Posts page.

当您将阅读设置设为最新帖子或选择静态页面并正在查看分配为帖子页面的页面时,将显示此模板。

Overall it will be shown only when you are viewing your blog archive page.

总体而言,它仅在您查看博客存档页面时显示。

index.php

index.php

This template will be shown when you have your reading settings to either Your latest posts or A static page and are currently viewing your posts page.

当您将阅读设置设置为“ 最新帖子”或“静态页面”并且当前正在查看帖子页面时,将显示此模板。

This will only be used when nothing else more applicable such as front-page.php or home.php is available in your theme and is used as the default template

仅当主题中没有其他更适用的内容(例如front-page.php或home.php )用作默认模板时,才使用此选项。

开发我们的插件-让我们开始吧! (Developing Our Plugin – Let’s Get to It!)

成品 (The Finished Product)

When you’re finished you will have something similar to what you see below.

完成后,您将看到与下面类似的内容。

The post preview shows you a sample of your next upcoming article, displaying the title, quick summary except along with information about when it will be published.

文章预览为您显示了下一篇文章的样本,显示了标题,快速摘要,以及有关何时发布的信息。

This post contrasts against your other recently published articles, showcasing your upcoming post with preview text and also an interactive author profile (so that users can see who you are and what other posts you have created).

这篇文章与您最近发表的其他文章形成对比,它以预览文本和交互式作者个人资料展示了您即将发布的文章(以便用户可以看到您是谁以及您创建了哪些其他文章)。

The look and feel will be dependent on your theme, however since everything has its own class you can easily style this to match your needs.

外观将取决于您的主题,但是由于所有内容都有其自己的类,因此您可以轻松地对此样式进行设置以满足您的需求。

获取源代码并将其复制到您的服务器 (Get the Source Code and Copy It to Your Server)

Lets start by downloading the source code for the plugin from the SitePoint GitHub repository.

首先,从SitePoint GitHub存储库下载插件的源代码。

The code will be contained inside of a single folder with several sub-directories for the CSS and JS elements. It should look similar to below.

该代码将包含在一个文件夹内,该文件夹包含CSS和JS元素的多个子目录。 它看起来应与下面类似。

Copy the plugin to your plugins directory and activate it. Once you have this activated you will be ready to go!

将插件复制到您的plugins目录并激活它。 激活此功能后,您就可以开始使用!

看重点 (Looking at the Highlights)

For the sake of simplicity I will outline the most important and interesting elements of the plugin in the next few sections. This should be enough help you understand how it all works.

为了简单起见,我将在接下来的几节中概述该插件最重要和最有趣的元素。 这应该足以帮助您了解所有工作原理。

If you are interested you should look through everything and possibly extend it to suit your own purposes.

如果您有兴趣,则应仔细阅读所有内容,并可能对其进行扩展以适合自己的目的。

构建管理界面 (Building the Admin Interface)

Since we want to extend the way in which blog posts work we will be modifying the add / edit post admin screen to provide additional options.

由于我们想扩展博客文章的工作方式,因此我们将修改添加/编辑文章管理屏幕以提供其他选项。

Your screen should look fairly unchanged except for the ‘Publish’ meta box displayed generally on the far right hand corner of your screen.

除了通常在屏幕最右端显示的“发布”元框外,您的屏幕看上去应该保持不变。

Just below the ‘Schedule For’ options you will see a new section called ‘Upcoming Preview’. This section will let you decide on a post by post basis if your scheduled post will have an upcoming preview.

在“计划”选项的下方,您将看到一个名为“即将预览”的新部分。 本部分将使您可以逐个帖子地决定预定的帖子是否即将发布。

If you want a post preview you simply select the enable option and you will get two additional options.

如果要发布预览,只需选择启用选项,您将获得两个附加选项。

显示带有“更多”标签的内容 (Display Content with the ‘More’ Tag)

Using this option will mean that when your preview is being displayed on the front-end of your website it will display ALL of your content on the front end up until it finds WordPress’s ‘Read More’ button.

使用此选项将意味着,当预览显示在网站的前端时,它将在前端显示所有内容,直到找到WordPress的“阅读更多”按钮。

In this example when displayed the post preview will show the image and the text up until the ‘MORE’ tag has been reached.

在此示例中,显示后发布预览时将显示图像和文本,直到到达“更多”标签为止。

显示最多X个单词的内容 (Displaying Content up to X Number of Words)

Using this option you will be able to determine how many ‘words’ are displayed from your posts content area. This means that you can display as many or as few words as you like to be displayed on the front end.

使用此选项,您将可以确定帖子内容区域中显示多少个“单词” 。 这意味着您可以根据需要显示任意多或少的单词。

The only real drawback from this approach is that since the content is trimmed to a set length any images or visual content you use will be stripped out (only your content will be pulled through).

这种方法的唯一真正的缺点是,由于将内容修剪为设定的长度,因此您使用的所有图像或视觉内容都将被剥离(仅内容会被拉出)。

In this example when used as a preview the post will show exactly 25 words and then finish with an ellipses / the call to action for the user.

在此示例中,用作预览时,帖子将准确显示25个字,然后以省略号/用户号召性用语结束。

Inside of the upcoming_posts_preview.php file look for the magic __construct function. Inside here we have hooked onto the post_submitbox_misc_actions hook which is used to output additional code just after the Schedule For options for each post.

在upcoming_posts_preview.php的__construct文件中,查找神奇的__construct函数。 在这里,我们已经钩住了post_submitbox_misc_actions钩子,该钩子用于在每个帖子的Schedule For选项之后输出其他代码。

We attach our function calledadd_post_preview_meta_options so that we can output our options for enabling / disabling the post previews (and settings such as choosing to display up to the read more link or via trimmed words).

我们附加了名为add_post_preview_meta_options的函数,以便我们可以输出用于启用/禁用帖子预览的选项(以及诸如选择最多显示更多链接或通过修饰词显示的设置)的选项。

Firstly we only want to execute if we are on the post post type which is why we declare the global $post_type.

首先,我们只想在post post类型上执行,这就是为什么我们声明全局$post_type 。

global $post, $post_type; //determine if we are on a post if('post' == $post_type){ }

When we are on a post we will collect our main options. These variables will be used to determine if this post will have its post preview enabled or disabled. If enabled it also determines the type of method that will be chosen (showing content up to the ‘more’ button or showing X number of words). We use ternary operators so that we can check if our post has any previous set values and if so assign them accordingly (if not we default to false or an empty string).

当我们发表文章时,我们将收集我们的主要选择。 这些变量将用于确定该帖子是启用还是禁用其帖子预览。 如果启用,它还会确定将要选择的方法的类型(显示内容直至“更多”按钮或显示X个单词)。 我们使用三元运算符,以便我们可以检查帖子中是否有以前的设置值,如果有的话,则进行相应的分配(如果没有,则默认为false或空字符串)。

//determine if we have enabled / disabled post previews $upcoming_preview_status = ( get_post_meta( $post->ID, 'upcoming_preview_status', true) ? get_post_meta( $post->ID, 'upcoming_preview_status', true) : 'false' ); //determines the type of post preview $upcoming_preview_type = ( get_post_meta( $post->ID, 'upcoming_preview_type', true) ? get_post_meta( $post->ID, 'upcoming_preview_type', true) : 'false' ); //determines the number of words shown per post preview (if we are displaying a trimmed excerpt) $upcoming_preview_type_x_words = ( get_post_meta( $post->ID, 'upcoming_preview_x_words_number', true) ? get_post_meta( $post->ID, 'upcoming_preview_x_words_number', true) : '' );

We define radio buttons for the post that let the user enable or disable the upcoming post preview. We build these like any other form elements by supplying a name and id for these elements and determining which button should be checked (the values we collect before ensure we can default check the correct elements).

我们为帖子定义单选按钮,使用户可以启用或禁用即将发布的帖子预览。 通过为这些元素提供name和id并确定应检查哪个按钮(我们在确保可以默认检查正确的元素之前收集的值),可以像构建其他表单元素一样构建这些元素。

After these basic radio buttons are defined we define a secondary set that are only displayed once we select to Enable upcoming preview, this will determine the type of upcoming post preview we will be executing. It will be either:

在定义了这些基本单选按钮之后,我们定义了一个次要集合,仅在选择“ 启用即将预览”时才显示该次要集合,这将确定我们将执行的即将发布的预览的类型 。 它将是:

Show post preview up to the ‘more’ tag

显示帖子预览直至“更多”标签 Show X number of words

显示X个字

If we select that we want to Show X number of words another set of information is displayed, this time it shows a number field where we can select the number of words we want to display.

如果选择要显示X个单词 ,则会显示另一组信息,这一次它将显示一个数字字段,我们可以在其中选择要显示的单词数量。

管理界面互动 (Admin Interface Interactivity)

To make the plugin easy to use and to mimic how WordPress designs their admin interface, there is a small amount of jQuery used by the plugin.

为了使插件易于使用并模仿WordPress设计其管理界面的方式,插件使用了少量的jQuery。

Our JS script called upcoming_posts_preview_admin_scripts.js is loaded onto on the admin side of WordPress and is used to make interacting with our plugin easier.

我们的JS脚本upcoming_posts_preview_admin_scripts.js已加载到WordPress的管理端,并用于简化与插件的交互。

Our first main interactivity is one used for the toggling of the ‘enabled’ / ‘disabled’ states for the post preview. We slide the container of secondary options up or down depending on what we have chosen.

我们的第一个主要交互是用于预览发布的“已启用” / “已禁用”状态。 我们根据选择的内容上下滑动辅助选项的容器。

//toggles the main enabled / disabled function upcoming_post_preview_toggle_display(){ //get current state, if we have enabled it, slide down else slide up chosen_preview_status = preview_status.filter(':checked').val(); //if we have chosen a post preview if(chosen_preview_status == 'true'){ preview_content_settings.slideDown('fast'); } //else we didn't choose a post preview else if(chosen_preview_status == 'false'){ preview_content_settings.slideUp('fast'); //reset the X number of characters to display preview_x_number_of_items.val(''); } } upcoming_post_preview_toggle_display();

We run this function just as we load and also attach it to the radio buttons so when we change our state we can update what happens.

我们在加载时就运行此函数,并将其附加到单选按钮上,以便在更改状态时可以更新发生的情况。

//when we change status, toggle container accordingly preview_status.on('click', upcoming_post_preview_toggle_display);

Our secondary helper function is used when we have chosen to enable a post preview. If we determine we want to show X number of words then we need to slide down an additional field which is the ‘number of words’ that will be used.

当我们选择启用帖子预览时,将使用我们的辅助帮助程序功能。 如果我们确定要显示X个单词,则需要向下滑动一个附加字段,即将使用的“单词数量” 。

//Toggling the main settings (display up to more tag or X number of words) function upcoming_post_preview_setting_display(){ //get the currently chosen option setting var chosen_preview_type = preview_types.filter(':checked').val(); //if we chose to display content up to the 'more' tag if(chosen_preview_type == 'upcoming_preview_more_tag'){ preview_content_sub_settings.slideUp('fast'); preview_x_number_of_items.removeAttr('required'); } //if we chose to display X number of words else if(chosen_preview_type == 'upcoming_preview_x_words'){ preview_content_sub_settings.slideDown('fast'); //set the number of words field to have the 'required' attribute preview_x_number_of_items.attr('required','required'); } } upcoming_post_preview_setting_display();

This function happens right when we load and also when we change our status type.

此功能在加载时以及更改状态类型时发生。

//when we choose our type of upcoming preview that will be displayed, toggle additional options if required preview_types.on('click', upcoming_post_preview_setting_display);

建立即将发布的帖子预览HTML (Building Your Upcoming Post Preview HTML)

Before your post preview is displayed it first has to be built. We use a function called get_upcoming_post_preview to do this.

在显示帖子预览之前,必须先构建它。 我们使用名为get_upcoming_post_preview的函数来执行此操作。

This function takes in an optional set of arguments and is used to fetch your most recent upcoming scheduled post.

此函数接受一组可选参数,用于获取您最近的即将安排的帖子。

The function defines its default arguments. These will be used in our main query shortly so that the website knows which posts to pull and how many.

该函数定义其默认参数。 这些将很快在我们的主要查询中使用,以便网站知道要拉哪些帖子以及多少帖子。

$arguments = array( 'number_of_previews' => 1, 'post_id' => false );

If we passed in any optional arguments we check to see if they exist in our arguments array (our defaults). If they do exists we update them (as we are overriding the default functionality).

如果传入任何可选参数,我们将检查它们是否存在于参数数组中(我们的默认值)。 如果确实存在,我们将对其进行更新(因为我们将覆盖默认功能)。

//If we passed in arguments, copy new arguments if($optional_arguments){ foreach($optional_arguments as $key => $value){ if(array_key_exists($key, $arguments)){ $arguments[$key] = $value; } } }

Now that we have our basic arguments ready we call the get_posts function and pass in a list of arguments to determine what posts will be collected. Some of our arguments will be able to determine how this function operates.

现在我们已经准备好基本参数,我们将调用get_posts函数并传递参数列表以确定将收集哪些帖子。 我们的某些论点将能够确定此函数的运行方式。

//main query to find posts $post_args = array( 'post_type' => 'post', 'post_status' => 'future', 'orderby' => 'post_date', 'order' => 'ASC', 'posts_per_page' => $arguments['number_of_previews'], 'include' => $arguments['post_id'], 'meta_key' => 'upcoming_preview_status', 'meta_value' => 'true' ); $posts = get_posts($post_args);

What important is that we are setting the meta_key value to be upcoming_preview_status and ensuring that its meta_value is true. This will restrict the search to only posts that have been enabled in the back-end of the website.

什么重要的是,我们正在设置meta_key值为upcoming_preview_status并确保其meta_value是true 。 这会将搜索限制为仅在网站后端enabled帖子。

For each of the upcoming previews we collect a heap of information from our post and also the post author so we can format an interesting design. Many of these elements won’t be displayed if there is no information (for example an author description or additional author posts).

对于即将发布的每个预览,我们都会从帖子以及帖子作者那里收集大量信息,以便我们格式化有趣的设计。 如果没有信息(例如,作者描述或其他作者帖子),则不会显示其中的许多元素。

Feel free to modify the plugin directly if you want to output specific information or you can optionally use the sc_upcoming_post_public_display_start and sc_upcoming_post_public_display_end filters to change up your display.

如果要输出特定信息,可以直接直接修改插件,也可以选择使用sc_upcoming_post_public_display_start和sc_upcoming_post_public_display_end过滤器来更改显示。

When the output has been completed its returned and eventually displayed to the user.

输出完成后,将返回并最终显示给用户。

在前端显示(通过动作挂钩) (Displaying on Your Front End (via an Action Hook))

The main way to display your upcoming post previews is to use the get_upcoming_post_preview hook the plugin supplies.

显示即将发布的帖子预览的主要方法是使用插件提供的get_upcoming_post_preview钩子。

You can call the action using its simple form.

您可以使用简单的形式调用该操作。

//display our latest upcoming post previews do_action('display_upcoming_post_previews');

Or you can use a more complex style where you pass in optional arguments to the action (which will let you customise what previews are displayed).

或者,您可以使用更复杂的样式,在其中将可选参数传递给操作(这将使您可以自定义显示的预览)。

//define arguments to pass to our action $optional_args = array( 'number_of_previews' => 2 ); //display our latest upcoming post previews do_action('display_upcoming_post_previews', $optional_args);

可以传递给我们行动的选择 (Options That Can Be Passed to Our Action)

Currently there are only two options that can be set:

当前只能设置两个选项:

number_of_previews – Determines the number of previews to be displayed (by default 1)

number_of_previews –确定要显示的预览数(默认为1)

post_id – Gets a single preview by its post id

post_id –按其帖子ID获得一个预览

The way this preview displays will be up to your theme and you are free to style it as you like. Here is what it looks like when used in ‘twentythirteen’, ‘twentyfourteen’ and ‘twentyfifteen’ respectively.

该预览显示的方式将取决于您的主题,您可以随意设置其样式。 这是分别在“二十一 十三” , “二十四”和“二十十五”中使用时的样子。

有用的挂钩和过滤器 (Useful Hooks and Filters)

Throughout the plugin I’ve added several helpful actions and filters that can be used to extend the plugin. You can hook into these elements and change default values or output your own code to extend what is possible.

在整个插件中,我添加了一些有用的操作和过滤器 ,可用于扩展插件。 您可以加入这些元素并更改默认值,或者输出自己的代码以扩展可能的范围。

Here are the hooks that you can use

这是您可以使用的挂钩

sc_upcoming_post_link_action

sc_upcoming_post_link_action

Used to change the link that the read more button will go to. By default it will create a mailto: link with the site administrators email address. You can use this to maybe send all actions to a specific page.

用于更改“更多”按钮将转到的link 。 默认情况下,它将创建一个mailto:链接,并带有站点管理员的电子邮件地址。 您可以使用它来将所有操作发送到特定页面。

sc_upcoming_post_link_action

sc_upcoming_post_link_action

sc_upcoming_post_link_text

sc_upcoming_post_link_text

Used to define the text that is displayed on the read more button. By default it says ‘Get in contact and we will update you when this post is published!’. You could set this to be any text you want

用于定义在“更多阅读”按钮上显示的text 。 默认情况下,它显示为“联系我们,我们将在发布此信息时为您更新!”。 您可以将其设置为您想要的任何文本

sc_upcoming_post_admin_form_start

sc_upcoming_post_admin_form_start

Displayed after the main ‘enable’ / ‘disable’ options for the post preview. This hook is displayed once you select ‘enable’ and will let you define any other additional options you might want to save.

在帖子预览的主要“启用” /“禁用”选项之后显示。 一旦选择“启用”,该钩子就会显示出来,并允许您定义其他可能要保存的其他选项。

sc_upcoming_post_admin_form_end

sc_upcoming_post_admin_form_end

Displayed after the ‘enable’ / ‘disable’ option for the post preview. This hook is displayed at the end of the form once you select to ‘enable’ the post preview. You can use this to save additional information

在帖子预览的“启用” /“禁用”选项之后显示。 一旦选择“启用”帖子预览,该钩子就会显示在表单的末尾。 您可以使用它来保存其他信息

sc_upcoming_post_admin_form_end

sc_upcoming_post_admin_form_end

sc_upcoming_post_admin_save

sc_upcoming_post_admin_save

This action is called during our save process for the post. This is triggered once we have successfully started to save and can be used to receive newly added meta fields added by either the sc_upcoming_post_admin_form_start or sc_upcoming_post_admin_form_end hooks.

在我们save帖子的过程中将调用此操作。 一旦我们成功开始保存,就会触发此操作,并且可以用来接收由sc_upcoming_post_admin_form_start或sc_upcoming_post_admin_form_end挂钩添加的新添加的元字段。

sc_upcoming_post_public_display_start

sc_upcoming_post_public_display_start

Defined just after the start of the upcoming post preview output. Used so that additional HTML or data can be outputted at the beginning of each post preview (for example to add some new info or styles)

在即将发布的帖子预览输出开始后定义。 用于使其他HTML或数据可以在每个帖子预览的开始处输出(例如,添加一些新的信息或样式)

sc_upcoming_post_public_display_end

sc_upcoming_post_public_display_end

defined just at the end of the upcoming preview output. Used so additional HTML or data can be outputted at the end of each post preview.

在即将到来的预览输出的末尾定义。 使用它,以便可以在每个帖子预览的末尾输出其他HTML或数据。

sc_upcoming_post_public_display_end

sc_upcoming_post_public_display_end

display_upcoming_post_previews

display_upcoming_post_previews

Our main display hook, used so that when called from the front-end the post previews will be shown. You can pass in a few options to change your output

我们的主显示挂钩,用于从前端调用时将显示帖子预览。 您可以传递一些选项来更改输出

display_upcoming_post_previews

display_upcoming_post_previews

在前端显示(通过简单的简码) (Displaying on Your Front End (via a Simple Shortcode))

Besides using the action hook, you can also use a handy shortcode that you can use to output your post previews on any page.

除了使用动作挂钩之外,您还可以使用方便的短代码,以便在任何页面上输出帖子预览。

You can use its simple form as below

您可以使用以下简单形式

//displays your upcoming post preview [upcoming_post_preview]

The shortcode is basically a wrapper for our main output function so it supports the same attributes as when calling it from our display_upcoming_post_previews action. You can pass in these options:

简码基本上是我们主要输出函数的包装,因此它支持与从display_upcoming_post_previews操作调用时相同的属性。 您可以传递以下选项:

number_of_previews – Determines the number of previews to be displayed (by default 1)

number_of_previews –确定要显示的预览数(默认为1)

post_id – Gets a single preview by its post id

post_id –按其帖子ID获得一个预览

If you wanted to display only a single upcoming post preview and know it’s ID you can output it on your page by using the following.

如果您只想显示一个即将发布的帖子预览并且知道它的ID,则可以使用以下内容将其输出到页面上。

//displays the upcoming post with the ID of 425 [upcoming_post_preview post_id="425"]

从这里到哪里? (Where to from Here?)

Now that you have an overview of how the plugin works and how you can use it to increase your viewers engagement with your site, you could extend this plugin and provide additional awesome features.

既然您已大致了解了该插件的工作方式以及如何使用它来增加观众对您网站的参与度,那么您可以扩展此插件并提供其他很棒的功能。

It’s up to you what you might like to do but here are a few things you might want to look into.

这取决于您自己想做什么,但是您可能需要考虑以下几件事。

Creating a simple Widget that can be used to display your upcoming post previews in your sidebar.

创建一个简单的Widget ,可用于在边栏中显示即将发布的帖子预览。

Extend the options that are available when you ‘enable’ the post preview. Maybe determine what exact options will be displayed such as hiding the author bio, gravatar image, links to other posts etc

扩展“启用”帖子预览时可用的选项。 也许确定要显示的确切选项是什么,例如隐藏作者的简历,头像图像,指向其他帖子的链接等

Extend the way this plugin works so that it also works with pages or custom post types etc

扩展此插件的工作方式,使其也可用于pages或custom post types等

Let me know if you end up using this plugin or use it as a base to build your own awesome plugin!

让我知道您是最终使用此插件还是将其用作构建自己的超赞插件的基础!

翻译自: https://www.sitepoint.com/upcoming-wordpress-blog-previews-increase-user-engagement/

相关资源:jdk-8u281-windows-x64.exe
最新回复(0)