Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
2.4k views
in Plugins by
I am trying to build a plugin that will allow me to insert content, like html to the bottom of specific (meaing that the content is unique to that question page) answer page. I tried using http://www.question2answer.org/qa/15066/new-plugin-widget-anywhere-beta-help-suggest-new-positions this plugin, however it posts the same content on all pages.

I have also done some further reading on plugins with $request but am afraid that i don't seem to understand. Doesn't the data need to be stored in the database and then pulled?

I have been working on this for a long time and really need this to work ASAP. I am willing to pay to build this plugin for me, if need be.

Thank you,

Anthony
by
I can not say that I have a real solution available, but there may be a workaround: If You dont need comments on answers You could reuse them for Your needs: You could set in admin/permissions allow comments to the highest level, editors and admins. So only You would have access to write comments.
In a second step You would have to modify Your advanced theme that way, that comments are shown seperately under the answers. Hope that helps a bit. I am sure there will be a plugin in the future, but until that time a workaround could do that.

1 Answer

0 votes
by

You are correct; I have indeed found a workaround with a great plugin by DisgruntledGoat (can be found here: Widget Anywhere), thank you, and the following steps and code:

First, I created a Database on my server (through cPanel)

Then, I added the following code, in the qa-wa-layer.php file (in the position i wanted), 

$con = mysql_connect("localhost","HERE GOES YOUR DB USER NAME","HERE GOES YOUR DB USERNAME PASSWORD");
        if ($con){
            mysql_select_db("HERE GOES YOUR DATABASE NAME", $con);
            $contentID = qa_request_part(0); //gives unique number of the question
            $sql = "SELECT TEXT FROM after_content WHERE ID = ".$contentID;
            $result = mysql_query($sql);
            $temp = mysql_fetch_row($result);
            $result = $temp[0];
            $this->output($result);        
        }

N.B. The "proper way" of coding the above would be to have the "$con" be written like

if (!$con){

die('Could not connect: ' . mysql_error());

} else {
            mysql_select_db("HERE GOES YOUR DATABASE NAME", $con);
            $contentID = qa_request_part(0); //gives unique number of the question
            $sql = "SELECT *FIELD* FROM  *TABLE NAME* WHERE ID = ".$contentID;
            $result = mysql_query($sql);
            $temp = mysql_fetch_row($result);
            $result = $temp[0];
            $this->output($result);        
        }

I avoided using the correct code because i didn't want my users to see the error if there was a connection failure to the secondary db.

The above code was added inside the "function a_list($a_list)" (because i wanted the content to be displayed after the answers) this can be demonstrated here: How long does creatine stay in your system. (after the answers and headed "Additional Information").

Crucial parts of how the code works:

DATABASE: I created a database and then a table within the database with two fields: ID and CONTENT. The ID as integer and the CONTENT as text.

CODE: $contentID = qa_request_part(0);  this part of the code will fetch the unique number which is assigned to the url (given the structure of your URLS are structured using the first option under the 'General' tab in the Admin section of Q2A).

Also, where it is indicated, you need to substitute those sentences with your values and also remove the * at same time when filling in your values in the $sql = "SELECT section.

CON: To enter data into the database you need to login to cPanel and then fill in the fields. I am currently working on a way to add this to the Admin section (any support would be appreciated).

Cheers!

...