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

parameter - Add a paramter to page url

programmeradmin1浏览0评论

I have a custom page template products, so i get the url site/products. I want to add a parameter (for example product) to this url, so that I can access this page using url site/products/product-1 or site/products/product-2 etc.

How can I add this parameter and make that url accessible?

I have a custom page template products, so i get the url site/products. I want to add a parameter (for example product) to this url, so that I can access this page using url site/products/product-1 or site/products/product-2 etc.

How can I add this parameter and make that url accessible?

Share Improve this question asked Mar 2, 2021 at 19:36 JayJay 1
Add a comment  | 

2 Answers 2

Reset to default 0

If you were willing to use a plugin you could use Custom Post Type UI to create a "products" custom post type. Any post made inside this post type would give the permalink you wanted.

So, adding a parameter to your url would look like this, with everything after the ? being a parameter:

example/products?product=product-1

But it sounds like maybe you're after using custom post types or at least a post in a category.

Say you have a CPT of "products" and a post of that type which is titled "Product 1". Your permalink would look like:

example/products/product-1

Or, maybe no CPT, but you do have a category named "Products" and a post under that category named "Product-2". (The caveat here is that you'd need to make sure your permalink structure supports this. In the WP admin panel, Settings >> Permalinks). Your url might look something like:

example/products/product-2

All of that is just to give you a little bit of context. It sounds like you're after something like a Custom Post Types plugin, or if you're into it, an ecommerce solution like WooCommerce.

It might also help to understand what a custom post type is. WordPress stores and displays contents as posts. It categorizes them as post types on your website. Even a "Page" is a type of post (a post type), in WP. Other post types that come out of the box, and that you might use without even knowing they are a post type:

  • Post (Post Type: 'post')
  • Page (Post Type: 'page')
  • Attachment (Post Type: 'attachment')
  • Revision (Post Type: 'revision')
  • Navigation menu (Post Type: 'nav_menu_item')

A Custom Post Type is a custom content type. So, examples might be:

  • Events
  • Media
  • Testimonials
  • Deals
  • Places
  • Downloads

and in your case, Products. Every time you'd create a post in the post type Products, your url will be generated based on your permalink structure, which you set up in settings. See the docs for more detail on choosing your structure.

I hope this clarifies some things! I remember that once I wrapped my head around the idea that "everything is a post type" in WP it was a game changer. :)

发布评论

评论列表(0)

  1. 暂无评论