hz2新建Keyword页面

news2025/5/14 18:47:05

新建一个single-keywords.php即可,需要筛选项再建taxonomy-knowledge-category.php
参考:https://www.tkwlkj.com/customize-wordpress-category-pages.html

WordPress中使用了ACF创建了自定义产品分类products,现在想实现自定义产品分类下的文章使用特定的详情页,不使用single.php,如何实现?要实现自定义产品分类下的文章使用特定的详情页而不使用single.php,您可以按照以下步骤操作:

创建自定义产品分类模板文件:
在您的主题文件夹中创建一个新的模板文件,命名为taxonomy-products.php。这里的products是您的自定义产品分类的标识符。
在这个模板文件中,您可以编写您想要显示的产品分类的内容和样式。
在taxonomy-products.php中查询文章:
使用WordPress提供的WP_Query或get_posts()函数在taxonomy-products.php中查询特定分类下的文章。
您可以根据需要设置查询参数,例如指定分类和数量等。
创建自定义文章模板文件:
创建一个单独的文章模板文件,命名为single-products.php。这里的products是您的自定义产品文章类型的标识符。
在这个模板文件中,您可以编写您想要显示的单个产品文章的详细内容和样式。
链接到详情页:
确保在您的分类模板文件taxonomy-products.php中,每篇文章标题都链接到对应的详情页。
您可以使用WordPress提供的the_permalink()函数来获取文章的链接。
保存并上传文件:
保存您的模板文件并上传到您的WordPress主题文件夹中。
通过这些步骤,您就可以实现自定义产品分类下的文章使用特定的详情页。确保您的主题支持这些自定义模板文件,并且在设置时备份您的文件以防万一。

在ACF插件中如何查找自定义产品文章类型的标识符?
要找到自定义产品文章类型的标识符,您可以按照以下步骤在ACF(*自定义字段)插件中查找:

进入WordPress后台:
登录到您的WordPress网站的后台管理页面。
导航到ACF设置:
在WordPress后台菜单中找到“自定义字段”(通常位于左侧菜单中),然后单击进入。
找到您的自定义字段组:
在自定义字段页面中找到与您的自定义产品文章类型相关联的自定义字段组。这可能是您之前创建的用于该文章类型的字段组。
编辑字段组:
单击您的自定义产品文章类型相关联的字段组。
查看字段设置:
在字段组编辑页面中,您将看到与您的自定义产品文章类型相关的字段。
通常,您可以在字段设置中找到“位置”设置。在这里,您可以看到字段组与特定的文章类型相关联。
查看相关文章类型:
在“位置”设置中,您将看到字段组与哪些文章类型相关联。自定义产品文章类型的标识符将在这里列出。
通过这些步骤,您应该能够在ACF插件中找到自定义产品文章类型的标识符。

ACF文章类型的标识符
不同类型的详情页

<!in single-keywords.php-->
<?php include( "header.php"); ?><!--内含主导航-->

<!--上大标题-->

<section class="SubPage-Hero" style="background-image: url(<?php echo get_template_directory_uri(); ?>/assets/images/inner-banner.jpg);">
<div class="container aos-init aos-animate" data-aos="fade-down">
    <h1><?php the_title(); ?></h1>
    <ul>
        <li><a href="<?php echo home_url(); ?>">Home</a></li>
        <span><i class="fa fa-angle-right" aria-hidden="true"></i></span>

        <?php if (is_singular('keywords')) : ?>
            <?php
            // Get the terms associated with the product
            $terms = get_the_terms(get_the_ID(), 'keyword_category');
            if ($terms && !is_wp_error($terms)) :
                $term = array_shift($terms); // Get the first term
            ?>
                <li><a href="<?php echo get_term_link($term->term_id); ?>"><?php echo esc_html($term->name); ?></a></li>
                <span><i class="fa fa-angle-right" aria-hidden="true"></i></span>
            <?php endif; ?>
            
            <li><?php the_title(); ?></li>
        <?php elseif (is_post_type_archive('keyword')) : ?>
            <li>Products</li>
        <?php endif; ?>
    </ul>
</div>

        </section>
        
        
<!--edit by pp-->

<!--描述-->
     <section class="shop-details">
   <div class="container">
    <div class="row">
       
        <!--<div class="main-tit-bar">-->
        <!--                <h1 class="title"><?php the_title(); ?></h1>-->
        <!--                <div class="clear"></div>-->
        <!--            </div>-->
                    <article class="entry blog-article">
                        <?php
                        if (have_posts()):
                            while (have_posts()): the_post();
                                the_content();
                            endwhile;
                        endif;
                        ?>
                        
                    </article>

    </div>
        <!---->
        <div class="lavelname">
           <h2>Related Products</h2>
        </div>
    
      <!--started Related Products-->
    
    <div class="row">
                
        <?php
        
       // $current_category = get_queried_object();
       $current_category_name = get_post_meta($post->ID, '_product_size', true);
       $current_category = get_term_by('name',$current_category_name,'product_category');
       
        if ($current_category && !is_wp_error($current_category)) {
            $popular_tag = 'popular-products';  // Ensure we're querying for 'popular-products' tag

            $popular_args = array(
                'post_type' => 'products', // Make sure you're querying 'products'
                'posts_per_page' => 7,     // Limit to 5 products per query
                'orderby' => 'rand',       // Randomize the results on each page load
                'tax_query' => array(
                    'relation' => 'AND',
                    array(
                        'taxonomy' => 'product_category', // Filter by product category
                        'field'    => 'term_id',
                        'terms'    => $current_category->term_id,
                    ),
                    array(
                        'taxonomy' => 'product_tag', // Filter by 'popular-products' tag
                        'field'    => 'slug',
                        'terms'    => $popular_tag,
                    ),
                ),
            );

            $popular_query = new WP_Query($popular_args);
          
            if ($popular_query->have_posts() && $popular_query->found_posts>7) :
           
                ?>
                
                    <?php while ($popular_query->have_posts()) : $popular_query->the_post(); ?>
                    <div class="col-lg-4 col-sm-6">
                        <div class="product_items">
                            <div class="overflows">
                                <div class="imagesec">
                                    <a href="<?php the_permalink(); ?>"><img  width="200" height="200" src="<?php the_post_thumbnail_url(); ?>" alt="<?php echo esc_attr(get_the_title() . ' - Product Image - ' . get_bloginfo('name')); ?>" title="<?php echo esc_attr(get_the_title()); ?>"></a>
                                    <div class="overly">
                                        <div class="addto">
                                           <a href="<?php the_permalink(); ?>">View Detail</a>
                                        </div>
                                    </div>
                                </div>
                                <div class="comtevt">
                                    <p><?php the_title(); ?></p>
                                </div>
                            </div>
                        </div>
                     </div>
                    <?php endwhile; ?>
                       
             </div>
            <?php 
            elseif($popular_query->have_posts() && $popular_query->found_posts<=7) : 
                
                    $popular_args_again = array(
                        'post_type' => 'products', // Make sure you're querying 'products'
                        'posts_per_page' => 7,     // Limit to 5 products per query
                        'orderby' => 'rand',       // Randomize the results on each page load
                        'tax_query' => array(
                            'relation' => 'AND',
                            array(
                                'taxonomy' => 'product_category', // Filter by product category
                                'field'    => 'term_id',
                                'terms'    => $current_category->term_id,
                            ),
                        ),
                    );
    
                $popular_query_again = new WP_Query($popular_args_again);
                if ($popular_query_again->have_posts() ) :
                        ?>
                        
                            <?php while ($popular_query_again->have_posts()) : $popular_query_again->the_post(); ?>
                                           <div class="col-lg-4 col-sm-6">
                    <div class="product_items">
                        <div class="overflows">
                                <div class="imagesec">
                                    <a href="<?php the_permalink(); ?>"><img  width="200" height="200" src="<?php the_post_thumbnail_url(); ?>" alt="<?php echo esc_attr(get_the_title() . ' - Product Image - ' . get_bloginfo('name')); ?>" title="<?php echo esc_attr(get_the_title()); ?>"></a>
                                    <div class="overly">
                                        <div class="addto">
                                            <a href="<?php the_permalink(); ?>">View Detail</a>
                                        </div>
                                    </div>
                                </div>
                                <div class="comtevt">
                                    <p><?php the_title(); ?></p>
                                </div>
                        </div>
                    </div>
                </div>
                            <?php endwhile; ?>
                       
             </div>
                    <?php 
                endif;
            else:
                echo '<p>No popular products found in this category.</p>';
            endif; 
            wp_reset_postdata();
        } else {
            echo '<p>No product category found.</p>';
        }
        ?>
                <div class="image_sc">
                    <?php if (has_post_thumbnail()) {
                        the_post_thumbnail('full', ['style' => 'width:100%;']);
                    } ?>
                </div>
    </div>
    <!--end Related Products-->
   <!---->
   
   
   
   
   
   </div>
</section>
        
        
        
        <!--开始第二节:热门商品-->
        

   <section class="shop-details">
   <div class="container">

        <!---->
        <div class="lavelname">
           <h2>Top Selling Products</h2>
        </div>
    
      <!--started popular Products-->
    
    <div class="row">
                
        <?php
        
       // $current_category = get_queried_object();
       $current_category_name = get_post_meta($post->ID, '_product_size', true);
       $current_category = get_term_by('name',$current_category_name,'product_category');
       
        if ($current_category && !is_wp_error($current_category)) {
            $popular_tag = 'popular-products';  // Ensure we're querying for 'popular-products' tag

            $popular_args = array(
                'post_type' => 'products', // Make sure you're querying 'products'
                'posts_per_page' => 6,     // Limit to 5 products per query
                'orderby' => 'rand',       // Randomize the results on each page load
                'tax_query' => array(
                    'relation' => 'AND',
                    array(
                        'post_type' => 'products', // Ensure this matches your custom post type
                        'posts_per_page' => 5, // Limit the number of products
                        'orderby' => 'rand',
                        'order' => 'DESC',
                    ),
                ),
            );

            $popular_query = new WP_Query($popular_args);
          
            if ($popular_query->have_posts()) :
           
                ?>
                
                    <?php while ($popular_query->have_posts()) : $popular_query->the_post(); ?>
                    <div class="col-lg-4 col-sm-6">
                        <div class="product_items">
                            <div class="overflows">
                                <div class="imagesec">
                                    <a href="<?php the_permalink(); ?>"><img  width="200" height="200" src="<?php the_post_thumbnail_url(); ?>" alt="<?php echo esc_attr(get_the_title() . ' - Product Image - ' . get_bloginfo('name')); ?>" title="<?php echo esc_attr(get_the_title()); ?>"></a>
                                    <div class="overly">
                                        <div class="addto">
                                            <a href="<?php the_permalink(); ?>">View Detail</a>
                                        </div>
                                    </div>
                                </div>
                                <div class="comtevt">
                                    <p><?php the_title(); ?></p>
                                </div>
                            </div>
                        </div>
                     </div>
                    <?php endwhile; ?>
                       
             </div>
            <?php 
            endif; 
            wp_reset_postdata();
        } else {
            echo '<p>No product category found.</p>';
        }
        ?>
              
    </div>
    <!--end popular Products-->
   <!---->
   
   
   
   
   
   </div>
</section>

  <!--结束第二节:热门商品-->


   <!--开始第三节:热门搜索-->
        

   <section class="shop-details">
   <div class="container">

        <!---->
        <div class="lavelname">
           <h2>related search</h2>
        </div>
    
      <!--started popular Products-->
    
    <div class="row">
                
        <?php
        
       // $current_category = get_queried_object();
       $current_category_name = get_post_meta($post->ID, '_product_size', true);
       $current_category = get_term_by('name',$current_category_name,'product_category');
       
        if ($current_category && !is_wp_error($current_category)) {
            $popular_tag = 'popular-products';  // Ensure we're querying for 'popular-products' tag

            $popular_args = array(
                'post_type' => 'keywords', // Make sure you're querying 'products'
                'posts_per_page' => 10,     // Limit to 5 products per query
                'orderby' => 'rand',       // Randomize the results on each page load
                'tax_query' => array(
                    'relation' => 'AND',
                    array(
                        'post_type' => 'keywords', // Ensure this matches your custom post type
                        'posts_per_page' => 10, // Limit the number of products
                        'orderby' => 'rand',
                        'order' => 'DESC',
                    ),
                ),
            );

            $popular_query = new WP_Query($popular_args);
          
            if ($popular_query->have_posts()) :
           
                ?>
                
                    <?php while ($popular_query->have_posts()) : $popular_query->the_post(); ?>
                    <div class="col-lg-4 col-sm-6">
                        <div class="product_items">
                            <div class="overflows">
                                <div class="imagesec">
                                    <a href="<?php the_permalink(); ?>"><img  width="200" height="200" src="<?php the_post_thumbnail_url(); ?>" alt="<?php echo esc_attr(get_the_title() . ' - Product Image - ' . get_bloginfo('name')); ?>" title="<?php echo esc_attr(get_the_title()); ?>"></a>
                                    <div class="overly">
                                        <div class="addto">
                                            <a href="<?php the_permalink(); ?>">View Detail</a>
                                        </div>
                                    </div>
                                </div>
                                <div class="comtevt">
                                    <p><?php the_title(); ?></p>
                                </div>
                            </div>
                        </div>
                     </div>
                    <?php endwhile; ?>
                       
             </div>
            <?php 
            endif; 
            wp_reset_postdata();
        } else {
            echo '<p>No product category found.</p>';
        }
        ?>
              
    </div>
    <!--end popular Products-->
   <!---->
   
   
   
   
   
   </div>
</section>

  <!--结束第san节:热门搜索-->

<?php include( "footer.php"); ?>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2375580.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

离散制造企业WMS+MES+QMS+条码管理系统高保真原型全解析

在离散型制造企业的生产过程中&#xff0c;库存管理混乱、生产进度不透明、质检流程繁琐等问题常常成为制约企业发展的瓶颈。为了帮助企业实现全流程数字化管控&#xff0c;我们精心打造了一款基于离散型制造企业&#xff08;涵盖单件生产、批量生产、混合生产模式&#xff09;…

基于 Spring Boot 瑞吉外卖系统开发(十三)

基于 Spring Boot 瑞吉外卖系统开发&#xff08;十三&#xff09; 查询套餐 在查询套餐信息时包含套餐的分类名&#xff0c;分类名称在category表中&#xff0c;因此这里需要进行两表关联查询。 自定义SQL如下&#xff1a; select s.* ,c.name as category_name from setmeal…

POSE识别 神经网络

Pose 识别模型介绍 Pose 识别是计算机视觉领域的一个重要研究方向&#xff0c;其目标是从图像或视频中检测出人体的关键点位置&#xff0c;从而估计出人体的姿态。这项技术在许多领域都有广泛的应用&#xff0c;如动作捕捉、人机交互、体育分析、安防监控等。 Pose 识别模型的…

力扣119题:杨辉三角II(滚动数组)

小学生一枚&#xff0c;自学信奥中&#xff0c;没参加培训机构&#xff0c;所以命名不规范、代码不优美是在所难免的&#xff0c;欢迎指正。 标签&#xff1a; 杨辉三角、滚动数组 语言&#xff1a; C 题目&#xff1a; 给定一个非负索引 rowIndex&#xff0c;返回「杨辉三角…

大疆无人机(全系列,包括mini)拉流至电脑,实现直播

参考视频 【保姆级教程】大疆无人机rtmp推流直播教程_哔哩哔哩_bilibili VLC使用教程&#xff1a; VLC工具使用指南-CSDN博客 目录 实现效果&#xff1a; 电脑端 ​编辑 ​编辑 无人机端 VLC拉流 分析 实现效果&#xff1a; (实验机型&#xff1a;大疆mini4kRC-N2遥控器、大…

uniapp-商城-54-后台 新增商品(页面布局)

后台页面中还存在商品信息的添加和修改等。接下来我们逐步进行分析和展开。包含页面布局和数据库逻辑等等。 1、整体效果 样式效果如下&#xff0c;依然采用了表单形式来完成和商家信息差不多&#xff0c;但在商品属性上多做了一些弹窗等界面&#xff0c;样式和功能点表多。 …

WebpackVite总结篇与进阶

模块化 Webpack Webpack 入口entry 分离app和第三方库入口 这是什么&#xff1f; 这是告诉 webpack 我们想要配置 2 个单独的入口点&#xff08;例如上面的示例&#xff09;。 为什么&#xff1f; 这样你就可以在 vendor.js 中存入未做修改的必要 library 或文件&#xff0…

【python】基础知识点100问

以下是Python基础语法知识的30条要点整理,涵盖数据类型、函数、控制结构等核心内容,结合最新资料归纳总结: 基础30问 一、函数特性 函数多返回值 支持用逗号分隔返回多个值,自动打包为元组,接收时可解包到多个变量 def func(): return 1, "a" x, y = func()匿…

SpringBoot--springboot简述及快速入门

spring Boot是spring提供的一个子项目&#xff0c;用于快速构建spring应用程序 传统方式&#xff1a; 在众多子项目中&#xff0c;spring framework项目为核心子项目&#xff0c;提供了核心的功能&#xff0c;其他的子项目都需要依赖于spring framework&#xff0c;在我们实际…

vscode_python远程调试_pathMappings配置说明

1.使用说明 vscode python 远程调试pathMappings 配置 launch.json "pathMappings": [{"localRoot": "本地代码目录","remoteRoot": "远程代码目录" # 注意不是运行目录, 是远程代码的目录}],2.测试验证 测试目的: 远程代…

遨游5G-A防爆手机:赋能工业通信更快、更安全

在工业数字化转型与5G-A商用进程加速的双重驱动下&#xff0c;中国防爆手机市场正迎来历史性发展机遇。作为“危、急、特”场景通信解决方案服务商&#xff0c;遨游通讯深刻洞察到&#xff1a;当5G-A网络以超高速率、海量连接和毫秒级时延重塑行业生态时&#xff0c;防爆手机这…

Profibus DP主站与Modbus RTU/TCP网关与海仕达变频器轻松实现数据交互

Profibus DP主站与Modbus RTU/TCP网关与海仕达变频器轻松实现数据交互 Profibus DP主站转Modbus RTU/TCP&#xff08;XD-MDPBm20&#xff09;网关在Profibus总线侧实现主站功能&#xff0c;在Modbus串口侧实现从站功能。可将ProfibusDP协议的设备&#xff08;如&#xff1a;海…

「华为」人形机器人赛道投资首秀!

温馨提示&#xff1a;运营团队2025年最新原创报告&#xff08;共210页&#xff09; —— 正文&#xff1a; 近日&#xff0c;【华为】完成具身智能赛道投资首秀&#xff0c;继续加码人形机器人赛道布局。 2025年3月31日&#xff0c;具身智能机器人头部创企【千寻智能&#x…

格雷希尔G10和G15系列自动化快速密封连接器,适用于哪些管件的密封,以及它们相关的特性有哪些?

格雷希尔G10和G15系列快速密封连接器&#xff0c;用于自动化和半自动化过程中的外部或内部密封&#xff0c;通过使用气压驱动来挤压内部的密封圈&#xff0c;创造一个适用于各种管件的无泄漏密封连接&#xff0c;连接器内部的弹性密封圈可以提供其他产品不能提供的卓越密封性能…

专栏特辑丨悬镜浅谈开源风险治理之SBOM与SCA

随着容器、微服务等新技术日新月异&#xff0c;开源软件成为业界主流形态&#xff0c;软件行业快速发展。但同时&#xff0c;软件供应链也越来越趋于复杂化和多样化&#xff0c;软件供应链安全风险不断加剧。 软件供应链安全主要包括软件开发生命周期和软件生存运营周期&#x…

vue3项目创建-配置-elementPlus导入-路由自动导入

目录 方法一&#xff1a;create-vue 方法二 &#xff1a;Vite Vue Vite.config.ts配置 引入element-plus 安装 如何在项目中使用 Element Plus 完整引入 按需导入 vue3vite中自动配置路由的神器&#xff1a;vite-plugin-pages 1. 安装 2、修改vite.config.js中配置…

MUSE Pi Pro 编译kernel内核及创建自动化脚本进行环境配置

视频讲解&#xff1a; MUSE Pi Pro 编译kernel内核及创建自动化脚本进行环境配置 今天分享的主题为创建自动化脚本编译MUSE Pi Pro的kernel内核&#xff0c;脚本已经上传到中 GitHub - LitchiCheng/MUSE-Pi-Pro-Learning: MUSE-Pi-Pro-Learning &#xff0c;有需要可以自行clon…

Innovus 25.1 版本更新:助力数字后端物理设计新飞跃

在数字后端物理设计领域&#xff0c;每一次工具的更新迭代都可能为项目带来巨大的效率提升与品质优化。今天&#xff0c;就让我们一同聚焦 Innovus 25.1 版本&#xff08;即 25.10 版本&#xff09;的更新要点&#xff0c;探寻其中蕴藏的创新能量。 一、核心功能的强势进 AI…

CodeBuddy 中国版 Cursor 实战:Redis+MySQL双引擎驱动〈王者荣耀〉战区排行榜

文章目录 一、引言二、系统架构设计2.1、整体架构概览2.2、数据库设计2.3、后端服务设计 三、实战&#xff1a;从零构建排行榜3.1、开发环境准备3.2、用户与战区 数据管理3.2.1、MySQL 数据库表创建3.2.2、实现用户和战区数据的 CURD 操作 3.3、实时分数更新3.4、排行榜查询3.5…

在线SQL转ER图工具

在线SQL转ER图网站 在数据库设计、软件开发或学术研究中&#xff0c;ER图&#xff08;实体-关系图&#xff09; 是展示数据库结构的重要工具。然而&#xff0c;手动绘制ER图不仅耗时费力&#xff0c;还容易出错。今天&#xff0c;我将为大家推荐一款非常实用的在线工具——SQL…