Dynamic SSI...
Moderator: General Moderators
Dynamic SSI...
Hello,
I have an include file, x.inc.php. In it, I have a table with a menu full of navigation links set up.
Is there a way to make the links dynamic in the include file so that when it is called by the parent page, each link bolds separately so that the user knows which page they are on?
I tried the following:
<?php
if ( $PAGE_TITLE == "Resources: Books" ) {
echo "<strong>";
} else {
echo "";
} ?>
<a href="/resources/books/index.php">Books</a>
<?php
if ( $PAGE_TITLE == "Resources: Books" ) {
echo "</strong>";
} else {
echo "";
} ?>
This bolds every link when the inc. is called
The following Doesn't work at all:
if ($PAGE_TITLE = "Resources: Books") echo '<strong>';
??????
Thanks!
I have an include file, x.inc.php. In it, I have a table with a menu full of navigation links set up.
Is there a way to make the links dynamic in the include file so that when it is called by the parent page, each link bolds separately so that the user knows which page they are on?
I tried the following:
<?php
if ( $PAGE_TITLE == "Resources: Books" ) {
echo "<strong>";
} else {
echo "";
} ?>
<a href="/resources/books/index.php">Books</a>
<?php
if ( $PAGE_TITLE == "Resources: Books" ) {
echo "</strong>";
} else {
echo "";
} ?>
This bolds every link when the inc. is called
The following Doesn't work at all:
if ($PAGE_TITLE = "Resources: Books") echo '<strong>';
??????
Thanks!
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
What I have done in the past to do this was to store the sites content in a database and have the content be relative to a page name. Then when the user lands on a certain page, use the basename() PHP function to find the name of the page and as you are looping through the links from the database, find the link whose page is the same as the one you are on and bold it.
It is a pretty easy thing to do, you just need to carefully think of the logic in the display process.
It is a pretty easy thing to do, you just need to carefully think of the logic in the display process.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Well, I'm posting the links in a table. Nothing Complicated.
<td valign="middle" class="x">
<?php
if ( $PAGE_TITLE == "y" ) {
echo "<strong>";
} else {
echo "";
}
?>
<a href="/z/index.php">Link Name</a><?php
if ( $PAGE_TITLE == "y" ) {
echo "</strong>";
} else {
echo "";
}
?>
</td>
Does this give you the answer to the question you are asking?
<td valign="middle" class="x">
<?php
if ( $PAGE_TITLE == "y" ) {
echo "<strong>";
} else {
echo "";
}
?>
<a href="/z/index.php">Link Name</a><?php
if ( $PAGE_TITLE == "y" ) {
echo "</strong>";
} else {
echo "";
}
?>
</td>
Does this give you the answer to the question you are asking?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Not exactly. Where are the links coming from? Are they hard coded into your script...
Or are they generated dynamically through a loop of some sort...
In order to do what you want you are going to need to dynamically generate your links so you can check each one against your current page name. If it checks, then bold it. Otherwise, let it ride.
On a side note, can you wrap your posted code in the appropriate "Syntax" BBCode tags? Thanks. It helps us all see your code a little better.
Code: Select all
<a href="lik1.php">Go to link 1</a><br />
<a href="lik2.php">Go to link 2</a><br />
<a href="lik3.php">Go to link 3</a><br />
<a href="lik4.php">Go to link 4</a><br />
<a href="lik5.php">Go to link 5</a><br />Code: Select all
<?php
foreach ($link_array as $href => $text)
{
echo "<a href=\"$href.php\">$text</a><br />";
}
?>On a side note, can you wrap your posted code in the appropriate "Syntax" BBCode tags? Thanks. It helps us all see your code a little better.
The links are coming from an inc. file. In the inc. file that has the table with the links, I have:
The index page calls the include file: <?php include('resources_other.inc.php');?>
I know that this is causing the bolding to occur on some of the links. So it's writing the HTML, just not selectively.
Is this an any better explanation? Thanks for your patience!
Code: Select all
<td valign="middle" class="inthissection">
<?php if ( $PAGE_TITLE == "x" ) {
echo "<strong>";
} else {
echo "";
} ?>
<a href="/resources/index.php">x</a> <?php if ( $PAGE_TITLE == "x" ) {
echo "</strong>";
} else {
echo "";
} ?>
</td>
<td valign="middle" class="inthissection">
<?php if ( $PAGE_TITLE == "y" ) {
echo "<strong>";
} else {
echo "";
} ?>
<a href="/facts/index.php">y</a> <?php if ( $PAGE_TITLE == "y" ) {
echo "</strong>";
} else {
echo "";
} ?>
</td>I know that this is causing the bolding to occur on some of the links. So it's writing the HTML, just not selectively.
Is this an any better explanation? Thanks for your patience!
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
My personal opinion... this is an horribly inefficient way of looping links.
My typicaly process is to database as much as I can, then pull what I need, loop through the result and match as needed. For what you are doing, I might step it down to an array of links as opposed to a db resultset, but I would still be inclined to loop through them and match as needed.
My typicaly process is to database as much as I can, then pull what I need, loop through the result and match as needed. For what you are doing, I might step it down to an array of links as opposed to a db resultset, but I would still be inclined to loop through them and match as needed.
Code: Select all
<?php
$link_array = array(
'about' => 'About Us',
'contact' => 'Contact Us',
'info' => 'More Info',
'address' => 'Our Location');
$this_page = basename($_SERVER['PHP_SELF']);
foreach ($link_array as $href => $text)
{
if ($href == $this_page)
{
echo "<a href=\"$href.php\"><strong>$text</strong></a><br />";
}
else
{
echo "<a href=\"$href.php\">$text</a><br />";
}
}
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA