Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-28-2012, 12:07 AM   PM User | #1
TylerB
New Coder

 
Join Date: Aug 2012
Location: Kalamazoo, MI
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
TylerB is an unknown quantity at this point
Featured Post on Custom Blogging System

I am building a personal blog for myself which has a fully functional administration panel that allows me to add, edit, and delete blogs very simply. I would like to add a "Featured" blog option which will position the "Featured" blog before all the others, without messing up the order of the other blogs. Right now, the blogs are being called from MySQL database and being displayed by their post date in descending order (newest posts first.)

My question is; What would be the best way to implement this sort of feature on my custom blog? I plan on using a checkbox and reading whether it is checked or not for true/false, if checked the blog is featured, if not checked it is displayed in normal order. But I don't know how to take that one blog and place it atop the others after the mysql query orders them in descending order. I would also like to be able to "Unfeature" the blog and have it be removed from the top and returned to its original position (I'm assuming this won't be an issue because the actual blog ID won't be changing)

I can post some of my PHP code if that will help generate some ideas/answers...
TylerB is offline   Reply With Quote
Old 09-28-2012, 03:31 AM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
One way to do it is to store a flag in the posts table that marks the post row as featured or not. Nothing complicated, just a TINYINT(1) where 1 represents featured and 0 is normal. Once you have that you can just query the posts, ordering by the featured field first. Something like this:
Code:
SELECT
    *
FROM
    `blog_posts`
WHERE
    `status` = 'published'
ORDER BY
    `featured` DESC, `post_date` DESC
Inigoesdr is offline   Reply With Quote
Reply

Bookmarks

Tags
blogs, mysql, php, queries

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:02 PM.


Advertisement
Log in to turn off these ads.