WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Different sort ordering ajaxed? (3 posts)

  1. haagendazs1
    Member
    Posted 6 years ago #

    hi,

    i have a site about books which has a catalog
    in it, there's a page /catalog/, and it's basically a table with headings including Book Name, Author, and Number of Pages

    each post i make is about 1 book, and has custom fields name, author, and pages

    at the top of the table, i want to have buttons that say "Sort by Book Name", "Sort by Author", and "Sort by Number of Pages"

    so for example, when i click on "Sort by Book Name" the table will alphabetically sort all the posts based on the book's title (which in turn is based on the "name" custom field of each post)

    and i'd prefer the url to say /catalog/ or something like /catalog/?sort=name, like the way deviantart.com does it

    ultimately i'd prefer it to be ajaxable, but right now i don't care if it isn't ajaxed.

    at the moment i know how to sort this specific /catalog/ page in any of the 3 ways (book title, author, page number). the problem is getting a button (eg. the "Sort by Book Name" button) to reload the page but with a different sort order.

    if anyone can help, i'd be very thankful!!! :)

  2. haagendazs1
    Member
    Posted 6 years ago #

    I think I figured this one out! thanks anyone who might have helped :)

    Anyways for anyone who might want to know this, what i did was use simple php $_GET commands to do it

    for example, make a div around "Sort by Author", make it a link that goes to something like .../catalog/?sort=author

    then at the top of the page template, type
    <?php $sortby = $_GET['author']; ?>

    in your query, have something like
    $query = SELECT *...etc...'.$sortby.'...etc...

    that way, you can also have a "Sort by Pages" button that href is .../catalog/?sort=page

    i guess this wasn't really a wordpress question, but more of just a general php kind of question.

    thanks!

  3. the-surfcamp.com
    Member
    Posted 5 years ago #

    Hi haagendazs1,

    I am new to wordpress and would like to add a table with sorting functionality to my blog (products - description of the product - adding some pics). I think that is exactly what you are describing above. Is there a good plugin you could recommend? I have no programming skills... is there a easy to use solution out there?

    Thanks a lot!!!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags