Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
in Themes by


is there any way to show first question image for thumb in question list ?

in this plugin :

Tab Widget by Towhid @ QA-Themes. popular and recent questions in two tabs, responsive design.

first image of question showing as thumb in popular and recent questions widget

so it is possible but can i use this plugin to show thumb in question list below the question title ?

thanks for helping me !


Q2A version: 1.7
thank you very mush ;)
i will waiting for you
hi jatin
sorry, for my message again
do you find any code for this option ?
i realy need that code !
thank you very much
jatin ?  -----------
I will try to write it tonight. lets see if I would be able to get it done today.

1 Answer

+7 votes
selected by
Best answer

So here we go. I have made entire code to get first image from the question content. Add below code to your theme file. Just make sure your theme should not have q_list method. If it is there than you may need to merge both code.

Updated on (2015/03/11)

Added condition to show image only and if the content has at least one image.

Download code from Gist

 * Add first image to the question list
 * Declearation
 * Base code is taken from Mouseover Layer plugin
 * Than I have extracted content using preg_match_all to get first image
 * and assing that to the q_list
 * How to use it:
 * Nothing complicated, just place 'q_list' method into your theme or plugin file and done.
 * Important:
 * Make sure your theme should not have this function already. If there is than add this code
 * to that function and modify as needed
 * @param array $q_list
 * @category Hook
 * @since 1.7
 * @author Q2A Market <dev@q2amarket.com>
 * @link http://www.q2amarket.com Q2A Market
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
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="64"/>'; // change the size using attr or css
                        $q_list['qs'][$index]['content'] = $image;

if there's not image it's showing a square with word "image" in it. It's not showing any uploaded image at all
You ca only populate the code only if image exists by conditionally check if $matches returning the image source.

If you can't do than i will try to add it as will get some time.
I have updated the answer so now it will only show if there is an image in content else it will just show the standard question list item
thank you very much jatin ;)
is there any whay to show a default image for question has no thumb ?
edited by
Big thanks !
you are welcome .. :)
Code seems not working with blobs, becouse URL of image is "/?qa=blob&qa_blobid=2277260727839511667" not .jpg. Any way to change that, so it would work with thumnails ? I gues i need to change preg_match_all part, but i don't know regex code...
Oh yeah, I haven't tested or considered it. I will try to update it when get bit time. However, you can try by checking if content containing blob id than you can try to extract it.

Let me know if the logic works in case if you are trying on it
reshown by
Works perfectly, thanks alot: http://2outof10wouldnotbang.com
How to make it only apply to the questions list and related questions list, and not other lists such as the hidden-content list in admin backend?
How to embed this file into my current qa-theme ( Snow / Snowflat ) ?

Thanks for your support
Get terminal access and edit the qa-theme.php file, ie:

vim qa-theme/SnowFlat/qa-theme.php

Look for the following:

class qa_html_theme extends qa_html_theme_base

Paste the code above as an additional function inside the qa_html_theme class. All the other changes that I did (size & positioning, ie what can be seen at http://2outof10wouldnotbang.com) was done via CSS.
I saw your site . It sounds good. But I still in stuck with the CSS customization
thank you very much jatin.soni
Glad....You are welcome....!
where to add this code? I use Classic theme
its not working with blobs , @jatin can you help me plz