Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8289373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:29:38+00:00 2026-06-08T12:29:38+00:00

I’m trying to create a simple sorting option for posts in my blog. The

  • 0

I’m trying to create a simple sorting option for posts in my blog. The problem is the last thing I want to use is a JS-based redirections because of the fact some users don’t have JS enabled in their browsers, thats why they wont be able to sort posts in me blog. Let me give you an example:

I have several categories in my blog:

//categories selection
<ul>
    <li class="active"><a id="cat1" href="/?category=music">Music</a></li>
    <li><a id="cat2" href="/?category=photo">Photo</a></li>
    <li><a id="cat3" href="/?category=cinema">Cinema</a></li>
    <li><a id="cat4" href="/?category=computers">Computes</a></li>
</ul>

Also, I have two sorting options:

//sorting options
<div>
    <a class="active">Last posts</a>
    <a>Last comments</a>
</div>

Depening on current active elements, user is redirected on page with such parameters, e.g. ‘/?category=music&sort=posted’ or ‘/?category=personal&sort=commented’.

For example, lets take that in categories selection ‘CINEMA’ tab is active at this moment (

<li class="actvie"><a id="cat3" href="/?category=cinema">Cinema</a></li>

). So, if user clicks Last comments link, it should redirect to

'/?category=cinema&sort=comments'

Another example: currently Last comments is active (

<a class="active">Last comments</a>

). User clicks on Computes in category selection and it should redirect to

'/?category=computers&sort=comments'.

So, are there any variants for performing such feature without JS? If no, could you suggest me the most elegant solution except manually running over every element in category and sorting optiona and generation link with JS/jQuery?

Thanks in advance!

SERVER SIDE:

db.collection("posts", function (err, collection) {
    //getting posts dependinc on requested category
    collection.find({category: req.query['category']}, {sort: [['time_added', -1]], limit:20}, function (err, posts) {
        //getting posts and rendering page
    });
});

UPDATE: I’ve found a so-so solution. For a separate category I render two div’s with different posts list. One for ‘Last posted’, the second – for ‘Last commented’. And the sort selector will just hide one div and shows another. The problem is just twice data size transfering to client side. I know, it will require a bit JS, but the main category links would be clear without ‘#’-hrefs. And sort options – it’s just a toogle, it may not have real link.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:29:41+00:00Added an answer on June 8, 2026 at 12:29 pm

    Seems like you are doing a page refresh for selecting a new category. Use the selected category parameter to determine the URL of the sorting options. Would need some more code from your server side to give you a more concrete example.

    If you don’t want to use Javascript you will have to generate the href-attribute of your sorting links <a class="active">Last posts</a> dynamically based on which category is selected. How are you rendering the page today? Just static files? Have a look at a template engine like mustache.js and then you could do it like this:

    <a class="active" href="/?category={{category}}&sort=comments">Last posts</a>
    

    Have a look at this tutorial for an Node.js example using mustache.js
    http://mrjaba.posterous.com/a-gentle-introduction-to-nodejs

    Edited after your comment: Or something like this using EJS

    <div>
        <a href="/?category=<%=category%>&sort=posts" class="active">Last posts</a>
        <a href="/?category=<%=category%>&sort=comments">Last comments</a>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.