繁体   English   中英

按日期更改类别wordpress的顺序

[英]Change order by date on category wordpress

我需要有关Wordpress中产品类别页面的帮助。 原始代码是由其他人制作的,而我对php还是相当陌生的。 在寻找一种使产品按发布日期排序的方式时,我可能需要帮助。 现在,这是我拥有的代码。

category-books.php

<?php
/**
* Template Name: Store Template
* @package WordPress
*/
get_header(); ?>

<div id="page-title"> 
<!-- 960 Container Start -->
<div class="container">
<div class="sixteen columns">
  <h1>
    <?php single_cat_title( '', true ); ?>
  </h1>
</div>
</div>
<!-- 960 Container End --> 
</div>
<?php 
get_template_part( 'content', 'product4' ); ?>
<div class="blogsidebar"  style="float:left !important">
<?php dynamic_sidebar('sidebar-1'); ?>
</div>
<?php get_footer();  ?>

content-product4.php

<?php function bac_wp_strip_header_tags_only( $excerpt ) {
$regex = '#(<h([1-6])[^>]*>)#';
$excerpt = preg_replace($regex,'', $excerpt);
return $excerpt;
}
add_filter( 'the_content', 'bac_wp_strip_header_tags_only', 0); ?>
<div class="container">
<?php  $sidebar_side = get_post_meta($post->ID, 'incr_sidebar_layout', true);
if($sidebar_side == "left-sidebar") {
get_sidebar();
} ?>

<!-- Blog Posts ================================================== -->

 <div class="twelve columns" style="float:right !important;">
  <div class="product-container">
    <?php $posts = query_posts($query_string . 'orderby=date&order=DESC&cat=238'); ?>
    <?php while (have_posts()) : the_post(); ?>

<!-- Post -->

 <div <?php post_class('post'); ?> id="product-post-2Col" > <a  class="post_title" href="<?php the_permalink() ?>">
  <div style="margin-bottom:10px;width: 130px;height: 180px !important;    border: 2px solid #000 !important;padding: 3px;float: left;margin: 0 15px 15px 0;overlay:hidden;">
  <?php if ( has_post_thumbnail() ) {
the_post_thumbnail( 'medium', array( 'class' => 'store-featured-image' ) );
  } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/product-image.png" alt="<?php the_title(); ?>" />
    <?php } ?>
  </div>
  <div style="min-height:40px !important;width:50% !important;float:left;">
    <h4>
      <?php the_title(); ?>
    </h4>
    </a> </div>
  <?php?>
  <div class="product-description-2col">
    <?php the_excerpt()?>
    <a style="margin-bottom: 8px;" class="post_title" href="<?php the_permalink() ?>">Learn More</a><br/>
    <?php ?>
    <a href="<?php the_field('buy_now_1')?>">
    <div id="buybtn">Buy Now</div>
    </a>
    <?php ?>
  </div>
  <?php ?>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
    </div>

    <!-- Post -->

    <?php endwhile; // End the loop. Whew.  ?>
  </div>
  <div style="text-align:center;">
    <?php posts_nav_link( ' &#183; ', 'previous page', 'next page' ); ?>
  </div>
</div>
<!-- eof eleven column -->

有没有一种方法可以添加一些功能。 我添加了这一行,但仍然无法正常工作:

<?php $posts = query_posts($query_string . 'orderby=date&order=DESC&cat=238'); ?>
<?php while (have_posts()) : the_post(); ?>

谢谢您的帮助。

与其为此使用functions.php,不如创建一个子主题并编辑要在此处更改的文件的副本。

https://codex.wordpress.org/Child_Themes

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM