Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
5.9k views
in Themes by

Hello,

Several years ago I have created a theme and overwrote the q_item_main function from my theme's qa-theme.php file:

function q_item_main($q_item)
        {
            $this->output('<DIV CLASS="qa-q-item-main">');
            $this->post_avatar($q_item, 'qa-q-item');
            $this->q_item_title($q_item);
            $this->post_meta($q_item, 'qa-q-item');
            $this->q_item_content($q_item);
            
            $this->output('<!--');
            print_r($q_item);
            $this->output('-->');
            $this->output('</DIV>');
            
        }

Today I have updated Q2A to the latest version and the content disappeared. The $q_item array doesn't have content anymore.

I tried to locate a function or file that populates this array, but with no luck...

How can I add content on the main page considering that I can do some php coding?

Thank you!

Q2A version: latest

1 Answer

+2 votes
by

As far as I can see, the qa-theme-base.php still holds the function. By default it is:

    public function q_item_main($q_item)
    {
        $this->output('<div class="qa-q-item-main">');

        $this->view_count($q_item);
        $this->q_item_title($q_item);
        $this->q_item_content($q_item);

        $this->post_avatar_meta($q_item, 'qa-q-item');
        $this->post_tags($q_item, 'qa-q-item');
        $this->q_item_buttons($q_item);

        $this->output('</div>');
    }


So you open the qa-theme.php and insert the code you need, for example: 

    public function q_item_main($q_item)
    {
        $this->output('<div class="qa-q-item-main">');

        $this->view_count($q_item);
        $this->q_item_title($q_item);
        $this->output("<p>Some Text</p>");
        $this->q_item_content($q_item);

        $this->post_avatar_meta($q_item, 'qa-q-item');
        $this->post_tags($q_item, 'qa-q-item');
        $this->q_item_buttons($q_item);

        $this->output('</div>');
    }

qa-theme-base.php holds all the functions you can override via qa-theme.php

 

> How can I add content on the main page considering that I can do some php coding?

Also use the qa-theme.php and override for example:

        // override main to output own html elements and more
        function main() {
            // teaser to ask
            if(!qa_is_logged_in() && ($this->template=='qa' || $this->template=='questions')) {
               $this->output('<p>Ask here...</p>');
            }
            // default call of the original function
            qa_html_theme_base::main();
        }

Hope that helps.

by
Thank you for your response!

This worked in previous versions of Q2A, but not in the latest version for some reason. The $this->q_item_content($q_item); function doesn't return anything because the $q_item array doesn't have content in it.

You can check the source code of this page http://golovoladki.ru - I print out the $q_item for each question and none of them have [content] in it:

Array
(
    [raw] => Array
        (
            [postid] => 2089
            [categoryid] =>
            [type] => Q
            [basetype] => Q
            [hidden] => 0
            [acount] => 1
            [selchildid] =>
            [closedbyid] =>
            [upvotes] => 1
            [downvotes] => 0
            [netvotes] => 1
            [views] => 586
            [hotness] => 37948200000
            [flagcount] => 0
            [title] => Для чего нужен этот предмет из металла
            [tags] =>
            [created] => 1447142085
            [name] =>
            [categoryname] =>
            [categorybackpath] =>
            [categoryids] =>
            [uservote] => 1
            [userflag] => 0
            [userfavoriteq] => 0
            [userid] => 5141
            [cookieid] =>
            [createip] => 171.25.188.179
            [points] => 35
            [flags] => 1
            [level] => 0
            [email] => trebnev@yandex.ru
            [handle] => виктор
            [avatarblobid] =>
            [avatarwidth] =>
            [avatarheight] =>
            [_order_] => 20
        )

    [hidden] => 0
    [tags] => id="q2089"
    [classes] =>
    [url] => ./2089/%D0%BF%D1%80%D0%B5%D0%B4%D0%BC%D0%B5%D1%82-%D0%BC%D0%B5%D1%82%D0%B0%D0%BB%D0%BB%D0%B0
    [title] => <span title="">Для чего нужен этот предмет из металла</span>
    [q_tags] => Array
        (
        )

    [answers_raw] => 1
    [answers] => Array
        (
            [prefix] =>
            [data] => 1
            [suffix] =>  ответ
        )

    [answer_selected] =>
    [views_raw] => 586
    [views] => Array
        (
            [prefix] =>
            [data] => 586
            [suffix] =>  просмотров
        )

    [upvotes_raw] => 1
    [downvotes_raw] => 0
    [netvotes_raw] => 1
    [vote_view] => net
    [vote_on_page] => enabled
    [upvotes_view] => Array
        (
            [prefix] =>
            [data] => 1
            [suffix] =>  ЗА
        )

    [downvotes_view] => Array
        (
            [prefix] =>
            [data] => 0
            [suffix] =>  не интерисует
        )

    [netvotes_view] => Array
        (
            [prefix] =>
            [data] => +1
            [suffix] =>  голос
        )

    [vote_tags] => id="voting_2089"
    [vote_state] => voted_up
    [vote_up_tags] => title="Вы голосовали ЗА - нажмите, чтобы отменить голос" name="vote_2089_0_q2089" onclick="return qa_vote_click(this);"
    [vote_down_tags] =>  
    [meta_order] => ^what^who^where^when
    [what] => загадка
    [when] => Array
        (
            [data] => 10 Ноя, 15
        )

    [who] => Array
        (
            [prefix] => от
            [data] => <a href="./user/%D0%B2%D0%B8%D0%BA%D1%82%D0%BE%D1%80" class="qa-user-link">виктор</a>
            [suffix] =>
            [points] => Array
                (
                    [prefix] =>
                    [data] => 35
                    [suffix] =>  баллов
                )

            [title] =>
            [level] => Зарегистрированный пользователь
        )

    [avatar] =>
)

Thanks again for your help!
by
Well, there is no question content in the question list items. Tip: You can use the plugin mouseover-layer and modify it so that it outputs the content not in the "title" property but below the question. See https://github.com/q2a/question2answer/tree/dev/qa-plugin/mouseover-layer

$q_list['qs'][$index]['title']='<span title="'.qa_html($text).'">'.@$question['title'].'</span>';

becomes

$q_list['qs'][$index]['title'] = @$question['title'].'<br /><span class="yourcssformat">'.qa_html($text).'</span>';

(not tested)
by
Thank you for this tip!
Now I remember that I was tweaking this plugin.

This was the modified code for old Q2A that populates the [content] element: http://pastebin.com/Qf0KKciH

I didn't realize that updating Q2A also updates the plugins, so didn't research the new plugin's code.
So this is the edited latest mouseover plugin's code that populates the content element in $q_list array: http://pastebin.com/CPPMhruN - it works perfectly!

Thanks everyone for the help!
...