vahidd 203 ارسال شده در اسفند 91 گزارش بازنشر ارسال شده در اسفند 91 سلام خدمت اساتیدراستش توی سایتم به صورتی هست که بالای 10 تا پست کوئری دارم، که احساس می کنم سایتم کند شده، تمام این کوئری ها مهم نیستند که خروجی شون هر ماه آپدیت بشه.در کل توی وردپرس چطوری تابع زیر رو مثلا یک هفته کش کنم:<?phpfunction reletad_posts($post) {$tags = wp_get_post_tags($post->ID); if ($tags) { $first_tag = $tags[0]->term_id; $args=array( 'tag__in' => array($first_tag), 'post__not_in' => array($post->ID), 'showposts'=>5, 'ignore_sticky_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <div class="rel_posts_with_post"> <a rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" href="<?php the_permalink() ?>"><?php if ( has_post_thumbnail() ) { ?> <img alt="<?php the_title(); ?>" src="<?php echo $tim_url; ?>?src=<?php echo $image[0]; ?>&h=69&w=98&zc=1" /> <?php } else { ?><img src="<?php echo get_template_directory_uri(); ?>/images/no-thumb.png" /><?php } ?></a> <h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4> </div> <?php endwhile; }}} فکر می کنم لینک های زیر هم راهنماش توی وردپرس هست:http://codex.wordpress.org/Class_Reference/WP_Object_Cachehttp://codex.wordpress.org/Transients_APIhttp://wp.smashingmagazine.com/2012/06/26/diy-caching-methods-wordpress/ نقل قول لینک به ارسال
Parsa 23463 ارسال شده در اسفند 91 گزارش بازنشر ارسال شده در اسفند 91 تست نشده:<?phpfunction reletad_posts($post) { $tags = wp_get_post_tags($post->ID); if ($tags) { $first_tag = $tags[0]->term_id; $args=array( 'tag__in' => array($first_tag), 'post__not_in' => array($post->ID), 'showposts'=>5, 'ignore_sticky_posts'=>1 ); $my_query = get_transient('reletad_posts_'.$post->ID); if ($my_query === false) { $my_query = new WP_Query($args); set_transient('reletad_posts_'.$post->ID, $my_query , 3600 * 24 * 7); } if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <div class="rel_posts_with_post"> <a rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" href="<?php the_permalink() ?>"><?php if ( has_post_thumbnail() ) { ?> <img alt="<?php the_title(); ?>" src="<?php echo $tim_url; ?>?src=<?php echo $image[0]; ?>&h=69&w=98&zc=1" /> <?php } else { ?><img src="<?php echo get_template_directory_uri(); ?>/images/no-thumb.png" /><?php } ?></a> <h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4> </div> <?php endwhile; }}} 4 نقل قول لینک به ارسال
پست های پیشنهاد شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .