• Resolved nanech

    (@nanech)


    Hi, i have question about the categories

    is there a way to add random category button to display category page not the posts in the category, just the category page

    thank you ??

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    But doesn’t every category page show posts in the category? I think I know what you mean. The thing to do is probably to randomly assign a category page permalink to the button link. Every time the page reloads, it gets a different link.

    Getting a random category could be done with a custom SQL query to get the term_id from the term_relationships table, where taxonomy is ‘category’, ordered by RANDOM() LIMIT 1. With the term ID, you can get the slug from the terms table, and with a slug you can construct a permalink.

    If you want a different random page every time button is clicked without reloading the page, it could be done by making an AJAX request where the AJAX handler makes that random query and returns the result. The AJAX response function then can assign the URL to window.location to navigate to that page.

Viewing 1 replies (of 1 total)
  • The topic ‘Create Random button For Categories’ is closed to new replies.