انجمن


پربازدیدترین مطالب سایت  (۴ نوشته)

  • saman2lak

    آفلاین
    عضو
    تعداد نوشته‌ها: ۱۵
    # نوشته شده: ۱۰ سال پیش
    ۶ مرداد ۱۳۹۲ - ۱۳:۳۸

    سلام
    میخوام برای بخش پربازدیدترین مطالب سایتم
    مطالب به صورت پربازدیدترینهای مــــاه نشون داده بشه
    الان بصورت سالیانه هست

    کسی بلده کمکم کنه
    مرسی

  • mortezq21

    آفلاین
    عضو
    تعداد نوشته‌ها: ۹۳
    تشکر شده: ۳۶ بار
    # نوشته شده: ۱۰ سال پیش
    ۶ مرداد ۱۳۹۲ - ۱۷:۵۶

    سلام
    فایل فانکشن

    function getPostViews($postID){
        $count_key = 'post_views_count';
        $count = get_post_meta($postID, $count_key, true);
        if($count==''){
            delete_post_meta($postID, $count_key);
            add_post_meta($postID, $count_key, '0');
            return "0 View";
        }
        return $count.' Views';
    }
    function setPostViews($postID) {
        $count_key = 'post_views_count';
        $count = get_post_meta($postID, $count_key, true);
        if($count==''){
            $count = 0;
            delete_post_meta($postID, $count_key);
            add_post_meta($postID, $count_key, '0');
        }else{
            $count++;
            update_post_meta($postID, $count_key, $count);
        }
    }

    فایل سینگل

    setPostViews(get_the_ID());

    محل نشان دادن پستها در قالب

    <ul>
    
    <?php
    function filter_where($where = '') {
        //posts in the last 30 days
        $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
        return $where;
    }
    add_filter('posts_where', 'filter_where');
    
    query_posts('post_type=post&posts_per_page=10&orderby=comment_count&order=DESC');
    
    while (have_posts()): the_post(); ?>
    
    <li><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr('Permalink to %s'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a></li>
    
    <?php
    endwhile;
    wp_reset_query();
    ?>
    
    </ul>
    کاربران زیر به‌خاطر این نوشته تشکر کرده‌اند:
    saman2lak
  • saman2lak

    آفلاین
    عضو
    تعداد نوشته‌ها: ۱۵
    # نوشته شده: ۱۰ سال پیش
    ۷ مرداد ۱۳۹۲ - ۰۰:۵۱

    mortezq21 گفت:
    سلام
    فایل فانکشن

    function getPostViews($postID){
        $count_key = 'post_views_count';
        $count = get_post_meta($postID, $count_key, true);
        if($count==''){
            delete_post_meta($postID, $count_key);
            add_post_meta($postID, $count_key, '0');
            return "0 View";
        }
        return $count.' Views';
    }
    function setPostViews($postID) {
        $count_key = 'post_views_count';
        $count = get_post_meta($postID, $count_key, true);
        if($count==''){
            $count = 0;
            delete_post_meta($postID, $count_key);
            add_post_meta($postID, $count_key, '0');
        }else{
            $count++;
            update_post_meta($postID, $count_key, $count);
        }
    }

    فایل سینگل

    setPostViews(get_the_ID());

    محل نشان دادن پستها در قالب

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

    واسه جدیدترین مطالب هم کمکم میکنی دوسته من ؟ :)

  • mortezq21

    آفلاین
    عضو
    تعداد نوشته‌ها: ۹۳
    تشکر شده: ۳۶ بار
    # نوشته شده: ۱۰ سال پیش
    ۸ مرداد ۱۳۹۲ - ۱۹:۵۴

    از این کد برای آخرین مطالب استفاده کنید.

    <?php
    $my_query = new WP_Query('showposts=10&cat=category  ID');
    while ($my_query->have_posts()):
    $my_query->the_post();
    $do_not_duplicate = $post->ID;?>
     <a href="<?php the_permalink() ?>"><?php the_title(); ?></a></br>
    <?php endwhile; ?>

    اگر خواستی مطالب دسته خاصی رانشان دهی آی دی دسته را در قسمت category جایگزین کن و اگر خواستی آخرین مطالب منتشر شده را نشان دهی category را از کد حذف کن.

    کاربران زیر به‌خاطر این نوشته تشکر کرده‌اند:
    saman2lak

درباره‌ی این موضوع



برچسب‌ها

هیچ برچسبی نیست.