新建一個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"); ?>