Copy link to clipboard
Copied
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 } ?>
Copy link to clipboard
Copied
Can anyone help me with this enhancement? I have added some more code, which is just another button, and this one is static.
$categories = getRegisteredCategories($Read);
if (isset($_GET['category']) && in_array($_GET['category'], $categories)) {
$selected = $_GET['category'];
} else {
$selected = "default";
}
$posts = getPostByCategory($Read, $selected);
$defaults = getdefaultposts($Read);
<input name="default" type="submit" id="default" value="default"> />
<?php foreach ($categories as $category) { ?>
<input name="category" type="submit" id="category" value="<?php echo $category ?>"
<?php if ($category == $selected) {
echo 'selected="selected"';
}
?>/>
<?php } ?>
But my problem is with the content that is being displayed. If I basically duplicate the content portion it obviously stays on the page, when a button (category) is selected. How can I have it so that this content (default) dissappears when a button (category) is selected?
<?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 } ?>
<?php foreach ($defaults as $default) { ?>
<p><strong><?php echo $default['name']; ?>: </strong><?php echo $default['description']; ?> <a href="post_details.php?post=<?php echo $default['link_name']; ?>">More</a></p>
<?php } ?>
The only solution I have been able to come up with is having to create two seperate pages, one that has the default content and one that updates using ajax with the category buttons so that the page is refreshing...
Any help would be greatly appreciated! Thanks for your time.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now