×با عرض پوزش به خاطر بالا آوردن تاپیک های قدیمی× ( مجبور بودم ! )
سلام
اصولا این کار همانطور که دوست عزیزمان اروین گفتند ، توی index.php انجام میشه ولی متنی که باید آن را جس و جو کنید ، در قالب های مختلف فرق می کنه ، مثلا در قالبی که من استفاده میکنم کل فایل ایندکس به صورت زیر می باشد:
<?php get_header(); ?> <?php global $woo_options; ?><div class="row homepage visible"> <!-- Header widget --> <section class="header-widget"> <?php if ( function_exists('dynamic_sidebar') ) dynamic_sidebar( 'header-widget' ); ?> </section><!--/.header-widget--> <section id="content"> <?php if ( is_woocommerce_activated() ) { ?> <!-- The first featured product --> <div class="featured-1 sixcol"> <?php $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'meta_query' => array( array('key' => '_visibility','value' => array('catalog', 'visible'),'compare' => 'IN'),array('key' => '_featured','value' => 'yes')) ); $loop = new WP_Query( $args ); if ( function_exists( 'get_product' ) ) { $_product = get_product( $loop->post->ID ); } else { $_product = new WC_Product( $loop->post->ID ); } while ( $loop->have_posts() ) : $loop->the_post(); $_product; ?> <?php woocommerce_show_product_sale_flash( $post, $_product ); ?> <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php // echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"> <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_single'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="'.$woocommerce->get_image_size('shop_single_image_width').'px" height="'.$woocommerce->get_image_size('shop_single_image_height').'px" />'; ?> </a> <div class="meta"> <h2><span><?php _e('Featured Product', 'woothemes'); ?></span> <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php // echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"><?php the_title(); ?></a></h2> <span class="price"><?php echo $product->get_price_html(); ?></span> <?php the_excerpt(); ?> <?php // woocommerce_template_loop_add_to_cart( $loop->post, $_product ); ?> </div><!--/.meta--> <?php endwhile; ?> </div><!--/.featured-1--> <!-- 4 recent products --> <div class="recent-1 sixcol last"> <ul class="recent products"> <?php $args = array( 'post_type' => 'product', 'posts_per_page' => 8, 'meta_query' => array( array('key' => '_visibility','value' => array('catalog', 'visible'),'compare' => 'IN'),array('key' => '_featured','value' => 'no')) ); $first_or_last = 'first'; $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $_product; ?> <li class="product sixcol <?php echo $first_or_last; $first_or_last = ('first'==$first_or_last) ? 'last' : 'first'; ?>"> <?php woocommerce_show_product_sale_flash( $post, $_product ); ?> <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php // echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"> <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="'.$woocommerce->get_image_size('shop_catalog_image_width').'px" height="'.$woocommerce->get_image_size('shop_catalog_image_height').'px" />'; ?> </a> <div class="meta"> <h3><a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php // echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"><?php the_title(); ?></a></h3> <span class="price"><?php echo $product->get_price_html(); ?></span> <?php // woocommerce_template_loop_add_to_cart( $loop->post, $_product ); ?> </div><!--/.meta--> </li> <?php endwhile; ?> </ul><!--/ul.recent--> <div class="clear"></div> <!-- Display the homepage widget area --> <?php if ( function_exists('dynamic_sidebar') ) dynamic_sidebar( 'homepage-content' ); ?> </div><!--/.recent-1--> <div class="clear"></div> <!-- 4 more recent products --> <div class="recent-2 sixcol"> <ul class="recent products"> <?php $args = array( 'post_type' => 'product', 'posts_per_page' => 8, 'offset' => 4, 'meta_query' => array( array('key' => '_visibility','value' => array('catalog', 'visible'),'compare' => 'IN'),array('key' => '_featured','value' => 'no')) ); $first_or_last = 'first'; $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $_product; ?> <li class="product sixcol <?php echo $first_or_last; $first_or_last = ('first'==$first_or_last) ? 'last' : 'first'; ?>"> <?php woocommerce_show_product_sale_flash( $post, $_product ); ?> <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php // echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"> <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="'.$woocommerce->get_image_size('shop_catalog_image_width').'px" height="'.$woocommerce->get_image_size('shop_catalog_image_height').'px" />'; ?> </a> <div class="meta"> <h3><a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php // echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"><?php the_title(); ?></a></h3> <span class="price"><?php echo $product->get_price_html(); ?></span> <?php // woocommerce_template_loop_add_to_cart( $loop->post, $_product ); ?> </div><!--/.meta--> </li> <?php endwhile; ?> </ul><!--/ul.recent--> <!-- Display the latest post --> <?php if ( $woo_options[ 'woo_homepage_content' ] == "true" ) { ?> <?php query_posts('posts_per_page=1'); ?> <?php while (have_posts()) : the_post(); ?> <article <?php post_class(); ?>> <h2 class="title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'woothemes' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2> <aside class="threecol meta"> <ul> <li class="date"><?php the_time('j F Y', '<time>', '</time>'); ?></li> <li class="author"><?php the_author_posts_link(); ?></li> <li class="category"><?php the_category(', '); ?></li> <!--<li class="tags"><?php // the_tags('Tagged: ',', ',''); ?></li>--> <li class="comments"><?php comments_popup_link(__( '0 Comments', 'woothemes' ), __( '1 Comment', 'woothemes' ), __( '% Comments', 'woothemes' )); ?></a></li> <?php the_tags( '<li class="tags">', ', ', '</li>' ); ?></li> </ul> </aside><!--/.meta--> <section class="article-content ninecol last"> <?php the_excerpt(); ?> </section><!--/.article-content--> </article><!--/.post--> <?php endwhile;?> <?php } else { ?> <?php } ?> </div><!--/.recent-2--> <!-- 2nd featured product --> <div class="featured-2 sixcol last"> <?php $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'offset' => 1, 'meta_query' => array( array('key' => '_visibility','value' => array('catalog', 'visible'),'compare' => 'IN'),array('key' => '_featured','value' => 'yes')) ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $_product; ?> <?php woocommerce_show_product_sale_flash( $post, $_product ); ?> <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php // echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"> <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_single'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="'.$woocommerce->get_image_size('shop_single_image_width').'px" height="'.$woocommerce->get_image_size('shop_single_image_height').'px" />'; ?> </a> <div class="meta"> <h2><span><?php _e('Featured Product', 'woothemes'); ?></span> <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php // echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"><?php the_title(); ?></a></h2> <span class="price"><?php echo $product->get_price_html(); ?></span> <?php the_excerpt(); ?> <?php // woocommerce_template_loop_add_to_cart( $loop->post, $_product ); ?> </div><!--/.meta--> <?php endwhile; ?> </div><!--/.featured-1--> <?php } // endif is_woocommerce_activated() ?> </section> </div><?php get_footer(); ?>اما قسمتی که باید تقییر بدم ۲ قسمت می باشد که به صورت زیر است:
<!-- 4 recent products --> <div class="recent-1 sixcol last"> <ul class="recent products"> <?php $args = array( 'post_type' => 'product', 'posts_per_page' => 6, 'meta_query' => array( array('key' => '_visibility','value' => array('catalog', 'visible'),'compare' => 'IN'),array('key' => '_featured','value' => 'no')) ); $first_or_last = 'first'; $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $_product; ?> <li class="product sixcol <?php echo $first_or_last; $first_or_last = ('first'==$first_or_last) ? 'last' : 'first'; ?>"> <?php woocommerce_show_product_sale_flash( $post, $_product ); ?> <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php // echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"> <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="'.$woocommerce->get_image_size('shop_catalog_image_width').'px" height="'.$woocommerce->get_image_size('shop_catalog_image_height').'px" />'; ?> </a> <div class="meta"> <h3><a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php // echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"><?php the_title(); ?></a></h3> <span class="price"><?php echo $product->get_price_html(); ?></span> <?php // woocommerce_template_loop_add_to_cart( $loop->post, $_product ); ?> </div><!--/.meta--> </li> <?php endwhile; ?> </ul><!--/ul.recent-->و
<!-- 4 more recent products --> <div class="recent-2 sixcol"> <ul class="recent products"> <?php $args = array( 'post_type' => 'product', 'posts_per_page' => 8, 'offset' => 6, 'meta_query' => array( array('key' => '_visibility','value' => array('catalog', 'visible'),'compare' => 'IN'),array('key' => '_featured','value' => 'no')) ); $first_or_last = 'first'; $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $_product; ?> <li class="product sixcol <?php echo $first_or_last; $first_or_last = ('first'==$first_or_last) ? 'last' : 'first'; ?>"> <?php woocommerce_show_product_sale_flash( $post, $_product ); ?> <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php // echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"> <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="'.$woocommerce->get_image_size('shop_catalog_image_width').'px" height="'.$woocommerce->get_image_size('shop_catalog_image_height').'px" />'; ?> </a> <div class="meta"> <h3><a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php // echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"><?php the_title(); ?></a></h3> <span class="price"><?php echo $product->get_price_html(); ?></span> <?php // woocommerce_template_loop_add_to_cart( $loop->post, $_product ); ?> </div><!--/.meta--> </li> <?php endwhile; ?> </ul><!--/ul.recent-->در هر دوی این کد ها ، این متن
product', 'posts_per_page' => ,,وجود دارد اما در دومی به این صورت است.
posts_per_page' => , 'offset' => این دو متن به ثورت پیش فرض در قالب من به صورت زیر بوده:
posts_per_page' => 4
posts_per_page' => 4, 'offset' => 4
بوده ولی از آنجایی که من تعداد بیشتری در صفحه اول می خواستم ، آن را به صورت زیر تغییر دادم:
posts_per_page' => 8
posts_per_page' => 8, 'offset' => 4
اما در قسمت پایینی لیست محصولات ، 4 محصول تکرار می شد و همچنین فاصله بین محصولا برجسته با محصولات معمولی زیاد بود
برای همین در نهایت کد ها رو به صورت زیر تغییر دادم اینگونه همان تعداد محصول دارم و محصولی هم تکرار نشده و فاصله هم مناسب است.
posts_per_page' => 8, 'offset' => 6
اما همانطور که گفتم این ها در هر قالبی بسته به اعصاب طراح قالب ، متفاوته!!