Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: 1MileCrash on May 18, 2007, 10:57:11 PM

Title: A simple tip for limiting pointless threads.
Post by: 1MileCrash on May 18, 2007, 10:57:11 PM
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 \.
Title: Re: A simple tip for limiting pointless threads.
Post by: Roph on May 19, 2007, 07:59:02 AM
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 :)
Title: Re: A simple tip for limiting pointless threads.
Post by: Paracelsus on May 21, 2007, 09:42:25 AM
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).
Title: Re: A simple tip for limiting pointless threads.
Post by: akosiparusa on July 05, 2009, 08:22:01 AM
i have a very long forum section, how to know the board id numbers? sorry, newbie only here.
Title: Re: A simple tip for limiting pointless threads.
Post by: Arantor on July 05, 2009, 01:44:43 PM
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.
Title: Re: A simple tip for limiting pointless threads.
Post by: 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>';
      }
Title: Re: A simple tip for limiting pointless threads.
Post by: _Anthony_ on July 06, 2009, 03:27:30 AM
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.
Title: Re: A simple tip for limiting pointless threads.
Post by: akosiparusa on July 06, 2009, 06:25:23 AM
Thanks dude, will try what you gave right now
Title: Re: A simple tip for limiting pointless threads.
Post by: _Anthony_ on July 06, 2009, 01:08:14 PM
No problem, glad I could help.
Tell me if you need anything else.
Title: Re: A simple tip for limiting pointless threads.
Post by: akosiparusa on July 06, 2009, 02:58:33 PM
hey it worked. thanks
Title: Re: A simple tip for limiting pointless threads.
Post by: akosiparusa on July 23, 2009, 03:58:31 AM
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

Title: Re: A simple tip for limiting pointless threads.
Post by: margarett on July 23, 2009, 06:48:08 AM
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...
Title: Re: A simple tip for limiting pointless threads.
Post by: Arantor on July 23, 2009, 08:11:26 AM
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?
Title: Re: A simple tip for limiting pointless threads.
Post by: akosiparusa on July 23, 2009, 08:59:57 AM
oh sorry, i forgot to mention that im using 1.1.9 with 2 custom themes, novelty & overview.
Title: Re: A simple tip for limiting pointless threads.
Post by: Arantor on July 23, 2009, 10:03:01 AM
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.
Title: Re: A simple tip for limiting pointless threads.
Post by: margarett on July 23, 2009, 11:14:23 AM
Arantor, thank you for the explanation ;)
Title: Re: A simple tip for limiting pointless threads.
Post by: willerby on August 07, 2009, 06:04:32 PM
Nice tip...  ;D
Title: Re: A simple tip for limiting pointless threads.
Post by: ajparker on August 12, 2009, 02:08:22 PM
Great tip - I'd seen that done before but didn't know how it could be set.

Avery