按日期在分类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?我已经添加了这一行,但仍然不工作:

<?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