I want some of my blocks to show on every page EXCEPT the frontpage.
I know that this has been asked before, and I know that the answer is that it can't be done, but I think it can, and here is how.
If I can get the base code for all of the blocks that I have, and place them into a php block, and run an if statement like the following:
//Are we on the frontpage now?
if ($url == 'http://www.yoursite.com/forum/index.php')
{
//If so then don't display the block
}
else
{
//If not then display the block
--The block's code--
}
This should work should it not?
All I need is to know where the code for the blocks is. Once I have this info, I should be able to run this through the block and exclude it from being visible on certain pages.
Where is the PHP code for the blocks?
You can set what to show on the front page, by going to admin/tp settings/Front page settings
there you can choose what you want from the options
I know that. What I want is exactly opposite. I want to be able to choose what NOT to show on the front page. There are also some situations were I don't want a specific block to show up in a certain page of the website.
If I can just have the code for the built in blocks now...
*Rubs hand together eagerly* ;D
You can already specify which blocks to display in any part of the site you want.
I have some centre blocks to display only in my FAQs board.
What you can't currently do is, turn Off left/right panels in the forum and then decide that you want a few left blocks in say the FAQs board.
I have left/right panels to display only on the home page. I can't use a left block in the FAQs because it's disabled from being shown in the forums.
This may be changed sometime.
I'm saying that I want to have, say the user block, to show up in the forum AND in the FAQ AND in the profile screen but NOWHERE else. (I'm not yelling or anything. Just emphasizing. ;D)
This could only be done if I had a separate block showing up in each individual section.
I don't want to have to do this.
If someone could kindly direct me to the code, then I should be able to do this relatively easily with the code up top.
I understand exactly what you are saying and I did from the start, and I agree, I have wanted this myself at times.
If you don't ask, you wont get ;)
No idea :2funny:
I've posted some code for this a few times. While TP doesn't have these options built in (yet), you can put some code in a block to only display on certain pages. Search my posts and you'll find it.
I'm not finding it Ichbin. I've done multiple searches but can't find where the code for the preset blocks are at. Maybe you could direct me?
(I know you have a lot of posts and this is probably a big request, but I can't seem to find it anywhere...)
if (isset($_GET['board']) && $_GET['board'] == 4){
echo 'all_your_stuff_here';
}
Change the #4 to what ever board you want.
If you don't want it to appear in just a board you can change board to topic and put the topic number instead of the board number.
The blocks are fetched and laid out in TPortal.php. Its a loop with the permission check inside it, so you need to look at how its fetching them and do some changes there.
Whats missing from block layout options is a switch from showing a block on a specific page, to NOT show a block in a specific page - which is why this option is already added for TP 1.0.
I believe this was suggested by IchBin a while back lol :) if memory serves me right.
LOL. Thanx Ichbin, but I just realized that maybe you don't understand what I mean. It's the 'all_your_stuff_here' that I'm needing.
I don't want to lose my blocks that are preset. ie. user, article, news, search, recent topics, stats...
I want to edit the code for these individual blocks and make it so that they show up where I want it to.
Is the base code for these blocks in TPortal.php?
Also, would changing the above code from
if (isset($_GET['board']) && $_GET['board'] == 4){
echo 'all_your_stuff_here';
}
to if (isset($_GET['board']) && $_GET['board'] !== 4){
echo 'all_your_stuff_here';
}
work to tell it to display on every page BUT one?
Also, would I have to recreate this statement for every different page or is there a way to easily add a list of possibilites? Could I use an array to do this?
Thanx again for the help.
If I can figure this out, then I may try to create a mod for it.
Who knows?
OK. I found it.
I'm a retard. It's a function. That's all. If I create a phpbox and call the function from there, it runs. Now if I put the function into an if/then statement, I can control where and when it is called.
So all that is left unanswered at this point is whether or not I can add the '!' to tell a block where NOT to display.
Here it the code that I have inside of a block:
if (isset($_GET['board']) && $_GET['board'] !== 'http://www.mysite.com/forum/index.php'){
global $context, $settings, $options, $scripturl, $txt, $modSettings;
// Show a random news item? (or you could pick one from news_lines...)
if (!empty($settings['enable_news']))
echo ' <div style="padding: 5px;" >', $context['random_news_line'], '</div>';
}
It doesn't do what I want it to though.
It should display on every page EXCEPT the frontpage, but It's not showing up anywhere.
Just an empty block.
TP has a variable that show if the user is on the homepage..so your code could look like this:
if (!$context['TPortal']['is_front'])
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
// Show a random news item? (or you could pick one from news_lines...)
if (!empty($settings['enable_news']))
echo ' <div style="padding: 5px;" >', $context['random_news_line'], '</div>';
}
Oh wow. That almost does it. Unfortunately it still shows up as an empty box. How would I get it to kill the whole box?
I could change the options to not show the frame, but I want the frame.
Hold on. I'll look and see if I can find the styling for the frame itself. If I can, then I can just hardcore the frame into the code and kill the frame options.
I'll try that.
If anyone sees a problem with this, then stop me now before I screw up my computer. ;D
OK. Here is what I've got in there, but It doesn't seem to work. I'd rather not have to put the CSS into a whole new file. I should be able to create the CSS directly inside of the phpbox right?
Here it is:
if (!$context['TPortal']['is_front'])
{
<<<EOD
.code
{
color: #000000;
background-color: #dddddd;
font-family: "courier new", "times new roman", monospace;
font-size: x-small;
line-height: 1.3em;
/* Put a nice border around it. */
border: 1px solid #000000;
margin: 1px auto 1px auto;
padding: 1px;
width: 99%;
/* Don't wrap its contents, and show scrollbars. */
white-space: nowrap;
overflow: auto;
/* Stop after about 24 lines, and just show a scrollbar. */
max-height: 24em;
}
EOD;
global $context, $settings, $options, $scripturl, $txt, $modSettings;
// Show a random news item? (or you could pick one from news_lines...)
if (!empty($settings['enable_news']))
echo ' <div class="code" style="padding: 5px;" >', $context['random_news_line'], '</div>';
}
EDIT: Ignore this post completely please. I was being a retard when I put it up. :uglystupid2:
OK. so I am really stupid and I don't know why I had that last code in there because that was the code for the code tag...
I'm really dumb.
Here is what I have.
I'd like to use this code but I'm getting a parse error.
Here is the code:
if (!$context['TPortal']['is_front'])
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo'
<div class=\"tborder\" style=\"margin-bottom: 2px;\">
<font size=\"1\"> </font><div class=\"titlebg\" style=\"padding: 4px; font-weight: bold;\"><font size=\"1\"><a href=\"javascript: void(0); return false\" onclick=\"toggle('5'); return false\"><img id=\"blockcollapse5\" style=\"margin: 0pt;\" src=\"http://www.priacta.com/forum/Themes/TPstyle11_tp/images/collapse.gif\" alt=\"\" align=\"right\" border=\"0\"></a><a href=\"http://www.priacta.com/forum/index.php?action=tpadmin;blockeditl=5;sesc=52e81c5eb9f3028ecd6fc13038f2f18a\"><img style=\"margin-right: 4px;\" src=\"http://www.priacta.com/forum/Themes/TPstyle11_tp/images/tp-edit.gif\" alt=\"\" align=\"right\" border=\"0\"></a>Tests </font></div>
<font size=\"1\"> </font><div class=\"windowbg\" style=\"padding: 4px;\" id=\"block5\"><div style=\"padding: 5px;\" class=\"smalltext\"><p style=\"margin: 0pt; padding: 0pt 0pt 0.5ex;\"><font size=\"1\"><img src=\"http://www.priacta.com/forum/Themes/TPstyle11_tp/images/tpoptions.gif\" style=\"margin: 0pt;\" alt=\"\" align=\"absbottom\">
<div style=\"padding: 5px;\" >',';
echo' $context['random_news_line']';
echo'</div>
<br></font></div></div></div>
';
}
And here is the parse error:
Parse error: parse error, unexpected T_LNUMBER, expecting ',' or ';' in c:\websites\mysite304\mysite.com\forum\Sources\Errors.php(1733) : eval()'d code(35) : eval()'d code on line 7
I can't figure out why I'm getting this error.
At the end
<br></font></div></div></div>
';
Remove the
';
Nope. That aint it.
That last part there is for the last echo.
Here. I cleaned it up so that it looks better.
if (!$context['TPortal']['is_front'])
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo'
<div class=\"tborder\" style=\"margin-bottom: 2px;\">
<font size=\"1\"> </font><div class=\"titlebg\" style=\"padding: 4px; font-weight: bold;\"><font size=\"1\"><a href=\"javascript: void(0); return false\" onclick=\"toggle('5'); return false\"><img id=\"blockcollapse5\" style=\"margin: 0pt;\" src=\"http://www.priacta.com/forum/Themes/TPstyle11_tp/images/collapse.gif\" alt=\"\" align=\"right\" border=\"0\"></a><a href=\"http://www.priacta.com/forum/index.php?action=tpadmin;blockeditl=5;sesc=52e81c5eb9f3028ecd6fc13038f2f18a\"><img style=\"margin-right: 4px;\" src=\"http://www.priacta.com/forum/Themes/TPstyle11_tp/images/tp-edit.gif\" alt=\"\" align=\"right\" border=\"0\"></a>Tests </font></div>
<font size=\"1\"> </font><div class=\"windowbg\" style=\"padding: 4px;\" id=\"block5\"><div style=\"padding: 5px;\" class=\"smalltext\"><p style=\"margin: 0pt; padding: 0pt 0pt 0.5ex;\"><font size=\"1\"><img src=\"http://www.priacta.com/forum/Themes/TPstyle11_tp/images/tpoptions.gif\" style=\"margin: 0pt;\" alt=\"\" align=\"absbottom\">
<div style=\"padding: 5px;\" >',
';
echo"
$context['random_news_line']
";
echo'
</div><br></font></div></div></div>
';
}
Try this then.
<div style=\"padding: 5px;\" >',
';
Seems like doubble up to me there
remove
';
I tried both of those, but it is still happening.
For some reason, all that I get is that parse error.
After cleaning it up some more,
it looks like this:
if (!$context['TPortal']['is_front'])
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo'
<div class=\"tborder\" style=\"margin-bottom: 2px;\">
<font size=\"1\"></font><div class=\"titlebg\" style=\"padding: 4px; font-weight: bold;\"><font size=\"1\"><a href=\"javascript: void(0); return false\" onclick=\"toggle('5'); return false\"><img id=\"blockcollapse5\" style=\"margin: 0pt;\" src=\"http://www.priacta.com/forum/Themes/TPstyle11_tp/images/collapse.gif\" alt=\"\" align=\"right\" border=\"0\"></a><a href=\"http://www.priacta.com/forum/index.php?action=tpadmin;blockeditl=5;sesc=52e81c5eb9f3028ecd6fc13038f2f18a\"><img style=\"margin-right: 4px;\" src=\"http://www.priacta.com/forum/Themes/TPstyle11_tp/images/tp-edit.gif\" alt=\"\" align=\"right\" border=\"0\"></a>Tests </font></div>
<font size=\"1\"></font><div class=\"windowbg\" style=\"padding: 4px;\" id=\"block5\"><div style=\"padding: 5px;\" class=\"smalltext\"><p style=\"margin: 0pt; padding: 0pt 0pt 0.5ex;\"><font size=\"1\"><img src=\"http://www.priacta.com/forum/Themes/TPstyle11_tp/images/tpoptions.gif\" style=\"margin: 0pt;\" alt=\"\" align=\"absbottom\">
<div style=\"padding: 5px;\" >',
';
echo"
$context['random_news_line']
";
echo'
</div><br></font></div></div></div>
';
}
I still don't see what on line 7 is causing this.
I have properly escaped all of my quotation marks.
You don't need to escape double quotes when using single quotes for your echo statement. You also had the session id in your link which I removed. You should put that info in a link. Removed some extra font tags you didn't appear to need too. Seem to be many extra div tags, but I'll let you mess with that. :)
Ã, Ã, if (!$context['TPortal']['is_front'])
Ã, Ã, {
Ã, Ã, Ã, Ã, global $context, $settings, $options, $scripturl, $txt, $modSettings;
Ã, Ã, Ã, Ã,Â
Ã, Ã, Ã, Ã, echo'
Ã, Ã, Ã, Ã, Ã, Ã, <div class="tborder" style="margin-bottom: 2px;">
Ã, Ã, Ã, Ã, Ã, Ã, <div class="titlebg" style="padding: 4px; font-weight: bold;"><font size="1"><a href="javascript: void(0); return false" onclick="toggle('5'); return false"><img id="blockcollapse5" style="margin: 0pt;" src="http://www.priacta.com/forum/Themes/TPstyle11_tp/images/collapse.gif" alt="" align="right" border="0"></a><a href="http://www.priacta.com/forum/index.php?action=tpadmin;blockeditl=5;"><img style="margin-right: 4px;" src="http://www.priacta.com/forum/Themes/TPstyle11_tp/images/tp-edit.gif" alt="" align="right" border="0"></a>Tests </font></div>
Ã, Ã, Ã, Ã, Ã, Ã, <div class="windowbg" style="padding: 4px;" id="block5"><div style="padding: 5px;" class="smalltext"><p style="margin: 0pt; padding: 0pt 0pt 0.5ex;"><font size="1"><img src="http://www.priacta.com/forum/Themes/TPstyle11_tp/images/tpoptions.gif" style="margin: 0pt;" alt="" align="absbottom">
Ã, Ã, Ã, Ã, Ã, Ã, <div style="padding: 5px;" >';
Ã, Ã, Ã, Ã, Ã, Ã, echo $context['random_news_line'];
Ã, Ã, Ã, Ã, Ã, Ã, echo'</div>
<br></font></div></div></div>
Ã, Ã, Ã, Ã, ';
Ã, Ã, }
If this code doesn't work then you may need to try this.
toggle('5');
Change to this:
toggle(\'5\');
Success!
You rock IchBin.
It was the toggle that was causing the trouble.
For those who want it,
This snippet of code will allow you to create a box that can hidden on only specific pages.
//Is the current page the frontpage?
if (!$context['TPortal']['is_front'])
{
//If so, then load the global variables
global $context, $settings, $options, $scripturl, $txt, $modSettings;
//and create the frame for the block.
echo'
<div class="tborder" style="margin-bottom: 2px;">
<div class="titlebg" style="padding: 4px; font-weight: bold;"><font size="1"><a href="javascript: void(0); return false" onclick="toggle(\'5\'); return false"><img id="blockcollapse5" style="margin: 0pt;" src="http://www.priacta.com/forum/Themes/TPstyle11_tp/images/collapse.gif" alt="" align="right" border="0"></a><a href="http://www.priacta.com/forum/index.php?action=tpadmin;blockeditl=5;"><img style="margin-right: 4px;" src="http://www.priacta.com/forum/Themes/TPstyle11_tp/images/tp-edit.gif" alt="" align="right" border="0"></a>Tests </font></div>
<div class="windowbg" style="padding: 4px;" id="block5"><div style="padding: 5px;" class="smalltext"><p style="margin: 0pt; padding: 0pt 0pt 0.5ex;"><font size="1">
<div style="padding: 5px;" >';
//Put all of your code here!
echo'</div><br></font></div></div></div>
';
}
To make this work with any other page (doesn't have to be frontpage), replace:
if (!$context['TPortal']['is_front'])
With:
// find out the domain
$domain = $_SERVER['HTTP_HOST'];
// find out the path to the current file:
$path = $_SERVER['SCRIPT_NAME'];
// find out the QueryString:
$queryString = $_SERVER['QUERY_STRING'];
// put it all together:
$url = "http://" . $domain . $path . "?" . $queryString;
//Are we on the BLANK page now?
//if ($url != 'http://www.mysite.com')
You must replace the 'mysite.com' portion with the exact URL for the page you want to exclude the block from.
Thanx again for everyone that helped out here. This has been a question on my mind for a very long time, and I'm glad to have it out of the way.
Thanx again!
EDIT:
Note that in order for this to work properly, you MUST have the frame turned off for the block.
the code above will create the frame for you and not display it while on the specified page.
Hum... It almost works...
Here is what you have to do to make it work properly.
You will have to open your database and browse smf_tp_articles.
Find what the id is for your specific block and change the following portions.
<div class="titlebg" style="padding: 4px; font-weight: bold;"><font size="1"><a href="javascript: void(0); return false" onclick="toggle(\'5\'); return false"><img id="blockcollapse5" style="margin: 0pt;" src="http://www.priacta.com/forum/Themes/TPstyle11_tp/images/collapse.gif" alt="" align="right" border="0"></a><a href="http://www.priacta.com/forum/index.php?action=tpadmin;blockeditl=5;"><img style="margin-right: 4px;" src="http://www.priacta.com/forum/Themes/TPstyle11_tp/images/tp-edit.gif" alt="" align="right" border="0"></a>Tests </font></div>
change it to:
<div class="titlebg" style="padding: 4px; font-weight: bold;"><font size="1"><a href="http://www.priacta.com/forum/index.php?action=tpadmin;blockeditl=5;"><img style="margin-right: 4px;" src="http://www.priacta.com/forum/Themes/TPstyle11_tp/images/tp-edit.gif" alt="" align="right" border="0"></a>Tests </font></div>
then exchange the part that says:
href="http://www.priacta.com/forum/index.php?action=tpadmin;blockeditl=5;">
and exchange with:
href="http://www.priacta.com/forum/index.php?action=tpadmin;blockeditl={BLOCK'S ID};">
You must exchange the {BLOCK'S ID} with your block's id.
This should fix the code.
Sorry 'bout the bug in that.