رفتن به مطلب

نمایش بیشترین بازدید ها در مدت خاص


پست های پیشنهاد شده

سلام دوستان من می خوام تو یه قسمت از قالب بیشترین بازدید های هفته رو نشون بده ام اونم بر اساس بازدید نه دیدگاه

لینک به ارسال

با استفاده از افزونه wp-postviews میتوانید از کد زیر استفاده کنید :


<?php
$args = array(
'date_query' => array(
array(
'column' => 'post_date_gmt',
'after' => '1 week ago',
),
),
'post_type' => 'post',
'posts_per_page' => 6,
'orderby' => 'meta_value_num',
'meta_key' => 'views',
'order' => 'DESC',

);
$my_query = new WP_Query( $args );
while ($my_query->have_posts()):
$my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<a href="<?php the_permalink(); ?>" target="_blank" title="<?php the_title(); ?>"><?php the_title(); ?></a><br />
<?php endwhile; ?>
<?php wp_reset_query(); ?>

در قسمت after' => '1 week ago', به جای week میتوانید year و یا ... قرار بدید .

در قسمت 'posts_per_page' => 6, میتوانید تعداد نمایش مطالب را مشخص کنید .

  • امتیاز 1
لینک به ارسال

با استفاده از افزونه wp-postviews میتوانید از کد زیر استفاده کنید :


<?php
$args = array(
'date_query' => array(
array(
'column' => 'post_date_gmt',
'after' => '1 week ago',
),
),
'post_type' => 'post',
'posts_per_page' => 6,
'orderby' => 'meta_value_num',
'meta_key' => 'views',
'order' => 'DESC',

);
$my_query = new WP_Query( $args );
while ($my_query->have_posts()):
$my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<a href="<?php the_permalink(); ?>" target="_blank" title="<?php the_title(); ?>"><?php the_title(); ?></a><br />
<?php endwhile; ?>
<?php wp_reset_query(); ?>

در قسمت after' => '1 week ago', به جای week میتوانید year و یا ... قرار بدید .

در قسمت 'posts_per_page' => 6, میتوانید تعداد نمایش مطالب را مشخص کنید .

ممنون چیزی نشون نمیده

من برای نمایش بازدید هر پست از این کد استفاده می کنم ایا راهی هس با این کد ستش کنیم


function set_post_views( $postID )
{
$count_key = 'views';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
// delete old 'post_views_count' value.
delete_post_meta( $postID, $count_key );
// add new 'post_views_count' value.
add_post_meta( $postID, $count_key, '0' );
} else {
$count++;
// update old 'post_views_count' value.
update_post_meta( $postID, $count_key, $count );
}
}
function get_post_views( $postID )
{
$count_key = 'views';
$count = get_post_meta( $postID, $count_key, true );
if($count=='') {
// delete old 'post_views_count' value.
delete_post_meta( $postID, $count_key );
// add new 'post_views_count' value.
add_post_meta( $postID, $count_key, '0' );
return "0";
}
return $count.' ';
}

و این رو داخل single قراردادم


<?php set_post_views (get_the_ID()); ?>

لینک به ارسال

چیزی رو که می خواستم پیدا کردم


<?php
function filter_where($where = ”) {
//posts in the last 7 days
$where .= " AND post_date > '" . date(‘Y-m-d’, strtotime('-7 days')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts('post_type=post&posts_per_page=7&orderby=comment_count&order=DESC');
while (have_posts()): the_post(); ?>
<a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a>
<?php
endwhile;
wp_reset_query();
?>

برای دوستانی که شاید روزی به کارشون بیاد ;):D

ویرایش شده توسط reza_yki
لینک به ارسال
  • 1 ماه بعد...

دوستان ببخشید که این تاپیک رو بالا اوردم یه مشکل دارم

اونم اینه که من می خوام بیشترین بازدید های یک هفته گذشته رو نشون بدم با کد @محمدرضا این کار تقریبا انجام میشه ولی اون نوشته هایی میاد که تو یه هفته گذشته ثبت شده ولی من میخوام اگه بازدید یک پست که واسه یک سال پیش هست

ولی تو این هفته خیلی بازدید داشت نشون داده بشه نمی دونم منتظورم رو تونستم برسونم یا نه

خودم از این کد استفاده میکنم ولی اونم همون کار کد محمدرضا میکنه:


function filter_where( $where = '' ) {
//posts in the last 7 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts('post_type=post&posts_per_page=7&orderby=meta_value_num&meta_key=views&order=DESC');
محتوا
endwhile; remove_filter( 'posts_where', 'filter_where' ); wp_reset_query();

لینک به ارسال

لطفا برای ارسال دیدگاه وارد شوید

شما بعد از اینکه وارد حساب کاربری خود شدید می توانید دیدگاهی ارسال کنید



ورود به حساب کاربری
×
×
  • اضافه کردن...