php - 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!
解决方案
我认为您将需要使用 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( ']]>', ']]>', $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() 应该可以解决您遇到的所有问题。
推荐阅读
- r - R tidyverse,统一后整理
- yii2 - Yii2. 如何构建子表达式
- python-3.x - 从两列中识别 txt 中的字符串
- unity3d - 确定 Quad Sphere Face 边缘的 Quad Tree 邻居的有效方法?
- html - 将 XML 转换为 HTML
- java - Selenium - Java - ChromeDriver:打开空白“数据”;在某些情况下,在打开另一个运行实际测试的 chrome 窗口之前?
- css - Chrome中的剪辑路径水平白线
- javascript - 用于 Angular 测试的 JS 堆内存不足
- javascript - 如果不在焦点上,Google 自动完成输入不起作用
- linux - 过滤命令输出并将其保存在 Json 格式列表中的 Shell 脚本