0

Hello the community,

I would like to know if is it possible to generate menu links using the PHP Get Method instead of the regural one used in Wordpress? e.g :

www.mybeautifulwebsite.com/category/sport?sport=football

instead of

www.mybeautifulwebsite.com/category/sport/football


Explanation:

My page about sports news list 1 news per sport, like this:

Sports News

My page about a particular sport news list all of its news, like this:

Football News

As you can see, it's quite the same page. So I want to reuse my page about "Sports News" to display the news about each sport.

For information:

Football, Basket-ball, ... are sub-categories of the Sport category

I registered my sport sub-menu via register_nav_menus() in my functions.php and called it via wp_nav_menu() in my category-sport.php.

I think I can create this sub-menu manually or create my menu with custom links to do what I want, but:

  1. I want to know if there is a more beautiful way to do it
  2. I want to know if my way of thinking is good because I'm new in Wordpress development

Thank you!

6
  • Do you mean GET parameters rather than POST parameters? A POST request doesn't add things to the URL as it sends parameters in the HTTP headers
    – Tom J Nowell
    Jan 28, 2020 at 13:55
  • 1
    Yes sorry for the confusion. I edit my question.
    – Gerald
    Jan 28, 2020 at 14:36
  • Why do you need to use a GET parameter. The second URL in your question will automatically list the posts that you want. It’s the default behaviour. Jan 28, 2020 at 14:47
  • Yes I'm agree but the archive pages for my Sport sub-categories need to be a little bit customized and not just list the posts like my "Health" archive for example. So, I thought of several solutions: 1. Customize my archive.php file 2. Create one category-$slug.php file for each sport, like I did for the Sport page 3. Find another way like the one I proposed. Maybe I'm totally wrong with the Wordpress mindset, just let me know. PS: The sub-menu will be only shown on the Sport main page and each Sport pages
    – Gerald
    Jan 28, 2020 at 15:06
  • Option 2 sounds better, you can always check the queried object ( get_queried_object() ) in the template to get the data, there's no need to change the URL and use $_GET
    – Tom J Nowell
    Jan 28, 2020 at 15:34

1 Answer 1

0

Well.
After a little search with the intention to find a way to re-use my category template (Sport), I found the solution of my problem: Force sub-categories to use the parent category template

So I let this solution here in case of someone has the same problem and the same weird idea to resolve it than me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.