当前位置: 首页 > news >正文

hz2新建Keyword页面

新建一个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"><?phpif (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.xdnf.cn/news/352909.html

相关文章:

  • 使用 swift 微调 Qwen3-4b 模型
  • 矩阵短剧系统:如何用1个后台管理100+小程序?深度解析多端绑定技术
  • C++--类中this指针的讲解
  • 从数据孤岛到智能工厂:RG3000边缘网关的数字化转型实践
  • Mac QT水平布局和垂直布局
  • 小红书视频无水印下载方法
  • AI技术与园区运营的深度融合:未来生态型园区的建设路径
  • VS Code配置指南:打造高效的QMK开发环境
  • 老旧 LabVIEW 系统升级改造
  • 系统的从零开始学习电子的相关知识,该如何规划?你是工作了18年的电子工程师,请给出你的建议
  • 三维GIS开发cesium智慧地铁教程(6)添加模型
  • 31【干货】Arcgis属性表常用查询表达式实战大全
  • 基于Java和GeoTools的根据矢量BBOx自动生成格网文件实践
  • 基于C++的多线程网络爬虫设计与实现(CURL + 线程池)
  • Java游戏服务器开发流水账(3)游戏数据的缓存简介
  • 第04章—技术突击篇:如何根据求职意向进行快速提升与复盘
  • 数据库索引
  • 使用Java处理多客户端服务器:从传统线程到虚拟线程
  • [250509] x-cmd 发布 v0.5.11 beta:x ping 优化、AI 模型新增支持和语言变量调整
  • kotlin 数据类
  • Electron知识框架
  • 基于SSM + JSP 的个人通讯录管理系统
  • 使用 ANSYS AEDT(单向耦合)进行高功率同轴射频滤波器的热分析
  • 前端取经路——性能优化:唐僧的九道心经
  • 橡胶制品行业质检管理的痛点 质检LIMS如何重构橡胶制品质检价值链
  • STM32外设-串口UART
  • 项目高压生存指南:科学重构身体与认知系统的抗压算法
  • 计算机二级WPS Office第三套电子表格
  • 排序算法-插入排序
  • Linux快速入门