【问题标题】:How can I set up a taxonomy category as my page on wordpress?如何在 wordpress 上设置分类类别作为我的页面?
【发布时间】:2021-10-30 15:12:24
【问题描述】:

我的电子商务网站上有这个主题,它叫做 Soma。他很棒,但遗憾的是,团队不再支持了。

我的问题是如何将类别设置为页面?因为在这个特别的主题上,侧边栏菜单不会出现在普通页面上,只会出现在商店页面和类别页面上。

我需要创建一个只显示一种产品类型的页面,这很容易使用 woocommerce 代码。但问题是在那个页面上,它没有显示侧边栏菜单。

我会在这里打印一些照片,也许它会有所帮助。

打印问题:

    <?php

/*
Default Template Page
*/

get_header();

if (have_posts()) : while (have_posts()) : the_post();

$soma_vc = preg_match("/\[vc_row.*?\]/i", get_the_content());

$soma_page_class = "container";

if ($soma_vc && function_exists('vc_map')) {
    $soma_page_class = "n-container";
}
?>
    <div class="<?php echo esc_attr($soma_page_class) ?>">
        <?php
            the_content();

            // WP Link Pages
            $args = array(
                'before' => '<div class="navigation">', 
                'after' => '</div>'
            );
            wp_link_pages($args);
        ?>
    </div>
    
<?php
endwhile; endif;

// Comments
comments_template();

get_footer();

这就是我需要放在那里的:

    <?php if($soma_shop_sidebar != '2' && is_active_sidebar('shop-sidebar')) : ?>
    <div class="soma-overlay" id="woo-sidebar_overlay"></div>
    <div class="woo-sidebar fixed-lateral left item-delay_off">
        <div class="hide-scrollbar">
            <div class="inner-hide_scrollbar">
                <div class="woo-sidebar_padding">
                    <a href="#" class="sidebar-close_button"><?php echo esc_html__('Close', 'soma') ?></a>
                    <?php get_sidebar('shop'); ?>
                </div>
            </div>
        </div>
    </div>

【问题讨论】:

  • 您好!您能否编辑您的帖子以包含代码示例,包括出现侧边栏的页面和没有出现侧边栏的页面?为了让其他 StackOverflow 用户提供建设性的答案,我们需要查看您正在使用的实际代码。
  • 完成!我说的,我认为这就是它可以工作的方式。

标签: php wordpress themes


【解决方案1】:

如果没有看到非开源 Soma 的完整源代码,这仍然很难提供帮助。

但是,如果您只是需要自定义用于显示单个类别的模板,而主题中还没有category.php 模板,则程序如下:

1。为单个类别创建自定义模板

参考WordPress Template Hierarchy,您需要创建一个名为category.php的自定义模板

如果您希望此页面的布局与另一个现有模板相似,只需将该模板的代码复制到 category.php 即可开始。

2。将相关的侧边栏代码复制到您的新 category.php 模板中

将您发布的侧边栏代码添加到新的 category.php 模板中,无论它属于布局中的什么位置。

如果您不确定将其放在哪里,或者您想以与商店和类别页面相同的方式包含侧边栏模板:

  • 查看当前出现侧边栏的模板的代码
  • 找到包含侧边栏模板的位置
  • 在您的新 category.php 文件中执行相同的操作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 1970-01-01
    • 2016-06-19
    • 2013-10-01
    • 2014-11-24
    • 2017-07-07
    • 1970-01-01
    相关资源
    最近更新 更多