2009-12-12 22 views
0

如何「突出顯示」(轉向不同的顏色,使粗體,無論..)已點擊的鏈接?PHP - Highligh選定的鏈接

示例在這裏: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> 

回答

5

CSS可以做到這一點。

如果鏈接已經在任何點被訪問:

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

如果鏈路具有焦點:

a:focus { color: red; } 

注: IE7和更低的不支持:focus。請參閱CSS contents and browser compatibility:focus

+0

可能想提及,這是CSS和如何把它放在樣式表中... – pstanton 2009-12-12 01:16:54

1

如果你問HOWTO使當前頁面主動這裏是你如何能做到這:

<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>