TinyPortal

Development => Block Codes => Topic started by: catchpen on December 07, 2007, 08:11:22 AM

Title: Forum Jump drop down menu block just by copy and paste
Post by: catchpen on December 07, 2007, 08:11:22 AM
NOTE: For working dynamic forum drop down menu see Dragooon's reply #7.

This will give you a quick jump forum drop down menu like the one on the bottom of SMF pages by just copy and paste in a script block.

Example is on the top of my page http://www.topsupplementshops.com (http://www.topsupplementshops.com)

I made a few small changes to get it to work at the beginning of the code but I can't remember what it was! maybe you can use the first code example below.

Note: I used the "Web Developer" Firefox plug in to view the "generated source" of my own web page.

Here's how:
log in as a regular member so your menu will have what your regular members have access too.

Now find a page on your site that has the SMF "jump to" menu on the bottom.

With the "web developer plug in tool bar just click on "view source" and then click on "view generated source" on the menu while on your webpage.  Don't want to use the plugin? Maybe a right mouse click on the page and choose "view page source" will do the same.

Scroll down on the view DOM source page or do a search you should see something like this: You can try to use the example, like I said I made some small changes to it to work on this part but I've slept since then. Copy and paste into a script block.

<form action="http://www.yoursitename.com/index.php"
method="get" accept-charset="ISO-8859-1"><label for="jumpto">
<b>Forum Jump:</b></label> <select name=
"jumpto" id="jumpto" onchange=
"if (this.selectedIndex &gt; 0 &amp;&amp; this.options[this.selectedIndex].value) window.location.href = smf_scripturl + this.options[this.selectedIndex].value.substr(smf_scripturl.indexOf('?') == -1 || this.options[this.selectedIndex].value.substr(0, 1) != '?' ? 0 : 1);">


below that on your gen source, copy and paste that all the way to </form>, remember to grab a fresh code when you add, delete or move a board. example -
<option value="">Please select a destination:</option>
<option value="" disabled="disabled">-----------------------------</option>
<option value="#1">General Chat and Discussion</option>

<option value="" disabled="disabled">-----------------------------</option>
<option value="?board=15.0"> =&gt; New Member? Say Hello!</option>
<option value="?board=1.0"> =&gt; General Chat and Discussion</option>
<option value="?board=25.0"> =&gt; TSS Announcements</option>

<option value="?board=26.0"> ===&gt; Board Rules and FAQS</option>
<option value="?board=27.0"> ===&gt; Ideas, Suggestions and Feedback</option>
<option value="?board=28.0"> ===&gt; TSS Mod and Admins</option>

<option value="" disabled="disabled">-----------------------------</option>
<option value="#2">The Top Deals on Supplements and Vitamins</option>
<option value="" disabled="disabled">-----------------------------</option>
<option value="?board=3.0"> =&gt; Body Building Vitamin and Supplement Deals</option>
<option value="?board=24.0"> ===&gt; Supplement of the week (SOTW)</option>

<option value="?board=5.0"> =&gt; Vitamin and Misc. Herbal Product Deals </option>
<option value="?board=8.0"> =&gt; All Other Health and Nutrition Deals</option>
<option value="?board=6.0"> =&gt; Deals on Sports and Fitness Equipment</option>

<option value="?board=20.0"> =&gt; Freebies</option>
<option value="?board=29.0"> ===&gt; Non - U.S. Freebies</option>
<option value="?board=23.0"> =&gt; Request a Deal</option>

<option value="" disabled="disabled">-----------------------------</option>
<option value="#3">The Top Shops: Online and Retail</option>
<option value="" disabled="disabled">-----------------------------</option>
<option value="?board=7.0"> =&gt; The Best and Worst Shops</option>
<option value="?board=22.0"> ===&gt; Store Shipping Rates</option>

<option value="?board=16.0"> =&gt; Deals at Regional Retail Stores</option>
<option value="" disabled="disabled">-----------------------------</option>
<option value="#4">Supplement Shake Down: Reviews, Why, What For and When?</option>
<option value="" disabled="disabled">-----------------------------</option>
<option value="?board=10.0"> =&gt; Nutritional Supplements: Definitions, Usage, and Purpose</option>

<option value="?board=30.0"> =&gt; New Supplement Products</option>
<option value="?board=9.0"> =&gt; Super Supplement or Snake Oil?</option>
<option value="?board=14.0"> ===&gt; You're better off eating dirt!</option>

<option value="?board=11.0"> =&gt; Diet, Nutrition and Workout Articles and  Discussion </option>
<option value="" disabled="disabled">-----------------------------</option>
<option value="#7">Recommended H&amp;F Forums and Sites</option>
<option value="" disabled="disabled">-----------------------------</option>
<option value="?board=18.0"> =&gt; Friends of TSS</option>

<option value="?board=31.0"> ===&gt; Off Topic Friends of TSS</option>
</select> &nbsp; <input value="go" onclick=
"if (this.form.jumpto.options[this.form.jumpto.selectedIndex].value) window.location.href = 'http://www.yoursitename.com/index.php' + this.form.jumpto.options[this.form.jumpto.selectedIndex].value;"
type="button"></form>

That's it. I added <div style="align:left;"><div class="smalltext"> at front and <div style="clear:both;" />
</div>
</div> on the end so it takes up less room

So does anyone know how to get this to change along when changes are made to forum boards and categories?



Title: Re: Forum Jump drop down menu block just by copy and paste
Post by: Dragooon on December 07, 2007, 08:34:47 AM
global $db_prefix, $user_info, $scripturl;
$query = db_query("
SELECT c.name AS catName, c.ID_CAT, b.ID_BOARD, b.name AS boardName, b.childLevel, b.boardOrder

FROM {$db_prefix}boards AS b
LEFT JOIN {$db_prefix}categories AS c ON (c.ID_CAT = b.ID_CAT)

                WHERE $user_info[query_see_board] "
                , __FILE__, __LINE__) or die(mysql_error());

        $cats = array();
        $tempCat = array('id' => -1);

while ($row = mysql_fetch_assoc($query))

if($tempCat['id'] != $row['ID_CAT'])
                  {
$tempCat = &$cats[];
$tempCat['id'] = $row['ID_CAT'];
$tempCat['name'] = shorten_subject($row['catName'], 20);
$tempCat['boards'] = array();
   }
$tempCat['boards'][] = array(
'id' => $row['ID_BOARD'],
'name' => shorten_subject($row['boardName'], 20),
'child_level' => $row['childLevel'],
'is_current' => isset($context['current_board']) && $row['ID_BOARD'] == $context['current_board']
);
}
     echo '<span class="smalltext">
<form action="', $scripturl, '" method="get" accept-charset="', $context['character_set'], '" style="padding:0; margin: 0;">
<select name="boardSelect" onchange=
"if (this.selectedIndex > 0 && this.options[this.selectedIndex].value) window.location.href = smf_scripturl + this.options[this.selectedIndex].value.substr(smf_scripturl.indexOf('?') == -1 || this.options[this.selectedIndex].value.substr(0, 1) != '?' ? 0 : 1);">';
foreach ($cats as $c)
{
echo '
<option value="" disabled="disabled">------------------------</option>
<option value="#', $c['id'], '">', $c['name'], '</option>
<option value="" disabled="disabled">------------------------</option>';
foreach ($c['boards'] as $b)
echo '
<option value="?board='.$b['id'].'"> ' . str_repeat('-', $b['child_level']) . '- ' . $b['name'] . '</option>';


echo '
</select></form>';

Edited to Fix the code
Title: Re: Forum Jump drop down menu block just by copy and paste
Post by: catchpen on December 07, 2007, 11:35:22 PM
Thanks Dragoon, what part did you correct? I think this would go in a php box now right?
Title: Re: Forum Jump drop down menu block just by copy and paste
Post by: Dragooon on December 08, 2007, 05:45:36 AM
I totally changed the code and made it use db queries :P
Yes a PHP Block.
Title: Re: Forum Jump drop down menu block just by copy and paste
Post by: fangweile on December 08, 2007, 06:04:03 AM
@Dragoon
I have this error when using your code.

faultCode0faultStringParse error:syntax error
Title: Re: Forum Jump drop down menu block just by copy and paste
Post by: Dragooon on December 08, 2007, 07:04:24 AM
Say what?!
What kind of error is that? :P
Try this one global $db_prefix, $user_info, $scripturl;
$query = db_query("
SELECT c.name AS catName, c.ID_CAT, b.ID_BOARD, b.name AS boardName, b.childLevel, b.boardOrder

FROM ({$db_prefix}boards AS b)
LEFT JOIN {$db_prefix}categories AS c ON (c.ID_CAT = b.ID_CAT)

                WHERE $user_info[query_see_board] "
                , __FILE__, __LINE__) or die(mysql_error());

        $cats = array();
        $tempCat = array('id' => -1);

while ($row = mysql_fetch_assoc($query))

if($tempCat['id'] != $row['ID_CAT'])
                  {
$tempCat = &$cats[];
$tempCat['id'] = $row['ID_CAT'];
$tempCat['name'] = shorten_subject($row['catName'], 20);
$tempCat['boards'] = array();
   }
$tempCat['boards'][] = array(
'id' => $row['ID_BOARD'],
'name' => shorten_subject($row['boardName'], 20),
'child_level' => $row['childLevel'],
'is_current' => isset($context['current_board']) && $row['ID_BOARD'] == $context['current_board']
);
}
     echo '<span class="smalltext">
<form action="', $scripturl, '" method="get" accept-charset="', $context['character_set'], '" style="padding:0; margin: 0;">
<select name="boardSelect" onchange=
"if (this.selectedIndex > 0 && this.options[this.selectedIndex].value) window.location.href = smf_scripturl + this.options[this.selectedIndex].value.substr(smf_scripturl.indexOf('?') == -1 || this.options[this.selectedIndex].value.substr(0, 1) != '?' ? 0 : 1);">';
foreach ($cats as $c)
{
echo '
<option value="" disabled="disabled">------------------------</option>
<option value="#', $c['id'], '">', $c['name'], '</option>
<option value="" disabled="disabled">------------------------</option>';
foreach ($c['boards'] as $b)
echo '
<option value="?board='.$b['id'].'"> ' . str_repeat('-', $b['child_level']) . '- ' . $b['name'] . '</option>';


echo '
</select></form>';

I just wrote it in 5 mins :P
Title: Re: Forum Jump drop down menu block just by copy and paste
Post by: fangweile on December 08, 2007, 07:28:13 AM
same error here

faultCode0faultStringParse error:syntax error, unexpected ';' in /home/vol2/Sources/Load.php(1770) : eval()'d code(35) : eval()'d code on line 33

I use the code in left php block.
Title: Re: Forum Jump drop down menu block just by copy and paste
Post by: Dragooon on December 08, 2007, 08:15:06 AM
Ahh I see
Try this global $db_prefix, $user_info, $scripturl;
$query = db_query("
SELECT c.name AS catName, c.ID_CAT, b.ID_BOARD, b.name AS boardName, b.childLevel, b.boardOrder

FROM ({$db_prefix}boards AS b)
LEFT JOIN {$db_prefix}categories AS c ON (c.ID_CAT = b.ID_CAT)

                WHERE $user_info[query_see_board] "
                , __FILE__, __LINE__) or die(mysql_error());

        $cats = array();
        $tempCat = array('id' => -1);

while ($row = mysql_fetch_assoc($query))

if($tempCat['id'] != $row['ID_CAT'])
                  {
$tempCat = &$cats[];
$tempCat['id'] = $row['ID_CAT'];
$tempCat['name'] = shorten_subject($row['catName'], 20);
$tempCat['boards'] = array();
   }
$tempCat['boards'][] = array(
'id' => $row['ID_BOARD'],
'name' => shorten_subject($row['boardName'], 20),
'child_level' => $row['childLevel'],
'is_current' => isset($context['current_board']) && $row['ID_BOARD'] == $context['current_board']
);
}
     echo '<span class="smalltext">
<form action="', $scripturl, '" method="get" accept-charset="', $context['character_set'], '" style="padding:0; margin: 0;">
<select name="boardSelect" onchange=
"if (this.selectedIndex > 0 && this.options[this.selectedIndex].value) window.location.href = smf_scripturl + this.options[this.selectedIndex].value.substr(smf_scripturl.indexOf(\'?\') == -1 || this.options[this.selectedIndex].value.substr(0, 1) != \'?\' ? 0 : 1);">';
foreach ($cats as $c)
{
echo '
<option value="" disabled="disabled">------------------------</option>
<option value="#', $c['id'], '">', $c['name'], '</option>
<option value="" disabled="disabled">------------------------</option>';
foreach ($c['boards'] as $b)
echo '
<option value="?board='.$b['id'].'"> ' . str_repeat('-', $b['child_level']) . '- ' . $b['name'] . '</option>';


echo '
</select></form>';
Title: Re: Forum Jump drop down menu block just by copy and paste
Post by: fangweile on December 08, 2007, 09:59:32 AM
Works like charm. Great code. Your are really a php coder, many thanks.
Title: Re: Forum Jump drop down menu block just by copy and paste
Post by: Dragooon on December 08, 2007, 10:06:38 AM
I started coding only 3 months back :P.
But thanks. I still wonder how did it worked on my test forum with that mistake :P
Title: Re: Forum Jump drop down menu block just by copy and paste
Post by: catchpen on December 08, 2007, 11:31:54 PM
Cool I'll replace mine with yours and see how it works when I get home.  Will it show boards that user doesn't have permissions too?
Title: Re: Forum Jump drop down menu block just by copy and paste
Post by: IchBin on December 08, 2007, 11:34:22 PM
$user_info[query_see_board] is an array of the boards allowed to be seen by the user. So no, it won't show boards that a user doesn't have access too.