首页 > 解决方案 > Page Content Not Showing in Wordpress

问题描述

We did some updates to the site and since then the content blocks don't show in the frontend. This is what's being called:

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

And this is what it refers to:

<?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; ?>

And in partials/content-blocks/custom-content-block.php is has the following code:

<?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>

We also had a similar problem with the images not showing and was able to change the PHP code to make it work. It seems what it calls (slugs etc) has all got knocked out. Really hoping there's a fix for the content, too, but I can't see it. TIA!

标签: phpwordpress

解决方案


我认为您将需要使用 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() 应该可以解决您遇到的所有问题。


推荐阅读