简体   繁体   中英

How to add a custom ID to a Wordpress page with pagination?

I have a Wordpress page. When I add a custom ID to the URL, I get unwanted 'paged' page.

I want an overview of custom data from an API. When I click on a item, it should be redirected to '/mypage/10'. I already build a plugin with shortcodes , which retrieves the data from the API and displays it.

Then I want want to check if my page 'mypage' has a ID in the URL. If so, retrieves new data and shows it.

Looked across the internet, but can't find what I want.

Validate the ID through GET parameters using

'mypage?ID=10'

And just check at the API side for:

$_GET['ID']

That should avoid any routing issues or having to rewrite the routes. Also make sure you escape your variables properly.

Update for SEO purpose

As of taken directly from wordpress, you could add a custom route rule to your application, using the following:

function custom_rewrite_basic() {
  add_rewrite_rule('^mypage/([0-9]+)/?', 'index.php?page_id=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_basic');

Just edit the 'index.php?page_id=$matches[1]', to match your own destination.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM