“最受欢迎”列表帖子(基于视图数)
我想显示按观看次数排序的最受欢迎帖子列表。
我想在左侧显示小缩略图(帖子中使用的相同图像只是调整大小以适合),在右侧显示摘录。所以格式看起来像:
[#1 Post Title]
[80x80 thumbnail] [excerpt, limit to x chars]
[#2 Post Title]
[80x80 thumbnail] [excerpt, limit to x chars]
[#3 Post Title]
[80x80 thumbnail] [excerpt, limit to x chars]
... up to 5 posts
有可用的插件吗?如果可以通过简单地使用 WordPress 模板标签来实现,我更喜欢使用第三方插件。但对我来说重要的是显示格式,我需要左侧的缩略图。
I'd like to show a list of most popular posts sorted by number of views.
I'd like to show small thumbnails (the same image(s) used in the posts just resized to fit) on left, and excerpt on right. So the formatting would look like:
[#1 Post Title]
[80x80 thumbnail] [excerpt, limit to x chars]
[#2 Post Title]
[80x80 thumbnail] [excerpt, limit to x chars]
[#3 Post Title]
[80x80 thumbnail] [excerpt, limit to x chars]
... up to 5 posts
Is there a plugin available for this? If can be achieved by simply using wordpress template tags, I'd prefer that over a 3rd party plugin. But important to me is display formatting, I need thumbnails on left.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以安装 Wordpress 热门帖子 等插件。
该插件不能完全满足您的要求,但它会在数据库中记录页面浏览量,您可以通过编写如下代码在主题中使用该数据:
You can install a plugin like Wordpress popular posts.
This plugin can't do exactly what you want, but it records pageviews in the database, and you can use that data in your theme by writing code like the following:
如果您想尽可能避免使用第三方插件,这可能会有所帮助。它确实需要插件 - wp-postiews - 但仅存储页面浏览量。完成后,您可以使用下面的代码来完全自定义您显示的内容以及排序方式。我使用它的目的与您大致相同(我想在缩略图滑块中显示最受欢迎的帖子的缩略图)。
现在,假设您想要将帖子显示为列表:
其中函数
popularPostsThumb()
将在下面定义(您可以更改要显示的帖子数量),但将返回以下内容列表元素,位于列表标记内。
现在在您的
functions.php
文件中定义上述函数。在此示例中,它仅输出图像的缩略图 - 但在
标记内您可以更改 HTML 以生成您想要的内容(加上一些 CSS 样式)。您可以轻松提取帖子的摘录 - 我还没有测试过它,但是像
$excerpt= $post->post_excerpt
这样的东西应该可以工作。(有一些“更简洁”的方法来获取缩略图帖子的标题 - 但这样您可以手动编辑的标题)。
希望这有帮助。
If you wanted to avoid a third party plugin as much as possible than this might help. It does require a plug-in - wp-postiews - but only to store the number of page views. Once you've done that you can use the code below to fully customise what you display and how you sort it. I have used it for much the same purpose as you are (I wanted to display the thumbnails of the most popular posts in a thumbnail slider).
Now, lets say you wanted to display your posts as a list:
Where the function
popularPostsThumb()
will be defined below (and you can alter how many posts you want displayed), but will return the content of the list elements, inside the list tags<li></li>
.Now define the above function in your
functions.php
fileIn this example it just outputs the thumbnail of the image - but inside the
<li></li>
tags you can change the HTML to produce what you wanted (plus a some CSS styling). You can easily extract the excerpt of the post - I've not tested it, but something like$excerpt= $post->post_excerpt
should work.(There are 'neater' ways of getting the thumbnail of the post - but this way you can manually edit the title of the<img>
).Hope this helps.
找到了一个完美运行的插件。
Found a plugin that works perfectly.