Bạn là chuyên gia trong lĩnh vực bạn đam mê! Đăng ký ngay, biến kiến thức của bạn thành sức mạnh lan tỏa cộng đồng!
1,876 views
0 votes
0 votes

Khi sử dụng Q2A xây dựng trang hỏi đáp, có những bài viết chứa hình ảnh. Muốn hiện ảnh thumnail thì phải làm thế nào?

User Avatar
by Editor
3.1k points

Please log in or register to answer this question.

1 Answer

1 vote
1 vote

 Vì trong các câu hỏi, thường có kèm ảnh ( ảnh từ website khác hoặc hình ảnh đính kèm ), để hiện lên ảnh thumbnail ở ngay danh sách câu hỏi / trả lời cần thực hiện chỉnh code giao diện như sau:

1. Sửa file qa-theme/tên-theme-dang-dung/qa-theme.php

Tìm từ:

public function attribution()

Thêm bên trên đó:

// new thumb
     public function q_list($q_list)
{

    if (!empty($q_list['qs'])) { // first check it is not an empty list and the feature is turned on
        // Collect the question ids of all items in the question list (so we can do this in one DB query)
        $postids = array();
        foreach ($q_list['qs'] as $question)
        {
            if (isset($question['raw']['postid']))
                $postids[] = $question['raw']['postid'];
        }

        if (!empty($postids)) {

            // Retrieve the content for these questions from the database and put into an array fetching
            // the minimal amount of characters needed to determine the string should be shortened or not

            $result   = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);
            $postinfo = qa_db_read_all_assoc($result, 'postid');

            // Get the regular expression fragment to use for blocked words and the maximum length of content to show
            $blockwordspreg = qa_get_block_words_preg();

            // Now add the popup to the title for each question
            foreach ($q_list['qs'] as $index => $question)
            {
                if (isset($postinfo[$question['raw']['postid']])) {
                    $thispost = $postinfo[$question['raw']['postid']];
                    $text     = qa_viewer_html($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));

                    // Extract image source from content
                    preg_match_all('/<img[^>]+src=[\'"]([^\'"]+)[\'"][^>]*>/i', $text, $matches);

                    // If content has image than show it!
                    if (!empty($matches[0])) {

                        // assign image to the variable
                        $image                           = '<img src="' . $matches[1][0] . '" alt="image" class="q-list-image" width="50"/>'; // change the size using attr or css
                        $q_list['qs'][$index]['content'] = $image;
                    }
                }
            }
        }
    }

    qa_html_theme_base::q_list($q_list);
}
   // end thumb @netdepviet

Save lại rồi upload lên server & tinh chỉnh lại phần CSS cho hợp lý là đẹp rồi.

edited by
User Avatar
by Editor
5.7k points
Cảm ơn bạn đã đóng góp những câu hỏi và câu trả lời giá trị về vẻ đẹp Việt Nam trong suốt thời gian qua. Để nâng tầm trải nghiệm và giúp di sản Việt vươn ra quốc tế, toàn bộ dữ liệu và hoạt động hỏi đáp sẽ được chuyển về chuyên mục Travel Guide và Heritage & Stories tại website chính thức. Trang web này sẽ dừng hoạt động, nhưng những giá trị bạn chia sẻ sẽ tiếp tục "toả sáng" tại địa chỉ mới với công nghệ AI hỗ trợ 3 ngôn ngữ (Anh - Việt - Trung). Khám phá Việt Nam nguyên bản: https://netdepviet.org

138 questions

120 answers

4 comments

72 users

Related questions

1 answer
1 vote
1 vote
77.2k views
1 answer
0 votes
0 votes
46.4k views
1 answer
0 votes
0 votes
4.9k views
0 answers
0 votes
0 votes
1.2k views
0 answers
–1 vote
–1 vote
703 views
Since © 2006 Netdepviet.org All rights reserved. Forum | Privacy Policy | Pictures