(WP Post Title)Malwarebytes反恶意软件(自定义字段值)3.5.1.2522
如何在同一超链接中的wp post title后在wordpress中添加自定义元值
(WP Post Title)Malwarebytes反恶意软件(自定义字段值)3.5.1.2522
如何在同一超链接中的wp post title后在wordpress中添加自定义元值
这是一个简单的三步流程:
查找您的帖子标题标记,该标记应如下所示:
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
现在,通过以下方式获取您的帖子自定义元值:<?php $bannerContent = get_post_meta($post->ID, \'bannerContent\', true); ?>
下一步,在您需要的地方将此值添加到您的标题中:<h1><a href="<?php the_permalink(); ?>"><?php the_title(); echo $bannerContent; ?></a></h1>
就是这样。如果您需要任何进一步的帮助,请告诉我们!快乐编码可以更改模板文件中显示的标题(例如content.php):
$custom_field = get_post_meta($post->ID, $custom_meta_key, true);
if ( is_single() ) {
the_title( \'<h1 class="entry-title">\', \'</h1>\' );
} elseif ( is_front_page() && is_home() ) {
the_title( \'<h3 class="entry-title"><a href="\' . esc_url( get_permalink() ) . \'" rel="bookmark">\',
\' \' . $custom_field . \'</a></h3>\' );
} else {
the_title( \'<h2 class="entry-title"><a href="\' . esc_url( get_permalink() ) . \'" rel="bookmark">\',
\' \' . $custom_field . \'</a></h2>\' );
}
您还可以使用the_title
过滤器挂钩(代码转到functions.php):add_filter( \'the_title\', \'modify_post_title\' );
function modify_post_title( $title ) {
global $post;
//
// --- show on list and single post view
// if ( $post->post_type == \'post\' && in_the_loop() ) {
// --- show only in single post view
// if ( is_singular() && $post->post_type == \'post\' && in_the_loop() ) {
// when to apply custom field suffix
// --- when type is "post" and when it\'s not a single post view
if ( !is_singular() && $post->post_type == \'post\' && in_the_loop() ) {
// $custom_field = get_post_meta($post->ID, $custom_meta_key, true);
$title .= $custom_field;
}
return $title;
}
这取决于你想要实现什么。add\\u filter(\'post\\u type\\u link\',\'append\\u query\\u string\',10,2);函数append\\u query\\u string($url,$post){返回$url。“?var\\u name=”。get\\u post\\u meta($post->ID,\'meta\\u key,true);}