Show selected categories post else show newest feature
What I am trying to do is show selected categories if selected, else show the top 10 newest posts. I have the categories working great but want to take it a step further. The best example I can give you is youtube.com. On the homepage they show some of the most trending videos, what I wan to do is just show the 10 newest posts. I have the categories populate dynamically and when they click on a category the contect changes accordingly. Here is the code...
$categories = getRegisteredCategories($Read);
if (isset($_GET['category']) && in_array($_GET['category'], $categories)) {
$selected = $_GET['category'];
} else {
$selected = "Street";
}
$posts = getPostByCategory($Read, $selected);
Here are the buttons populating...
<?php foreach ($categories as $category) { ?>
<input name="category" type="submit" id="category" value="<?php echo $category ?>"
<?php if ($category == $selected) {
echo 'selected="selected"';
}
?>/>
<?php } ?>
And here is the content....
<?php foreach ($posts as $post) { ?>
<p><strong><?php echo $post['name']; ?>: </strong><?php echo $post['description']; ?> <a href="post_details.php?post=<?php echo $post['link_name']; ?>">More</a></p>
<?php } ?>
