Last active
December 22, 2015 18:19
-
-
Save melissacabral/6512630 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aside id="complementary"> | |
<?php | |
//get the titles of the most popular (by number of comments) 5 published posts | |
$query_popular = 'SELECT posts.title, posts.post_id, COUNT(*) AS numcomments | |
FROM posts, comments | |
WHERE posts.is_published = 1 | |
AND posts.post_id = comments.post_id | |
GROUP BY posts.post_id | |
ORDER BY numcomments DESC | |
LIMIT 5'; | |
//run the query | |
$result_popular = $db->query($query_popular); | |
//make sure at least one post was found | |
if( $result_popular->num_rows >= 1 ){ | |
?> | |
<section> | |
<h3>Most Popular Posts</h3> | |
<ul> | |
<?php //loop through each row in the results | |
while( $row_popular = $result_popular->fetch_assoc() ){ ?> | |
<li><a href="#"><?php echo $row_popular['title']; ?></a> | |
(<?php echo $row_popular['numcomments']; ?>)</li> | |
<?php } //end while ?> | |
</ul> | |
</section> | |
<?php }// and if posts found ?> | |
<?php | |
//get the titles of the latest 5 published posts | |
$query_latest = 'SELECT title, post_id | |
FROM posts | |
WHERE is_published = 1 | |
ORDER BY date DESC | |
LIMIT 5'; | |
//run the query | |
$result_latest = $db->query($query_latest); | |
//make sure at least one post was found | |
if( $result_latest->num_rows >= 1 ){ | |
?> | |
<section> | |
<h3>Latest Posts</h3> | |
<ul> | |
<?php //loop through each row in the results | |
while( $row_latest = $result_latest->fetch_assoc() ){ ?> | |
<li><a href="#"><?php echo $row_latest['title']; ?></a> | |
(X) </li> | |
<?php } //end while ?> | |
</ul> | |
</section> | |
<?php }// end if posts found ?> | |
<section> | |
<h3>Categories</h3> | |
<ul> | |
<li><a href="#">CATEGORY NAME</a></li> | |
<li><a href="#">CATEGORY NAME</a></li> | |
<li><a href="#">CATEGORY NAME</a></li> | |
</ul> | |
</section> | |
<section> | |
<h3>Links</h3> | |
<ul> | |
<li><a href="#">TITLE</a></li> | |
<li><a href="#">TITLE</a></li> | |
<li><a href="#">TITLE</a></li> | |
</ul> | |
</section> | |
</aside> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment