Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
190 views
in Q2A Core by
edited by

By default I can create feed for questions or for question's answers (without full question content).

I've found that I can change feed output in /qa-include/qa-feed.php

There is a function called qa_feed_load_ifcategory(), but despite of my poor php skills I figured out that it can either output question itself or the answer. All my tries of merging them together finished without any luck.

This is basic illustration of what I want to get in my feed:

1) Question 1 title
Question 1 content
Question 1 answer 1
Question 1 answer 2
Question 1 answer 3
-----
-----
2) Question 2 title
Question 2 content
Question 2 answer 1
Question 2 answer 2
Question 2 answer 3

-----
-----
etc...

When last parameter is passed to qa_feed_load_ifcategory(), which is $questionselectspec, the full question content is pushed away. Instead answer is added. I want to have them both.

Ofcourse, I could make some kind of workaround with my own code, but I don't want to do any crutches whith horrible piece of shit-like code.

Is there a way to achieve this through Q2A standard methods?

Q2A version: 1.8.3
by
If you do a MySQL query and display the results in XML format (instead of regular HTML format) , then you have a feed.

A normal RSS feed format contains such information like <title>, <link>, <pubDate>, <description>.

I'm not sure what your real purpose of feed modification is. But I guess you may want to display it in your Wordpress installtion.

So you have to put all the answers and comments and stuffs in to <description> tags.

Because your ideas will include extra variables like the answers content, answer postid,... or maybe you want to display author names and avatars too, you may not achieve this merely editing a few lines in core files. You have to write layout to display all these things.
by
Nah... implementing wordpress for this task is way too much.

What I'm trying to do is to add my website to Yandex Turbo Pages (the same as Google AMP, but for Yandex).

And they need special xml feed for this.

But all I can do now is feed them with trimmed content in xml, but rss feed in this situation has to represent the same content, as the normal website page.

1 Answer

0 votes
by

I didn't want to do it, but I had to radically change /qa-include/qa-feed.php code.

There are two functions in /qa-include/app/posts.php, which are:

  • qa_post_get_full() - gets the full question content by its id;
  • qa_post_get_question_answers() - gets all answers by the question id.
These functions are already available in qa-feed.php.
The only thing left unsolved is how to load more than 50 questions without performance issues.
by
bigboy, I also struggle with this problem that I just did not try it, nothing happens. If you can find how to solve the problem, please share the solution. If I find it, I'll write it too.
by
I'll write a plugin later, if I'll have time.

I can show you how I did it for now, but If you're not a programmer you will struggle a lot. But, you can try.

(!!!)
This example below IS NOT THE RIGHT SOLUTION and a really bad practice. It does not completely cover the issue and changes core files, which must to be avoided, so make backups in case something will go wrong. It's not something I would ever recommend doing. It is done only in test purposes, I'm still learning PHP and Q2A as well.
(!!!)

Go to /qa-include/qa-feed.php file.

Inside foreach ($questions as $question) section, approximately on 405 line add:

    $qcontent = qa_post_get_full($question['postid']);
    $acontent =  qa_post_get_question_answers($question['postid']);

Now, $qcontent variable contains all question data, while $acontent - holds all answers on particular question.

Then you have to comment every $lines variable and also comment this line:

//echo implode("\n", $lines);

This has to be done, because by default Q2A is printing feeds in a way Yandex Turbo will not understand. So you have to rewrite the output of qa-feed.php.

In order to debug you can print our arrays like this:
print_r($qcontent);
print_r($acontent);

You will see everything inside those arrays and will be able to print them as Yandex expects - https://yandex.ru/dev/turbo/doc/rss/example-docpage/
by
Thanks, I'll try
by
And be aware of the problem, that standard feed will provide no more than 50 questions, this number is hardcoded in Q2A core files.

So wee need to write a plugin in order to do it right way.
...