I have a website under construction, using PHP MYSQL, which contains a news page with three columns.
-
col1(middle column) displays the news title and news text.
-
col2(left column) displays the titles of 10 most recent news entries.
-
col3(right column) – is an archives column that displays the month and year.
Like I said above, the Recent News column (col2) displays the titles of the 10 most recent news entries. When I click on a particular title, then col1 displays the main content corresponding to that title. What I want to do is to highlight the active title in col2. Is there a way to do this using css & PHP?
The db queries are as below:
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());
And here is the relevant extract of the html/css for news page:
<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>
Things work fine, but I need help with highlighting the current list item in the ‘Recent News’ (col2) column.
I did search quite a bit, but almost all of solutions are wordpess specific.
Thanks in advance 🙂
I’m not quite sure what you want highlighted how.
What I think you’re trying to do is add some effect to the
<li>s in thecol2div when a user is over that space?You can easily achive this by putting something like this between your
<head></head>tags:What this does is toggle a CSS class on or off on your
<li>tags undercol2after your page has loaded.EDIT: To mark the currently selected news item in the
col2div, make a class for it in the header and apply it based on the submitted news_id:EDIT2: To mark the currently selected month in
col3, you’d have to mark<li>s like this: