当前位置: 首页 > 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"); ?>

相关文章:

  • Spring 必会之微服务篇(1)
  • python实现点餐系统
  • gitlab相关面试题及答案
  • 学习笔记:黑马程序员JavaWeb开发教程(2025.3.31)
  • 用Python监控金价并实现自动提醒!附完整源码
  • 软件测试——用例篇(2)
  • OpenHarmony 以太网卡热插拔事件接口无效
  • 【RLHF】 Reward Model 和 Critic Model 在 RLHF 中的作用
  • 云原生架构下的微服务通信机制演进与实践
  • 31【干货】Arcgis属性表常用查询表达式实战大全
  • 1 bit AI 框架:Part 1.1,CPU 上的快速无损 BitNet b1.58 推理
  • CAN转ModbusTCP网关:破解电池生产线设备协议壁垒,实现全链路智能互联
  • excel单元格如果是日期格式,在C#读取的时候会变成45807,怎么处理
  • c++:库(Library)
  • 系统的从零开始学习电子的相关知识,该如何规划?你是工作了18年的电子工程师,请给出你的建议
  • 【Linux】环境变量(图文)
  • learning ray之ray强化学习/超参调优和数据处理
  • ‌FunASR‌阿里开源的语音识别工具
  • 使用 ECharts GL 实现交互式 3D 饼图:技术解析与实践
  • WHAT - 冷启动和热启动
  • 5天完成1000多万元交易额,“一张手机膜”畅销海内外的启示
  • 比特币价格重返10万美元,哪些因素使然?
  • 国家发改委:美芯片药品等领域关税影响全球科技发展,损害人类共同利益
  • 少年中国之少年的形塑
  • 太空摄影的发展
  • 央行将增加3000亿元科技创新和技术改造再贷款额度