Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter mmkh

    (@mmkh)

    code 2

    <?php
    // if ( is_category() || is_tag() ) {
    // $current_term = get_queried_object();
    //
    // // آرگومان‌های WP_Query برای دریافت پست‌های مرتبط با ترم جاری
    // $args = [
    // 'post_type' => 'post',
    // 'post_status' => 'publish',
    // 'tax_query' => [
    // [
    // 'taxonomy' => $current_term->taxonomy,
    // 'terms' => $current_term->term_id,
    // 'field' => 'term_id',
    // ],
    // ],
    // 'posts_per_page' => -1,
    // 'cache_results' => false,
    // 'update_post_meta_cache' => false,
    // 'update_post_term_cache' => false,
    // 'suppress_filters' => false,
    // ];
    // //
    // // اجرای کوئری با استفاده از WP_Query
    // $query = new WP_Query( $args );
    //
    // // شمارش پست‌ها بر اساس نویسنده
    // $authors = [];
    // if ( $query->have_posts() ) {
    // while ( $query->have_posts() ) {
    // $query->the_post();
    //
    // $author_id = get_the_author_meta( 'ID' );
    // if ( isset( $authors[ $author_id ] ) ) {
    // $authors[ $author_id ]++; // افزایش تعداد پست‌ها
    // } else {
    // $authors[ $author_id ] = 1; // شروع شمارش
    // }
    // }
    // wp_reset_postdata(); // بازنشانی وضعیت پس از کوئری
    // }
    //
    // // مرتب‌سازی نویسندگان بر اساس تعداد پست‌ها
    // arsort( $authors );
    //
    // // نمایش اطلاعات نویسندگان
    // if ( ! empty( $authors ) ) {
    // foreach ( $authors as $author_id => $post_count ) {
    // $user = get_userdata( $author_id );
    //
    // if ( $user ) { // بررسی معتبر بودن نویسنده
    // ?>
    <!-- <div class="author-box">-->
    <!-- <a href="--><?php //echo esc_url( get_author_posts_url( $author_id ) ); ?><!--">-->
    <!-- <div class="author-info">-->
    <!-- <div class="author-avatar">-->
    <!-- <img src="--><?php //echo esc_url( get_avatar_url( $author_id ) ); ?><!--" alt="--><?php //echo esc_attr( $user->display_name ); ?><!--" />-->
    <!-- </div>-->
    <!-- <div class="author-name">-->
    <!-- <h3>--><?php //echo esc_html( $user->display_name ); ?><!--</h3>-->
    <!-- </div>-->
    <!-- </div>-->
    <!-- </a>-->
    <!-- <p>--><?php //echo esc_html( $user->first_name ); ?><!-- تا کنون <span>--><?php //echo esc_html( $post_count ); ?><!--</span> پست نوشته است.</p>-->
    <!-- <a href="--><?php //echo esc_url( get_author_posts_url( $author_id ) ); ?><!--">-->
    <!-- <button>مشاهده پست‌های --><?php //echo esc_html( $user->display_name ); ?><!--</button>-->
    <!-- </a>-->
    <!-- </div>-->
    <!-- --><?php
    // }
    // }
    // } else {
    // echo '<p>هیچ نویسنده‌ای برای این دسته‌بندی یا برچسب وجود ندارد.</p>';
    // }
    // }
    // ?>

    Neither of these two solutions requires Kurdish in the function file (unlike the first solution).

    😊

    Thread Starter mmkh

    (@mmkh)

    code 1

    <?php
    if ( is_category() || is_tag() ) { // بررسی اینکه آیا در صفحه آرشیو دسته‌بندی یا برچسب هستیم
    $current_term = get_queried_object(); // گرفتن شیء دسته‌بندی یا برچسب فعلی

    global $wpdb;

    // کوئری برای دریافت نویسندگان و تعداد پست‌های هر نویسنده در دسته‌بندی یا برچسب جاری
    $sql = "
    SELECT p.post_author, COUNT(p.ID) AS post_count
    FROM $wpdb->posts p
    INNER JOIN $wpdb->term_relationships tr ON p.ID = tr.object_id
    INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
    WHERE tt.taxonomy = %s
    AND tt.term_id = %d
    AND p.post_status = 'publish'
    GROUP BY p.post_author
    ORDER BY post_count DESC
    ";

    // اجرای کوئری برای دریافت نویسندگان و تعداد پست‌ها
    $results = $wpdb->get_results( $wpdb->prepare( $sql, $current_term->taxonomy, $current_term->term_id ) );

    // بررسی اینکه آیا نتایجی داریم
    if ($results) {
    foreach ($results as $row) {
    $author_id = $row->post_author;
    $post_count = $row->post_count;
    $user = get_user_by('ID', $author_id);

    ?>
    <div>
    <div>
    <a href="<?php echo get_author_posts_url($author_id); ?>">
    <div>
    <!-- نمایش تصویر نویسنده -->
    <div class="author-avatar">
    <img src="<?php echo get_avatar_url($author_id); ?>" alt="<?php echo esc_attr($user->display_name); ?>" />
    </div>
    <img src="<?php echo get_avatar_url($author_id); ?>" alt="<?php echo esc_attr($user->display_name); ?>" />
    </div>
    </a>
    <div>
    <a href="<?php echo get_author_posts_url($author_id); ?>">
    <h3><?php echo esc_html($user->display_name); ?></h3>
    </a>
    <p><?php echo esc_html($user->first_name); ?> تا کنون <span> <?php echo esc_html($post_count); ?> </span> محتوا نوشته!</p>
    </div>
    </div>
    <div>
    <a href="<?php echo get_author_posts_url($author_id); ?>">
    <button>
    سایر محتوا های <?php echo esc_html($user->first_name); ?> را بخوانید
    <!-- curve left and right -->
    <div><div><span></span><span></span></div></div>
    <div><div><span></span><span></span></div></div>
    </button>
    </a>
    </div>
    </div>
    <?php
    }
    } else {
    echo 'هیچ نویسنده‌ای برای این دسته‌بندی یا برچسب وجود ندارد.';
    }
    }
    ?>
    Thread Starter mmkh

    (@mmkh)

    Hello, thank you for your answer, but it still didn’t work, but I solved it, of course, with my own method, hoping that this answer will help someone in the future. I will write the solution below. I will write two solutions. One directly retrieves information from the database. This is faster than the second method, but its security and compatibility with WordPress will be less in the future. So if you are looking for a more attractive solution, use the first code, and if you are looking for a more reliable solution, use the second code.

    Thread Starter mmkh

    (@mmkh)

    Hi threadi, I hope you are doing well. Unfortunately, I tried to figure out what to do but I didn’t really get it. I realize this is taking up a lot of your time, but I was wondering if you could be kind enough to implement (place) what you mean in my code itself? That way I might understand what you mean and figure out where my problem was.

    Thread Starter mmkh

    (@mmkh)

    Hi bcworkz
    Thanks for your help. The code snippet you wrote for my first problem was great and worked! 😊
    However, despite your help, I still couldn’t find an answer and solution for the second part. Could you please help me further? If necessary, I need to explain my problem in a different way. Thanks.

    Thread Starter mmkh

    (@mmkh)

    Hello, I hope you are well
    First of all, thank you very much for taking the time to review and also thank you very much for your free and good plugin and I hope you improve more every day
    Regarding the problem that has arisen for me, I must say that I am using the latest version you have released (1.1.4) and my WordPress is also completely up to date (6.7.1) Regarding the template, I am using a custom template that I am coding myself and I can assure you that there is no problem
    Regarding your plugin, I just tested it on my localhost with the default template and without any other active plugins using the plugin shortcode! But it did not work. Below is an image showing my use of the plugin shortcode in the template on the single.php file

    Regarding your IP being blocked, I am very sorry. I am an Iranian and I use an Iranian CDN called Arvancloud, not Cloudflare. However, if this problem persists for you, please let me know so I can see what I can do for it. I hope it is a simple problem and can be solved quickly. Thank you for your time.

Viewing 6 replies - 1 through 6 (of 6 total)