• Welcome to Simple Machines Community Forum. Please login or sign up.
December 06, 2021, 01:58:47 PM

News:

Wondering if this will always be free?  See why free is better.


A simple tip for limiting pointless threads.

Started by 1MileCrash, May 18, 2007, 10:57:11 PM

Previous topic - Next topic

1MileCrash

Tired of people posting questions without searching? Or asking something that has been answered umpteen times? I was too. So i did this.



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 \.
The only thing php can't do is tell you how much milk is left in the fridge.



Roph

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 :)

Paracelsus

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).

akosiparusa

i have a very long forum section, how to know the board id numbers? sorry, newbie only here.

Arantor

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.
No good deed goes unpunished
All helpful urges should be circumvented

akosiparusa

@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>';
      }

_Anthony_

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.

akosiparusa

Thanks dude, will try what you gave right now

_Anthony_

No problem, glad I could help.
Tell me if you need anything else.

akosiparusa


akosiparusa

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


margarett

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...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

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?
No good deed goes unpunished
All helpful urges should be circumvented

akosiparusa

oh sorry, i forgot to mention that im using 1.1.9 with 2 custom themes, novelty & overview.

Arantor

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.
No good deed goes unpunished
All helpful urges should be circumvented

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

willerby

What type of washing machine is September?

An autumnatic. :)

ajparker

Great tip - I'd seen that done before but didn't know how it could be set.

Avery

Advertisement: