我有一个网站正在建设中,使用 PHP MYSQL,其中包含一个包含三列的新闻页面。
col1(中间列)显示新闻标题和新闻文本。
col2(左列)显示 10 个最新新闻条目的标题。
col3(right column) - 是显示月份和年份的档案栏。
就像我上面所说的,最近的新闻栏 (col2) 显示了 10 个最近的新闻条目的标题。当我单击特定标题时, col1 会显示与该标题对应的主要内容。我想要做的是突出显示 col2 中的活动标题。有没有办法使用 css & PHP 做到这一点?
数据库查询如下:
mysql_select_db($database_admin_conn, $admin_conn);
$query_getArchives = "SELECT DISTINCT DATE_FORMAT (news.updated, '%M %Y') AS archive, DATE_FORMAT (news.updated, '%Y-%m') AS link FROM news ORDER BY news.updated DESC";
$getArchives = mysql_query($query_getArchives, $admin_conn) or die(mysql_error());
$row_getArchives = mysql_fetch_assoc($getArchives);
$totalRows_getArchives = mysql_num_rows($getArchives);
mysql_select_db($database_admin_conn, $admin_conn);
$query_getRecent = "SELECT news.news_id, news.title FROM news ORDER BY news.updated DESC LIMIT 10";
$getRecent = mysql_query($query_getRecent, $admin_conn) or die(mysql_error());
$row_getRecent = mysql_fetch_assoc($getRecent);
$totalRows_getRecent = mysql_num_rows($getRecent);
$var1_getDisplay2 = "-1";
if (isset($_GET['archive'])) {
$var1_getDisplay2 = $_GET['archive'];
$query_getDisplay = sprintf("SELECT news.news_id, news.title, news.news_entry, DATE_FORMAT (news.updated, '%%M %%e, %%Y') AS formatted FROM news WHERE DATE_FORMAT(news.updated, '%%Y-%%m') = %s ORDER BY news.updated DESC", GetSQLValueString($var1_getDisplay2, "text"));
} elseif (isset($_GET['news_id'])) {
$var2_getDisplay3 = $_GET['news_id'];
$query_getDisplay = sprintf("SELECT news.news_id, news.title, news.news_entry, DATE_FORMAT(news.updated, '%%M %%e, %%Y') AS formatted FROM news WHERE news.news_id=%s ", GetSQLValueString($var2_getDisplay3, "int"));
} else {
mysql_select_db($database_admin_conn, $admin_conn);
$query_getDisplay = "SELECT news.news_id, news.title, news.news_entry, DATE_FORMAT (news.updated, '%M %e, %Y') AS formatted FROM news ORDER BY news.updated DESC LIMIT 3";
}
$getDisplay = mysql_query($query_getDisplay, $admin_conn) or die(mysql_error());
这是新闻页面的 html/css 的相关摘录:
<div class="col1">
<div class="news">
<?php while($newsItem = mysql_fetch_array($getDisplay))
{ ?>
<?php $arrayNews[$getDisplay['news_id']] = $newsItem; ?>
<?php foreach($arrayNews AS $newsItem)
{ ?>
<h1> <?php echo $newsItem['title'] ; ?> <h3><?php echo $newsItem['formatted'];?></h3></h1>
<?php $query_getPhotoDetails = "SELECT *
FROM photos INNER JOIN news2photo USING (photo_id)
WHERE news2photo.news_id = '" . $newsItem['news_id'] . "' LIMIT 3
";
$getPhotoDetails = mysql_query($query_getPhotoDetails, $admin_conn) or die(mysql_error());
while($photo = mysql_fetch_array($getPhotoDetails))
{ ?>
<div class="imagefield">
<p> </p>
<p> <img src="../images/<?php echo $photo['filename']; ?>" width="200" />
</p>
</div>
<?php }
?>
<?php $newsItem['news_entry'] = preg_replace("/((http)+(s)?:\/\/[^<>\s]+)/i", "<a href=\"\\0\" target=\"_blank\">\\0</a>", $newsItem['news_entry'] ); ?>
<div class="newsitem">
<p> </p>
<p> <?php echo nl2br($newsItem['news_entry']);
?>
</p>
</div>
<?php } ?>
<?php } ?>
</div><!--end news-->
</div>
<div class="col2">
<h3>Recent News</h3>
<ul>
<?php do {
?> <li class="seperator"><a href="news.php?news_id=<?php echo $row_getRecent['news_id'];
?>"><?php echo $row_getRecent['title']; ?></a></li>
<?php } while ($row_getRecent = mysql_fetch_assoc($getRecent)); ?>
</ul>
</div>
<div class="col3"><h3>News Archives</h3>
<ul>
<?php do { ?>
<li class="seperator"><a href="news.php?archive=<?php echo $row_getArchives['link']; ?>"><?php echo $row_getArchives['archive']; ?></a></li>
<?php } while ($row_getArchives = mysql_fetch_assoc($getArchives)); ?>
</ul>
</div>
一切正常,但我需要帮助突出显示“最近新闻”(col2)列中的当前列表项。我确实搜索了很多,但几乎所有的解决方案都是 wordpess 特定的。提前致谢 :)