最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Menu links URL with PHP GET method

programmeradmin3浏览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/category/sport?sport=football

instead of

www.mybeautifulwebsite/category/sport/football


Explanation:

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

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

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!

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/category/sport?sport=football

instead of

www.mybeautifulwebsite/category/sport/football


Explanation:

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

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

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!

Share Improve this question edited Jan 28, 2020 at 14:37 Gerald asked Jan 28, 2020 at 13:42 GeraldGerald 12 bronze badges 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 Commented Jan 28, 2020 at 13:55
  • 1 Yes sorry for the confusion. I edit my question. – Gerald Commented 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. – Jacob Peattie Commented 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 Commented 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 Commented Jan 28, 2020 at 15:34
 |  Show 1 more comment

1 Answer 1

Reset to default 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论