The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End List post date and title within a category

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #28801


    I would like to produce the php to list posts only within a particular category, with their post dates listed above. I also want to be able to limit the number of posts and style the date and post title independently.

    I’m not sure if I’m wording this perfectly, but the final product should look like the image above. I’ve found a couple articles online that take very different approaches to seemingly the same issue, and implementing either of their ideas didn’t work properly. One of them got the post titles to list, but didn’t restrict the posts to one category.

    Thanks for your help!


    How is your database set up?

    If you have each item as a row with an id as a primary key, simply run the php to get the mysql and output it. The basics follow:

    This will get you the five most recent posts.

    $sql = “SELECT * FROM post_table LIMIT 5 ORDER BY id desc”

    Then, do this (I forget the raw php methods for getting sql stuff, but you can look them up):

    $results = my_sql_query($sql);
    foreach ($results as $result) {
    echo $result->title;
    echo $result->date;

    Depending on how much php programming you’ve done, there’s a chance the above will be confusing. If this is the case, I’d encourage you to look up php arrays. Check out php’s foreach keyword and how it works, too. In the example above, $results represents the mysql object returned from a query. The foreach block handles this object like an array, extracting one row at a time and calling it $result. Then, it simply accesses the attributes needed in that row. title, date, etc. are column names in your table.

    Best of luck, and let me know if you have any questions.


    I just reread your question, and your want of extracting only a particular category. This is done in the sql statement. SELECT * FROM post_table WHERE category=whatever_category_you_want

    Finally, the fact that you want to style them independently says you’re ready to do some research on the Model-View-Controller software design pattern. MVC is a fantastic way to separate your php logic from your presentation. It also keeps your data encapsulated very cleanly. There are many php frameworks out there that use MVC as their pattern. I’ve used CodeIgniter, which is fantastic. Also, at my work we use Kohana, which is also great. CodeIgniter is where I’d start, as its learning curve is less severe.


    Wow! Democritus, thank you so much for all the info. I’ll read up. I love this forum and all its members! I can’t express how much I’ve learned in the past few months.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.