小工具      在线工具  汉语词典  dos游戏  css  js  c++  java

如何在WordPress主题中显示博客文章元数据

python,java,php,html,linux 额外说明

收录于:23天前

您想了解如何在 WordPress 博客文章中显示文章元数据吗?帖子元数据是关于您的博客帖子的相关信息,例如发布日期、类别、作者姓名等。在本文中,我们将向您展示如何在 WordPress 帖子中显示帖子元数据。

您想了解如何在 WordPress 博客文章中显示文章元数据吗?帖子元数据是关于您的博客帖子的相关信息,例如发布日期、类别、作者姓名等。在本文中,我们将向您展示如何在 WordPress 帖子中显示帖子元数据。

Displaying post meta data in WordPress
什么是WordPress中的发布元数据? What is Post Meta Data in WordPress?

Post meta data is information about a post that is not part of the actual content. This includes information like post date, author, 类别和标签, or custom taxonomies.

帖子元数据是关于帖子的信息,不属于实际内容。 这包括发布日期,作者, 类别和标签或自定义分类法等信息。

Post meta data shown in a WordPress blog post

Depending on your WordPress theme, this information can be displayed on different locations. For example, below post title, 发布内容后, in a sidebar column, and more.

根据您的WordPress主题,此信息可以显示在不同的位置。 例如,在帖子标题下方, 发布内容后 ,在侧栏栏中等等。

This information helps your users learn more about the content they are viewing. If used correctly, post meta data can 增加页面浏览量, improve user experience, and make your site look more professional.

此信息可帮助您的用户更多地了解他们正在查看的内容。 如果使用正确,发布元数据可以增加页面浏览量 ,改善用户体验,并使您的网站看起来更加专业。

不利的一面是,太多的元数据会让您的网站看起来很混乱。

缺点是太多的元数据会使您的网站看起来混乱。

Messy display of post meta data

Depending on your website, you can add or remove information and add 自定义 CSS 样式 to make it more useful.

根据您的网站,您可以添加或删除信息,以及添加自定义 CSS 样式以使其更有用。

让我们看看如何在 WordPress 中显示帖子元数据。

让我们看看如何在 WordPress 中显示帖子元数据。

Note: This article requires basic understanding of how WordPress themes work. You’ll also need to edit WordPress files. If you haven’t done this before, then take a look at our guide on 如何在 WordPress 中复制和粘贴代码.

注意:本文需要对WordPress主题的工作原理有基本的了解。 您还需要编辑WordPress文件。 如果您以前没有做过,请查看我们的指南, 了解如何在 WordPress 中复制和粘贴代码

WordPress主题如何显示帖子元数据? How WordPress Themes Display Post Meta Data?

有多种方法可以显示帖子元数据。有些主题在帖子标题下方有更简单的代码。

有多种方法可以显示帖子元数据。有些主题在帖子标题下方有更简单的代码。


By <?php the_author_posts_link(); ?> on <?php the_time('F jS, Y'); ?>  in <?php the_category(', '); ?> <?php edit_post_link(__('{Edit}'), ''); ?>

此代码仅显示作者姓名、发布日期和类别。

此代码仅显示作者姓名、标题日期和类别。

Other themes may define their own 模板标签, functions, and classes to display post meta data. These functions are then called in the theme files responsible for displaying posts.

其他主题可以定义自己的模板标签 ,功能和类以显示帖子元数据。 然后在负责显示帖子的主题文件中调用这些功能。

通常,您会在主题的index.php、single.php、archive.php 和内容模板中找到发布元数据代码。

通常,您会在主题的index.php、single.php、archive.php 和内容模板中找到帖子元数据代码。

You can 创建一个子主题 to override these theme files. If you are creating your own custom theme, then you can directly add or modify the code in your existing theme files.

您可以创建副主题以覆盖这些主题文件。 如果要创建自己的自定义主题,则可以直接在现有主题文件中添加或修改代码。

让我们看一下如何在 WordPress 中显示不同帖子元数据的一些示例。

让我们看一些如何在 WordPress 中显示不同帖子元数据的示例。

如何在WordPress中显示或隐藏发布日期 How to Display or Hide Post Date in WordPress

要显示帖子的发布日期,您需要将此代码添加到您的主题中。

要显示帖子的发布日期,您需要将此代码添加到您的主题中。


<p>This article was published on: <?php the_time('m/j/y g:i A') ?></p>

Notice the characters inside the_time function. These are called format characters, and they tell PHP how to format the date and time. To learn more, see our article on 如何更改 WordPress 中的日期和时间格式.

注意the_time函数中的字符。 这些称为格式字符,它们告诉PHP如何格式化日期和时间。 要了解更多信息,请参阅有关如何更改 WordPress 中的日期和时间格式文章。

Showing publish date for WordPress posts

Want to remove dates from your WordPress posts? You’ll need to locate the code with the_time or the_date functions in your theme files and delete those lines.

是否要从WordPress帖子中删除日期? 您需要在主题文件中使用the_timethe_date函数查找代码,然后删除这些行。

如何显示WordPress帖子的最后更新日期 How to Display Last Update Date for WordPress Posts

如果您经常更新网站上的旧文章,那么您可能需要显示帖子的最后更新日期。这有助于您的内容看起来新鲜,并吸引那些可能没有读过几年前发表的帖子的读者。

如果您经常更新网站上的旧文章,您可能需要显示帖子的上次更新日期。这有助于使您的内容看起来新鲜并吸引可能没有阅读过几年前发表的帖子的读者。

只需将以下代码添加到要显示上次更新日期的主题文件中:

只需将以下代码添加到要显示上次更新日期的主题文件中:


$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
echo "<p>Last modified on "; 
the_modified_time('F jS, Y'); 
echo " at "; 
the_modified_time(); 
echo "</p> "; 
} 

Showing last updated date for a WordPress post

For alternate methods and more detailed instructions, see our guide on how to 在 WordPress 中显示帖子的最后更新日期.

有关替代方法和更详细的说明,请参阅有关如何在 WordPress 中显示帖子的最后更新日期指南。

如何在WordPress中显示或隐藏作者姓名 How to Show or Hide Author Name in WordPress

To display 作者姓名, you need to add the following code to your theme files.

要显示作者姓名 ,您需要在主题文件中添加以下代码。


<p>This article was written by <?php the_author(); ?></p>

This code uses the_author tag, which only displays author name.

此代码使用the_author标记,该标记仅显示作者姓名。

You can also display author name linked to all posts written by that author. Simply replace the_author tag with the the_author_posts_link:

您还可以显示链接到该作者撰写的所有帖子的作者姓名。 只需将the_author标记替换为the_author_posts_link


<p>View all articles by <?php the_author_posts_link(); ?></p>

Showing author link in WordPress posts

如果您想从主题中删除作者姓名,则需要在主题文件中找到这些标签并将其删除。

如果您想从主题中删除作者姓名,则需要在主题文件中找到这些标签并将其删除。

如何在WordPress帖子中显示或隐藏类别 How to Show or Hide Categories in WordPress Posts

To display 类别, you need to add the following code to your theme files:

要显示类别 ,您需要在主题文件中添加以下代码:


<p>This post was filed under: <?php the_category(', ') ?></p>

此代码将显示以逗号分隔的帖子类别。您可以将逗号替换为要用作类别名称之间分隔符的任何字符。

此代码将显示以逗号分隔的帖子类别。您可以将逗号替换为要用作类别名称之间分隔符的任何字符。

Showing post categories

显示帖子类别的另一种方法是一次显示一个类别。这使您可以更好地控制样式。

显示帖子类别的另一种方法是一次显示一个类别。这使您可以更好地控制样式。

例如,您可以将以下代码添加到 WordPress 主题文件中:

例如,您可以将以下代码添加到 WordPress 主题文件中:


<?php
$categories = get_the_category( $post->ID );
foreach ( $categories as $category ) {
echo '<span class="wpb-category"><a href="' . get_category_link( $category->term_id ) . '">' .  $category->name  . '</a></span>';
}
?>

Now you can use wpb-category class in your 自定义 CSS 样式类别 names.

现在,您可以在自定义CSS使用wpb-category设置类别名称的风格

Want to remove category names from WordPress posts? You’ll need to locate the line with the_category tag in your theme files and delete it.

是否要从WordPress帖子中删除类别名称? 您需要在主题文件中找到带有the_category标记的行并将其删除。

如何在WordPress帖子中显示或隐藏标签 How to Show or Hide Tags in WordPress Posts

要显示帖子标签,您需要将以下代码添加到主题文件中:

要显示帖子标签,您需要将以下代码添加到主题文件中:


<p>Tags: <?php the_tags(); ?></p>

此代码将仅显示与帖子关联的所有标签,并以逗号分隔。您可以将逗号替换为要用作分隔符的任何字符。

此代码将仅显示与帖子相关的所有标签,以逗号分隔。您可以将逗号替换为要用作分隔符的任何字符。

例如,以下代码将显示由斜杠分隔的标签。

例如,以下代码将显示由斜杠分隔的标签。

 <?php the_tags( 'Tags: '/ ', ', '<br />' ); ?>

如您所见,the_tags 函数接受三个参数。

如您所见,the_tags 函数接受三个参数。


the_tags($before, $separator, $after)

您可以使用 before 和 after 参数添加您想要添加的任何文本或 HTML。这允许您添加 CSS 类,稍后您可以使用这些类在 WordPress 中设置标签样式。

您可以使用 before 和 after 参数添加任何您想要的文本或 HTML。这允许您添加稍后可用于在 WordPress 中设置标签样式的 CSS 类。

看一下下面的例子:

看下面的例子:


<?php the_tags('<div class="wpb-tags">Tags: ', '  ', '</div>');

Showing post tags

If you don’t want to display tags before or after each post, then locate the line with the_tags() code and delete it from your theme files.

如果您不想在每个帖子之前或之后显示标签,请找到带有the_tags()代码的行并将其从主题文件中删除。

使用WordPress中的发布元数据做更多事情 Doing More with Post Meta Data in WordPress

到目前为止,我们向您展示了如何显示或隐藏基本的默认帖子元数据项。主题开发人员可以使用相同的基本模板标签以多种不同的方式显示帖子元数据。

到目前为止,我们已经向您展示了如何显示或隐藏基本的默认帖子元数据项。主题开发人员可以使用相同的基本模板标签以多种不同的方式显示帖子元数据。

For example, you can use post meta data to display 作者信息框, or 将发布日期替换为相对日期.

例如,您可以使用发布元数据显示作者信息框 ,或将发布日期替换为相对日期

Want to take it to the next level? Check out 自定义字段, which allow you to add your own meta data to WordPress posts. You can even create 自定义元框 to easily add those custom fields.

是否想将其提升到一个新的水平? 签出自定义字段 ,使您可以将自己的元数据添加到WordPress帖子中。 您甚至可以创建自定义元框来轻松添加这些自定义字段。

目前为止就这样了。

现在就这样。

We hope this article helped you learn how to display post meta data in WordPress. You may also want to see our list of the 最想要的 WordPress 提示、技巧和技巧.

我们希望本文能帮助您学习如何在WordPress中显示帖子元数据。 您可能还想查看我们最想要的 WordPress 提示、技巧和技巧列表

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

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

翻译自: https://www.wpbeginner.com/wp-themes/how-to-display-post-meta-data-in-wordpress-themes/

. . .

相关推荐

额外说明

Android GreenDao的配置与使用

前言: 本文讲述在Eclipse开发Android项目集成GreenDao ORM的教程和代码示例,讲述GreenDao在项目中的部署以及使用GreenDao生成Dao类的示例,最后讲解GreenDao的增删改查的使用,本文讲述的完整项目源码,将在文章末

额外说明

[Java|多线程与高并发]线程池详解

文章目录 1. 线程池简介 2. 创建线程池 3. 工厂模式简介 4. 线程池的使用 5. 实现线程池 6. ThreadPoolExecutor的构造方法讲解 7. 线程池的线程数量,如何确定? 1. 线程池简介 Java线程池是一种用于管理和重用线程

额外说明

解决 :A problem occurred configuring root project ‘demo1‘. > Could not resolve all files for configu

标题 解决 :A problem occurred configuring root project 'demo1'. 摘要 引言 解决问题的步骤和方法 1. 识别问题 2. Java 版本 升级 Java 版本 在 `build.gradle` 中指定

额外说明

【Unity3D鼠标操作】Unity中实现鼠标经过物体时变颜色,离开时恢复

推荐阅读 CSDN主页 GitHub开源地址 Unity3D插件分享 简书地址 我的个人博客 QQ群:1040082875 大家好,我是佛系工程师☆恬静的小魔龙☆,不定时更新Unity开发技巧,觉得有用记得一键三连哦。 一、前言 点击3D物体时变颜色 效

额外说明

【JavaEE】线程安全的集合类

文章目录 前言 多线程环境使用 ArrayList 多线程环境使用队列 多线程环境使用哈希表 1. HashTable 2. ConcurrentHashMap 前言 前面我们学习了很多的Java集合类,像什么ArrayList、Queue、HashTa

额外说明

架构初识之 —— 使用kafka进行商品维度化缓存解决方案

随着分布式,微服务越来越普遍,对开发的要求也在不断的增加,对架构的要求也提出了越来越多的要求,在那些分布式项目中,经常面临的一个问题就是,高效,解耦,举例来说,当一个小型电商网站越来越大的时候,单体架构必然满足不了日益增长的业务需求,就说当众多的流量一起

额外说明

Memcached安装与使用实例

Memcached简介 安装与启动 1.安装Libevent 2.安装memcached libevent安装 安装问题解决 命令端连接与使用 Java连接获取值 Memcached简介 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态

额外说明

安卓学习笔记11:常用布局 - 网格布局

文章目录 零、学习目标 一、网格布局概述 1、布局特点 2、继承关系图 3、常用属性 (1)针对布局的属性 (2)针对子控件的属性 二、案例演示——计算器界面 (一)运行效果 (二)涉及知识点 (三)实现步骤 1、创建安卓应用【GridLayoutCal

额外说明

【前端领域高频笔试面试】—— Ajax相关

目录 1.Ajax 是什么? 如何创建一个Ajax? 2.同步和异步的区别 3.如何解决跨域问题? 4.页面编码和被请求的资源编码如果不一致如何处理? 5.简述ajax 的过程 6.阐述一下异步加载 7.请解释一下JavaScript的同源策略 8.GE

ads via 小工具