Wordpress标题帖没有显示

问题描述 投票:0回答:1

如果'significado2'自定义字段为空,我创建了一个条件,所有内容都是隐藏的。字段在前端Wordpress Post上运行良好,但帖子的标题没有显示。

有些不对劲:

<?php $post = get_post_meta($post->ID, 'significado2', true) ; if (!empty($post)) { ?>
    <div class="conteudo"<?php wpex_schema_markup( 'entry_content' ); ?>><?php the_content(); ?>
          <hr />
<strong><span style="font-size: 21px;">2.  <?php the_title(); ?></span></strong>        
<p><em><span style="font-size: 18px; color: #008000;"> <?php the_field( 'significado2' ); ?></span></em></p>
<p style="padding-left: 30px;"><span style="color: #000080; font-size: 14px;"><i><?php the_field( 'ingles2' ); ?></i></span><br>
<span style="color: #ff0000; font-size: 14px;"><i> <?php the_field( 'portugues2' ); ?></i></span></p>

          <?php echo wpautop( get_post_meta( get_the_ID(), $post . 'significado2', true ) );?>
    </div>

我怎样才能解决这个问题? <?php the_title(); ?>没有显示在前端帖子页面上

php wordpress advanced-custom-fields custom-fields
1个回答
1
投票

我相信问题在这里:

$post = get_post_meta($post->ID, 'significado2', true) ;

因为这基本上覆盖了全球$post变量。

所以改变这一行:

<?php $post = get_post_meta($post->ID, 'significado2', true) ; if (!empty($post)) { ?>

..到这个:

<?php $key = get_post_meta($post->ID, 'significado2', true) ; if (!empty($key)) { ?>

并改变这一行:

<?php echo wpautop( get_post_meta( get_the_ID(), $post . 'significado2', true ) );?>

..到这个:

<?php echo wpautop( get_post_meta( get_the_ID(), $key . 'significado2', true ) );?>

或者这里是修改后的代码:

<?php $key = get_post_meta($post->ID, 'significado2', true) ; if (!empty($key)) { ?>
    <div class="conteudo"<?php wpex_schema_markup( 'entry_content' ); ?>><?php the_content(); ?>
          <hr />
<strong><span style="font-size: 21px;">2.  <?php the_title(); ?></span></strong>        
<p><em><span style="font-size: 18px; color: #008000;"> <?php the_field( 'significado2' ); ?></span></em></p>
<p style="padding-left: 30px;"><span style="color: #000080; font-size: 14px;"><i><?php the_field( 'ingles2' ); ?></i></span><br>
<span style="color: #ff0000; font-size: 14px;"><i> <?php the_field( 'portugues2' ); ?></i></span></p>

          <?php echo wpautop( get_post_meta( get_the_ID(), $key . 'significado2', true ) );?>
    </div>
<?php
// You forgot to include the closing } (i.e. bracket). If this causes problems,
// then remove it.
?>
<?php } // end $key ?>
© www.soinside.com 2019 - 2024. All rights reserved.