Created
April 28, 2011 01:33
-
-
Save chriscoyier/945619 to your computer and use it in GitHub Desktop.
commentgraph.php
This file contains hidden or 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
| <?php | |
| /* | |
| Template Name: Comment Graph | |
| */ | |
| ?> | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset=utf-8> | |
| <title>Comment Graph</title> | |
| <style> | |
| #chart { margin: 0 auto; padding: 100px 0; height: 400px; position: relative; text-align: center; } | |
| #chart > a { | |
| width: 1px; | |
| background: red; | |
| background: -webkit-linear-gradient(top, hsl(27, 95%, 45%), hsl(27, 95%, 65%), hsl(27, 95%, 45%)); | |
| background: -moz-linear-gradient(top, hsl(27, 95%, 45%), hsl(27, 95%, 65%), hsl(27, 95%, 45%)); | |
| background: -ms-linear-gradient(top, hsl(27, 95%, 45%), hsl(27, 95%, 65%), hsl(27, 95%, 45%)); | |
| background: -o-linear-gradient(top, hsl(27, 95%, 45%), hsl(27, 95%, 65%), hsl(27, 95%, 45%)); | |
| background: linear-gradient(top, hsl(27, 95%, 45%), hsl(27, 95%, 65%), hsl(27, 95%, 45%)); | |
| display: inline-block; | |
| vertical-align: middle; | |
| text-decoration: none; | |
| } | |
| #chart > a:hover { | |
| background: black; | |
| } | |
| #chart span { | |
| width: 50px; | |
| background: black; | |
| color: white; | |
| text-align: center; | |
| padding: 10px; | |
| position: absolute; | |
| top: 0; | |
| left: 50%; | |
| margin-left: -30px; | |
| opacity: 0; | |
| z-index: 1; | |
| } | |
| #chart > a:hover > span { | |
| opacity: 1; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <?php | |
| $i = 1; | |
| $query = "SELECT comment_count FROM " . $wpdb->posts . " WHERE post_type = 'post' && post_status = 'publish' ORDER BY comment_count DESC LIMIT 1"; | |
| $results = $wpdb->get_results($query); | |
| $maxComments = $results[0]->comment_count; | |
| query_posts('posts_per_page=-1&order=ASC'); | |
| ?> | |
| <div id="chart"> | |
| <?php | |
| while (have_posts() ) : the_post(); | |
| // Echo the first year post published | |
| if ($i == 1) { echo "<strong>" . the_date("Y") . "</strong>"; } | |
| $numComments = get_comments_number(); | |
| $heightPercentage = (($numComments / $maxComments) * 100); | |
| echo "<a href='"; | |
| echo get_permalink(); | |
| echo "' style='height: $heightPercentage%;'>"; | |
| // echo strip_tags(get_the_title()); | |
| echo "<span>$numComments</span>"; | |
| echo "</a>"; | |
| $i++; | |
| endwhile; | |
| // Echo the last year post published | |
| echo "<strong>" . the_date("Y") . "</strong>"; | |
| ?> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment