wordpress - 在 DIVI 中显示自定义元数据
问题描述
我知道这需要定制,但不知道在哪里编辑。
我使用 ACF(高级自定义字段)创建了一个自定义字段。我希望它显示在我的博客元数据中(而不是在页面上)。DIVI 有作者、日期、评论、评级、类别。
ACF 有一个函数,我可以在其中调用值 $value = get_field("text_field");。我知道它可以添加到子主题 function.php 中,但需要编码方面的帮助。
下面的链接显示了如何将“上次更新”添加到我的元数据中。我需要用自定义字段替换它
编辑:我设法通过编辑我的子主题来实现它,我使用 meta_key 来显示我的自定义类别中的值。我将代码添加到显示元数据的数组中。(模块-posts-content.php)
'meta_key' => $value = the_field('custom_date_or_text'),
最后一个问题是我的自定义字段出现在元字段上方而不是与其对齐。
(来自我的主题的代码)
<?php
$meta_args = array(
'author_link' => $show_author,
'author_link_by' => et_get_safe_localization( __( 'Posted by %s', 'extra' ) ),
'post_date' => $show_date,
'date_format' => $date_format,
'categories' => $show_categories,
'comment_count' => $show_comments,
'rating_stars' => $show_rating,
'meta_key' => $value = the_field('custom_date_or_text'),
);
?>
解决方案
尝试获取 post_meta 以及该帖子/页面模板上的 ID:
<?php $text_field = get_post_meta( get_the_ID(), 'text_field', true); ?>
<p><?php echo esc_html( $text_field );?></p>
推荐阅读
- gulp - Gulp 4手表不工作,只运行一次
- regex - 使用正则表达式提取数据
- react-native - 从一个屏幕导航到另一个屏幕在使用 wix react native navigation V2 时不起作用
- graphql - 运行 apollo-server 时获取节点“错误:找不到模块'core-js/proposals/array-flat-and-flat-map'”
- python - 使用 Panda 通过匹配日期来合并 .csv 文件
- sql - 从表列中的 SQL Server 日期值获取月份名称
- c++ - 宏定义中的空 # 是什么意思?
- python - 如何将 .cer 文件(我拥有的数字签名证书)添加到 pdf?
- c++ - 为 postgresql 编译 libpqxx C++ 库时找不到 libpq-fe.h
- machine-learning - 我可以同时在测试和训练数据上使用 CountVectorizer 还是需要将其拆分?