页面内容未显示在Wordpress中

时间:2020-02-11 20:34:46

标签: php wordpress

我们对网站进行了一些更新,此后,内容块不再显示在前端。这就是所谓的:

<div class="page-content">
        <?php get_template_part('content-block-loop'); ?>
    </div>

这就是它的含义:

<?php
$post_objects = get_field('page_content_blocks');
if( $post_objects ):
    foreach( $post_objects as $post_object):
        $args = array('orderby' => 'menu_order', 'order' => 'ASC', 'fields' => 'all');
        $terms = wp_get_post_terms( $post_object->ID, 'content_block_cat', $args );
        if( get_field('disable_wpautop',$post_object->ID) ){
          remove_filter ('acf_the_content', 'wpautop');
        }
        include( locate_template( 'partials/content-blocks/'.$terms[0]->slug.".php" ) );
        add_filter ('acf_the_content', 'wpautop');
    endforeach; ?>
<?php endif; ?>

在partials / content-blocks / custom-content-block.php中,具有以下代码:

<?php

$vertical_padding = "less-space";
$background_color = "white-bg";

if ( get_field('vertical_padding',$post_object->ID) ){
    $vertical_padding = get_field('vertical_padding',$post_object->ID);
}

if ( get_field('content_block_background_color',$post_object->ID) ){
    $background_color = get_field('content_block_background_color',$post_object->ID);
}

?>

<div class="panel <?php if( $vertical_padding != "none" ) { echo $vertical_padding; } ?> <?php echo $background_color; ?> relative-block">
    <div class="row">
        <div class="column small-12">
            <?php $custom_content_block_content = get_field('content',$post_object->ID);
            if( $custom_content_block_content ){
                the_field('content',$post_object->ID);
            } ?>
        </div>
    </div>
</div>

我们也遇到了类似的问题,即图像未显示,并且能够更改PHP代码以使其正常工作。似乎它所谓的(子弹等)都被淘汰了。确实希望内容也有修复,但我看不到。 TIA!

1 个答案:

答案 0 :(得分:0)

我认为您将需要使用the_content()来显示帖子内容。

function the_content( $more_link_text = null, $strip_teaser = false ) {
$content = get_the_content( $more_link_text, $strip_teaser );

/**
 * Filters the post content.
 *
 * @since 0.71
 *
 * @param string $content Content of the current post.
 */
$content = apply_filters( 'the_content', $content );
$content = str_replace( ']]>', ']]&gt;', $content );
echo $content;
}

the_content()模板标记获取帖子的内容,对其进行过滤,然后将其显示。这是每条穿过The Loop的肉和土豆。

尝试一下:

<?php

$vertical_padding = "less-space";
$background_color = "white-bg";

if ( get_field('vertical_padding',$post_object->ID) ){
  $vertical_padding = get_field('vertical_padding',$post_object->ID);
}

if ( get_field('content_block_background_color',$post_object->ID) ){
  $background_color = get_field('content_block_background_color',$post_object->ID);
}

?>
<?php the_content(); ?>

<div class="panel <?php if( $vertical_padding != "none" ) { echo $vertical_padding; } ?> <?php echo $background_color; ?> relative-block">
<div class="row">
    <div class="column small-12">
        <?php $custom_content_block_content = get_field('content',$post_object->ID);
        if( $custom_content_block_content ){
            the_field('content',$post_object->ID);
        } ?>

    </div>
</div>
</div>

WordPress循环在您的页面上无效,并且通过包含the_content()应该可以解决您遇到的所有问题。