PHP - 突出显示选定的链接

发布于 2024-08-14 08:52:58 字数 1319 浏览 8 评论 0原文

如何“突出显示”(变成不同的颜色、加粗等等……)已单击的链接?

示例如下: http://www.celebrything.com/ 尝试让右侧边栏中的“今天”、“周”和“月”链接在单击后变成不同的颜色。

这是我用来在右侧边栏中显示结果的代码:

<div id="sidebar">

<div class="post">
<h2>

<font color="#333333">Top 50 Celebrities</font>
<br>
<br>
<font color="#333333"><a href="index.php?table=today">Today</a></font>
<font color="#333333"><a href="index.php?table=week">Week</a></font>
<font color="#333333"><a href="index.php?table=month">Month</a></font>
</font>
<br>
<br>

<?php

function showTable ($table){

if (!in_array($table, array('today', 'week', 'month'))) {
  return false;
}

global $wpdb;
$result = $wpdb->get_results('SELECT name, count FROM wp_celebcount_' . $table);
foreach($result as $row) {
echo '<a href="http://www.celebrything.com/?s=' .
    urlencode($row->name) . '&search=Search">' . $row->name .
    '</a> - ' . $row->count . ' Posts<br/>';
}
}


if (!empty($_GET['table'])) {
showTable($_GET['table']);

} else { showTable('today'); }

?>




</h2>
</div>

</div>

<div class="clear"></div>

How do I "highlight" (turn to a different color, make bold, whatever..) a link that has been clicked on?

Example is here: http://www.celebrything.com/
Trying to get the Today, Week, and Month links in the right sidebar to turn a different color once clicked.

Here's the code I'm using to show the results in the right sidebar:

<div id="sidebar">

<div class="post">
<h2>

<font color="#333333">Top 50 Celebrities</font>
<br>
<br>
<font color="#333333"><a href="index.php?table=today">Today</a></font>
<font color="#333333"><a href="index.php?table=week">Week</a></font>
<font color="#333333"><a href="index.php?table=month">Month</a></font>
</font>
<br>
<br>

<?php

function showTable ($table){

if (!in_array($table, array('today', 'week', 'month'))) {
  return false;
}

global $wpdb;
$result = $wpdb->get_results('SELECT name, count FROM wp_celebcount_' . $table);
foreach($result as $row) {
echo '<a href="http://www.celebrything.com/?s=' .
    urlencode($row->name) . '&search=Search">' . $row->name .
    '</a> - ' . $row->count . ' Posts<br/>';
}
}


if (!empty($_GET['table'])) {
showTable($_GET['table']);

} else { showTable('today'); }

?>




</h2>
</div>

</div>

<div class="clear"></div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

勿忘初心 2024-08-21 08:52:58

CSS 可以做到这一点。

如果某个链接在任何时候被访问过:

<style type="text/css">
a:visited { color: red; }
</style>

如果该链接具有焦点:

a:focus { color: red; }

注意: IE7 及更低版本不支持 :focus。请参阅 CSS 内容和浏览器兼容性:focus

CSS can do this.

If a link has been visited at any point:

<style type="text/css">
a:visited { color: red; }
</style>

If the link has focus:

a:focus { color: red; }

Note: IE7 and lower don't support :focus. See CSS contents and browser compatibility and :focus.

压抑⊿情绪 2024-08-21 08:52:58

如果您询问如何使当前页面处于活动状态,那么您可以这样做:

<font color="#333333"><a class="<?php echo currentPage('today') ?>" href="index.php?table=today">Today</a></font>
<font color="#333333"><a class="<?php echo currentPage('week') ?>" href="index.php?table=week">Week</a></font>
<font color="#333333"><a class="<?php echo currentPage('month') ?>"href="index.php?table=month">Month</a></font>


function currentPage($isTableSet)
{
    if($_GET['table'] == $isTableSet)
        return 'selected'
    else
        return '';
}

并且您将需要在 css 中添加 .selected 类并将其样式设置为您想要的任何样式,也许是这样的:

<style type="text/css">
    .selected  {
        font-weight: bold;
    }
</style>

If your asking howto make the current page active here is how you can do it:

<font color="#333333"><a class="<?php echo currentPage('today') ?>" href="index.php?table=today">Today</a></font>
<font color="#333333"><a class="<?php echo currentPage('week') ?>" href="index.php?table=week">Week</a></font>
<font color="#333333"><a class="<?php echo currentPage('month') ?>"href="index.php?table=month">Month</a></font>


function currentPage($isTableSet)
{
    if($_GET['table'] == $isTableSet)
        return 'selected'
    else
        return '';
}

And you will need to add the .selected class in your css and style it to whatever you want, maybe something like this:

<style type="text/css">
    .selected  {
        font-weight: bold;
    }
</style>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文