【发布时间】:2019-04-10 11:55:20
【问题描述】:
我正在开发一个相当复杂的主题,其中我为“页眉”和“页脚”创建了自定义帖子类型,为此我启用了 WPBakery Page Builder(目前在 Wordpress 4.9.8 中使用 v5.5.5)。
在 header.php 中,将 Header 帖子拉入并呈现在
这一切都完美无缺,除了在 WooCommerce 中转到产品类别页面时,页眉和页脚仅显示为页面构建器的原始短代码并且不解析它们。 WooCommerce 的其他一切都很好;商店页面、单个产品页面、购物车、结帐,一切都很好。出于某种原因,这只是类别。
这里是 header.php 中的代码:
<?php
$this_page_id = get_queried_object_id();
$gd_page_header = get_post_meta( $this_page_id, 'gd_page_header' );
if(empty($gd_page_header) || count($gd_page_header) == 0 || $gd_page_header[0] == 'default'){
$header_id = intval(get_option('default_header'));
}else{
$header_id = $gd_page_header[0];
}
if(!empty($header_id) && $header_id != '' && $header_id != 'none'){
$post = get_post( $header_id );
$transparent_header = get_post_meta( $post->ID, 'transparent_header', true );
$sticky_header = get_post_meta( $post->ID, 'sticky_header', true );
$sticky_desktop_only = get_post_meta( $post->ID, 'sticky_desktop_only', true );
if($sticky_header == '1'){
$header_class = 'sticky';
if($sticky_desktop_only == '1'){
$header_class .= ' dt_only';
}
}elseif($transparent_header == '1'){
$header_class = 'transparent';
}else{
$header_class = '';
}
$content = $post->post_content;
$content_css = visual_composer()->parseShortcodesCustomCss( $content );
if ( ! empty( $content_css ) ) { ?>
<style type="text/css" data-type="vc_shortcodes-custom-css">
<?php echo strip_tags( $content_css ); ?>
</style>
<?php } ?>
<header class="<?php echo($header_class); ?>">
<div id="container" class="container clearfix">
<?php echo apply_filters( 'the_content', $content ); ?>
</div>
</header>
<?php } ?>
然后是 WooCommerce 将其内容提取到的 page.php 中的代码:
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<main id="post-<?php the_ID(); ?>">
<div id="container" class="container clearfix">
<?php the_content(); ?>
</div>
</main>
<?php endwhile; endif; ?>
<?php get_footer(); ?>
这里是我的测试网站主页:http://sandbox.graphicdetail.co.nz/
如您所见,一切都很好地显示在那里。 一切也都很好地显示在商店页面上:http://sandbox.graphicdetail.co.nz/shop/
但是当我们进入一个类别页面时,一切都崩溃了:http://sandbox.graphicdetail.co.nz/product-category/toys/
我知道 WPBakery Page Builder 在此页面上仍然处于活动状态,因为您可以在 header.php 代码中看到它所在的位置:
$content_css = visual_composer()->parseShortcodesCustomCss( $content );
if ( ! empty( $content_css ) ) { ?>
<style type="text/css" data-type="vc_shortcodes-custom-css">
<?php echo strip_tags( $content_css ); ?>
</style>
<?php } ?>
...这似乎工作正常,因为当我使用检查器查看页面时,我可以看到 css 填充正确。
希望这里有人可能知道我在哪里犯了可怕的错误?
【问题讨论】:
-
您的类别页面上似乎缺少可视化作曲家 js 文件
js_composer_front.min.js -
知道为什么它会选择不在类别页面上排队,以及如何让它加载而无需在所有其他页面上重复加载?在这样做之前,还需要检查 WPBakery Page Builder 是否已实际安装和激活。
-
好的,我已经设法强制将 js_composer_front.min.js 加载到类别页面上,但页面的外观仍然没有变化。
标签: php wordpress woocommerce themes