wordpress主题中的woocommerce支持无效

时间:2016-07-16 06:06:20

标签: php wordpress woocommerce

我是wordpress的初学者,我尝试了所有方法,但我不能让我的主题woocommerce得到支持。以下是我的page.php

  

page.php文件

<?php
/**
 * The template for displaying pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages and that
 * other "pages" on your WordPress site will use a different template.
 *
 */
?>
<?php get_header(); ?>
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="page">
            <?php if ( have_posts() ) : ?>
            <?php while( have_posts() ) : the_post(); ?>

                <div class="post">
                    <h3 class="<?php post_class(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></h3>
                    <div class="entry-content">
                        <?php the_content(); ?>
                    </div>
                    <?php
                        // If comments are open or we have at least one comment, load up the comment template.
                        if ( comments_open() || get_comments_number() ) {
                            comments_template();
                        }
                    ?>
                </div>

            <?php endwhile; ?>
            <?php endif; ?>
        </div>
    </div>

<?php get_footer(); ?>

首先我复制page.php并创建woocommerce.php并上传到服务器,但它失败了,下面是我的woocommerce.php

  

woocommerce.php

<?php
/**
 * The template for displaying pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages and that
 * other "pages" on your WordPress site will use a different template.
 *
 */
?>


<?php get_header(); ?>
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="page">
            <?php woocommerce_content(); ?>
        </div>
    </div>
<?php get_footer(); ?>

但它失败了,之后我从服务器删除了woocommerce.php并编辑了我的functions.php文件以添加支持woocommerce的代码。以下是我在functions.php文件中添加的代码。

remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);

add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10);

function my_theme_wrapper_start() {
  echo '<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><div class="page">';
}

function my_theme_wrapper_end() {
  echo '</div></div>';
}

add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
    add_theme_support( 'woocommerce' );
}

但它也失败了,你可以看到输出here

如果你在调试器中看到你可以看到没有加载woocommerce css文件。

请帮我解决你的建议。谢谢。

1 个答案:

答案 0 :(得分:3)

转到functions.php并在顶部添加

add_theme_support('woocommerce');
最优选的是初始化函数。