Tired of people posting questions without searching? Or asking something that has been answered umpteen times? I was too. So i did this.
(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fimg180.imageshack.us%2Fimg180%2F6600%2Fpostwarningei3.gif&hash=e31b5226abbe83d7dd2c274417385441feff21c2)
This is displayed when a user attempts to post a new topic in a specific board. In only displays when posting the topic. This is done with a simple IF statement in the Post.template.php file of your theme.
Right after this:
function template_main()
{
global $context, $settings, $options, $txt, $scripturl, $modSettings;
Add this, but make sure you replace the board id with the one you want, and edit the html to your preferences.
// Display a notice to SEARCH for an answer first
if ( $context['num_replies'] == 0 && $context['current_board'] == X) {
echo ' <center> Please remember to search the forum before asking questions in this board.</center>';
}
Replace the capital "x" with the board id you need. You can replace the html with anything, just remember to escape ' with a \.
As my forum is primarily a support forum for certain stuff, I always had something like this in mind. Thanks for sharing, it works perfectly :)
Thank you so much for the tip.
I've actually used it with another function, in this case, with minimum post count, to display a warning (and a link) for newbies to follow the forum rules when posting.
Needless to say, this tip has unlimited potential, as one can start building rules to display custom postboxes according to different parameters (post count, user membergroup, reply or new topic, etc).
i have a very long forum section, how to know the board id numbers? sorry, newbie only here.
Starting from the board index, you will see the board id number if you hover over it, e.g. this board's link is http://www.simplemachines.org/community/index.php?board=72.0 - Tips and Tricks is board 72, since ?board=72.
@Arantor
thanks. additional question, with that code above, how am i be able too add multiple boards, should i use comma on it like:
// Display a notice to SEARCH for an answer first
if ( $context['num_replies'] == 0 && $context['current_board'] == [color=red]1, 2, 3[/color]) {
echo ' <center> Please remember to search the forum before asking questions in this board.</center>';
}
Quote from: akosiparusa on July 06, 2009, 02:04:46 AM
@Arantor
thanks. additional question, with that code above, how am i be able too add multiple boards, should i use comma on it like:
// Display a notice to SEARCH for an answer first
if ( $context['num_replies'] == 0 && $context['current_board'] == [color=red]1, 2, 3[/color]) {
echo ' <center> Please remember to search the forum before asking questions in this board.</center>';
}
If you want to do multiple you should use an array in my opinion, some PHP devs might think otherwise but here is how I would personally do it.
// Display a notice to SEARCH for an answer first
$msgboards = array(1, 2, 3); // The board ids to display the message.
if ($context['num_replies'] == 0 && in_array($context['current_board'], $msgboards)) { // Check if it's a new topic and the current board is in the array.
echo ' <center> Please remember to search the forum before asking questions in this board.</center>'; // Echo you message
} // End the if statement
I commented each line for you too.
Thanks dude, will try what you gave right now
No problem, glad I could help.
Tell me if you need anything else.
hey it worked. thanks
hi again, i knew it worked but this is just the day i had to look at the forum error log, and yes there was an error on Post.template line 11.
Quote8: Undefined index: num_replies
File: /hermes/web07/b2352/moo.digitalron/_pc-experts.org/forum/Themes/default/Post.template.php
Line: 11
colored red is line 11 on my current file:
Quote// Display a notice to SEARCH for an answer first
$msgboards = array(10, 7, 2, 37, 3, 4, 5, 38, 6, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22); // The board ids to display the message.
if ($context['num_replies'] == 0 && in_array($context['current_board'], $msgboards)) { // Check if it's a new topic and the current board is in the array.
echo ' <center> <font color="red"><br>Please remember to search the forum before asking questions and/or making a new thread in this board.</br>
<br>Limit the posting of images to 640 pixels width/height only. 4 images per post.</br></font></center>'; // Echo you message
} // End the if statement
The "if" statement is missing some parentesis... It should be:
if (($context['num_replies'] == 0) && in_array($context['current_board'], $msgboards))
I don't know if it is causing your error or not... But the correct "C" construction is like this...
Actually, margarett, the parentheses are fine in the above statement, PHP executes left to right, and is quite capable of doing that.
The issue is that $context is not being populated properly. I think it may be for a different version of SMF - which version are you using, akosiparusa?
oh sorry, i forgot to mention that im using 1.1.9 with 2 custom themes, novelty & overview.
The issue is that $context['num_replies'] doesn't exist on a new thread. Fixed version allowing multiple boards (comments removed for brevity)
// Display a notice to SEARCH for an answer first
$msgboards = array(1, 2, 3); // The board ids to display the message.
if (!isset($context['num_replies']) && in_array($context['current_board'], $msgboards)) {
echo ' <center> Please remember to search the forum before asking questions in this board.</center>';
}
Note the first version would also throw the warning on the first reply in a topic (when there are no replies). This version detects on new thread instead.
Arantor, thank you for the explanation ;)
Nice tip... ;D
Great tip - I'd seen that done before but didn't know how it could be set.
Avery