Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+41 votes
22.5k views
in Plugins by
edited by

I noticed that a lot of questions get asked here by site owners how to add small bits of content to their site. The usual answer is to make an advanced theme, but that can be a bit much just to add a few modules here and there.

So I've made a new plugin that allows you to put any content anywhere (almost). You just click "add a new widget" then choose what position on the page it should go (e.g. header, sidebar, after the question text) and what pages it should be displayed on (e.g. question pages, recent questions, user pages etc). Then enter whatever HTML you want.

Thanks for the great comments and feedback!

by
edited by
I was speaking with Lancomega, and we both have the same problem (maybe with an old theme we are sharing) - So I don't know if it's me but I got this when I tried to run the plugin =>
Warning: require(/home/numeroco/public_html/odlg.org/qa-include/qa-install.php) [function.require]: failed to open stream: No such file or directory in /home/numeroco/public_html/odlg.org/qa-include/qa-index.php on line 158

Fatal error: require() [function.require]: Failed opening required '/home/numeroco/public_html/odlg.org/qa-include/qa-install.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/numeroco/public_html/odlg.org/qa-include/qa-index.php on line 158
by
I found the solution, I was because I deleted the qa-install.php for more "security"... a bit stupid. ;-)
by
I ran into the same issue, and read your comment here.

I have since re-uploaded the qa-install.php file,   but it has not fixed the problem.


Can i ask what you did to solve this?
by
Thank you for the plugin.

12 Answers

+3 votes
by

Thanks for making this available.

I've found that there doesn't seem to be a way to delete the widget after creating it. Also, it seems a bit buggy when I put the following code in a widgt in the sidebar:

 

<html>
<head>
<style type="text/css">
.container { width: 175px; border: 1px solid #f7c; }
.textareaContainer { display: block; border: 3px solid #38c; padding: 10px; }
textarea { width: 100%; margin: 0; padding: 0; border-width: 0; }

</style>
</head>
 
<body>
<div class="container">
    <br><B>Write your question here:</b><br><br>

<FORM METHOD="POST" ACTION=http://www.example.com/ask>
    <label class="textareaContainer">
        <textarea rows="2" cols="19" name="title"></textarea>
    </label>
</div>
<span class="button">
<INPUT  NAME="doask1" VALUE="Ask..." TYPE="submit" style="float: none; display: block; width: 100px; height: 30px; padding: 5px; margin: 15px auto; background: #ffd012; border-color: #ff7f00; text-align:center;">
</span>
</FORM>
</body>
</html>

 

It chops the last few lines off and displays a phanom button where it doesn't belong.

by
Good point about deleting them...I'll add that in today.

As for the code you posted, you have html, head and body tags in there. You can't add that inside another page because it already has those tags. You end up with <html><head>...</head><body>... <html><head>... and so on.

So take out html, head and body tags and you will be fine. The style tag still works without a head tag.
by
Yes, thanks for your help with this.

I looked at the source and figured out what was happening. Basically, as you said, there was a </html> tag midway in the page and it messed everything up.

The problem is that I can't modify the widgets, because the page is messed up, and I can't remove the widgets either, because it's not an option yet.

I'll wait till you release the new version and try then. Thanks for this plugin anyway!
by
Hi jimduggan, don't know if you saw the recent version with the delete function, but anyway I have a newer version now with the delete and other stuff as well so check it out :)
+2 votes
by
Is it possible to put different content & HTML on my category pages by using this add on?
by
Hmm, not sure. I am using the same list of templates that Q2A uses elsewhere. There is one called "Browse categories" which I think is what you want. Give it a try and let me know :)
by
Hehe.. Hey DisgruntledGoat !! Can you help me with one more query ? I just wanted to know what to do so that I can stop displaying category list in the sidepanel on every page. I have huge list of category & they are taking so much space in sidepanel which i want to utilize for other better things.  Please make me understand at my level. I am not code guru like you :)
by
If you're using an advanced theme you can override the sidepanel function and remove this line:
$this->nav('cat', 1);

Or, just remove it from qa-include/qa-theme-base.php
0 votes
by
Please add "Home" Position
by
What is "home position"?
by
Homepage frist Page on the Side.
Over or under the Questions ?
I need a text on the home Side under the Questions.
NOT Custom Home !!
by
Hi ChrisX, you should be able to do this in the latest version by selecting "Main area - Top" for the position and ticking "Recent questions and answers" for the page to display.
0 votes
by
hi,

can you add a Position on a Question ? With Question ID ?

 

I will add in a special Question a HTML Layer under the Question Text ^^

i have the Question ID ;)
by
Not at the moment but it's a good idea, I might add that in the future.
by
very coool Thanks :D
0 votes
by
edited by

Hi, I installed this on the latest Q2A (1.5.2) with WP integration (using WP 3.3.2). I'm also using PHP 5.3 . The database initialization works fine, but when I go to the plugins page and click "add widget", it goes to a blank page.


The blank page has this url: http://site.com/qa/admin/widgetanyw

 

Edit: I got this in my error log:

 

 

[Thu Jun 14 00:52:54 2012] [error] [client 1xx.xx.xx.xx] Failed lo
ading /usr/php/53/usr/lib64/php/modules/ZendGuardLoader.so:  /usr
/php/53/usr/lib64/php/modules/ZendGuardLoader.so: undefined symbol
: gc_remove_zval_from_buffer, referer: http://site.com/qa/admin/plugins
 

 

Any clue how to fix this up? I'm not very familiar with this, I'd appreciate any help. Thanks :)

by
I don't think the error is related to me plugin, not directly anyway. It is just plain PHP code, no Zend stuff in there.

I don't know if it would be the Wordpress integration, but there is very little user-based code there. Try commenting out the first two lines in the process_request function (lines 106-107). Let me know if that fixes it. Note this will allow access to any user, but if that is the problem then I can find a solution.
by
Hi, thanks for the reply,

commenting out line 106-107 solved the problem.

So what should I do next?
by
First, double check if a regular user can access /qa/admin/widgetanyw because it may block them anyway due to the URL being under admin. The page will probably be accessible to Moderators and above though.

I will see if I can find a solution.
by
Fortunately, regular users are still blocked from accessing the page.

Thank you very much, I really appreciate it :)
by
Same issue.. its not working.  Nothing is being displayed :(
+1 vote
by
Thanks scott for your great plugin. I was using this plugin and it is very helpful for my site.

If u trying to upgrade the version I would like to give some of my opion, which I was trying but fail to do so.

I hope it would be great if there is another option for permission.

for example :-

Anonymous - Which can be seen by the users who are not login.

Register User - Which can be seen by the Register User only.

Expert -

Moderator -

Admin -

................ so on.
by
Nice idea. I think someone else asked about showing a widget based on points, so I may add this in the future.
0 votes
by
Excellent work.

Is it possible to use php code in the widget. Basically, I want to pull a question by ID either using MySQL or Q2A's inbuilt function and display it over there.
by
No, that's not possible - it accepts HTML only. If you know PHP you should write your own custom plugin anyway, see http://www.question2answer.org/plugins.php for details.
0 votes
by
Hi,

is it possible to modify the plugin in order to show a certain content depending on user agent string (for adsense mobile)?

How modify it?

 

Thank you in advance
+1 vote
by

Thank you great plugin. I used this plugin at Announcement field of my site.

Small Tips: How to edit contents by WYSIWYG editor 

0 votes
by
edited by

Improvement request in future version

Q2A Base theme is specifications to output widget contents by widgets() function. Current version outputs contents direct with output() function. Therefore, theme and other plugin cannot customize contents that widget anywhere plugin generated. All may be impossible, but I want you to display widget contents according to specifications of base theme if possible. I hope that this plugin use qa_register_plugin_module('widget' ... ) function OR add array in $this->content['widgets'][$region][$place] without using output() function.

by
Can you give an example of your problem? e.g. how a theme would "customize contents"?

All the plugin does now is literally output the HTML you put in the box. If you want something else, put it in the box :)
by
edited by
Think about the case that wants to add specific class to all widgets. For example, in the case of my FlexArmor1 theme, all widgets are moved and can customize title. This structure is performed by the widgets() function inner base theme. All widgets made based on the rule of Q2A widget can include those feature. However, because widget anywhere plugin outputs content direct without using widgets() function, we can not give these feature to content that widget anywhere plugin generated.
http://askive.cmsbox.jp/demo/flexarmor1/document-35-design
0 votes
by
edited by
Hello Scott.

Thank you for your plugin!

You know how to remove a widget from a specific category or specific question?

Using the widget pages of all questions, but not for a specific question. If you need to remove pages that violate the rules of ad network.

I asked a question about it: http://www.question2answer.org/qa/52365/

I suggest adding this option in the future. :)

Thanks!
by
I posted a possible solution on the other question.

With regards to this plugin, I'm actually looking to move the idea into core, so instead of the miscellaneous "Custom HTML in..." options in Admin > Layout, you can simply create whichever snippets you like. But that will probably be simple and not have category customisation.
+1 vote
by

Scott yes Thank you for the plugin, very helpful, Question, is it possible to use PHP within the widget instead of HTML?

Let me just explain what I want to do, perhaps you have a better approach anyway, I want a few widgets spread around my page that will read information from a txt or xml file with some information that I tent to update accross a network of sites (not only Q2A site). I also thought about using JavaScript, but in the case of your widget, do you have any suggestion?

Thanks again!

by
No it's not possible to use PHP in the widget. If you know PHP you should make your own widget plugin, it's quite simple: http://docs.question2answer.org/plugins/modules-widget/
by
@Scott One issue with custom widget is that Q2A does not show the option to place them on custom pages, where as in your plugin widget-anywhere this is possible. Is it normal behaviour or something wrong with my site?
by
@arjunsuresh I actually just added that functionality last week! So it will be in v1.8.
by
Thanks Scott :)
...