custom-product.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <!doctype html>
  2. <html>
  3. <?php include 'head.php'; ?>
  4. <body>
  5. <?php
  6. /*Template Name: Custom Product*/
  7. get_header();
  8. ?>
  9. <div class="ny_ban"><img src="/wp-content/uploads/2024/03/2019072513554171.jpg"></div>
  10. <div class="ny_main w1200">
  11. <div class="l">
  12. <div class="box">
  13. <div class="tit">产品介绍</div>
  14. <div class="bor">
  15. <ul class="lm">
  16. <?php
  17. // 获取当前子分类
  18. $cat_id = $_REQUEST['fid'] ?? 27;
  19. // 输出目录
  20. echo get_slider_submenus('product',26,$cat_id)
  21. ?>
  22. </ul>
  23. </div>
  24. </div>
  25. <?php include 'concat.php'; ?>
  26. </div>
  27. <div class="r">
  28. <div class="tit">
  29. <div class="lj">您当前位置 :<a href="/index">首页</a> > <a href="/product">产品介绍</a> > <span><?php echo get_cat_name($cat_id) ?></span></div>
  30. <span><?php echo get_cat_name($cat_id) ?></span>
  31. </div>
  32. <div class="con ny_product">
  33. <?php
  34. // 产品查询
  35. if($cat_id == 28){
  36. // 获取该分类下的第一篇文章
  37. $args = array(
  38. 'cat' => $cat_id, // 分类ID
  39. 'posts_per_page' => 1, // 每页显示的文章数量
  40. 'orderby' => 'date', // 按日期排序
  41. 'order' => 'ASC', // 升序
  42. );
  43. $cur_post = get_posts($args);
  44. if ($cur_post) {
  45. $content = $cur_post[0]->post_content; // 文章内容
  46. echo $content;
  47. } else {
  48. echo '文章不存在';
  49. }
  50. // 释放查询结果
  51. wp_reset_postdata();
  52. }
  53. // 假设你已经在WordPress环境中,并且有分类ID $category_id
  54. $category_id = $cat_id; // 替换为你的分类ID
  55. // 获取分页参数
  56. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  57. // 查询参数
  58. $args = array(
  59. 'cat' => $category_id, // 分类ID
  60. 'posts_per_page' => 9, // 每页显示的文章数量
  61. 'paged' => $paged
  62. );
  63. // 查询文章
  64. $query = new WP_Query($args);
  65. if ($query->have_posts()) {
  66. echo '<ul>';
  67. while ($query->have_posts()) {
  68. $query->the_post();
  69. // 在这里编写你的文章列表
  70. $post_id = get_the_ID(); // 获取文章ID
  71. $excerpt = get_the_excerpt(); // 获取摘要
  72. if ( mb_strlen( $excerpt ) > 90 ) { // 如果字数超过200字
  73. $excerpt = mb_substr( $excerpt, 0, 90 ); // 截取前200个字符
  74. $excerpt .= '...'; // 添加省略号
  75. }
  76. // 产品介绍模板
  77. if($cat_id == 27){
  78. ?>
  79. <li>
  80. <div>
  81. <?php
  82. if(has_post_thumbnail()){
  83. // 获取特色图片的ID
  84. $thumbnail_id = get_post_thumbnail_id();
  85. // 获取特色图片的URL
  86. $thumbnail_url = wp_get_attachment_url( $thumbnail_id );
  87. ?>
  88. <a href="#"><img src="<?php echo $thumbnail_url ?>" width="100%"></a>
  89. <?php
  90. }
  91. ?>
  92. </div>
  93. <h3><a href="#"><?php the_title(); ?></a></h3>
  94. <p><?php echo $excerpt; ?></p>
  95. </li>
  96. <?php
  97. }
  98. }
  99. echo '</ul>';
  100. // 分页导航
  101. lingfeng_pagenavi();
  102. } else {
  103. // 没有找到文章的提示
  104. echo '没有找到文章。';
  105. }
  106. // 重置WordPress查询
  107. wp_reset_postdata();
  108. ?>
  109. </div>
  110. </div>
  111. </div>
  112. <style>
  113. .swiper-wrapper{height:auto;}
  114. </style>
  115. <?php get_footer(); ?>
  116. </body>
  117. </html>