How to make get_the_ID() function show the id of the page correct?
-
Hi! I have a wordpress installation with woocommerce. Every page like, for example, product category page, consists of several templates, combined together. For example, just after the header, i have “afterheader” template, where i want to show something, depending on product category id.
So, i use get_the_ID() function in this template. But it returns the id of template, not id of the product category page. Which function i can use to detect the id of whole page in the template?
-
Hi there!
Thanks for reaching out. It seems the site you are asking about is not hosted here with us at WordPress.com and is actually a self hosted, or WordPress.org, site.
I’d be happy to provide some general advice but keep in mind that we only offer support for WordPress.com hosted sites here in the forums.
I’m afraid I can’t help with specific code adjustments. However, I do have some recommendations. It sounds like you are trying to apply a specific and custom template to product category pages. To edit the product category template, you’ll want to make a copy of the file into your child theme. However, if you have several templates you are trying to apply to different product category pages, it will be a bit more involved.
You might check out the related question I found here: https://stackoverflow.com/questions/50612737/changing-wordpress-template-for-specific-product-category-page
Alternatively, you might consider creating custom category pages using WooCommerce blocks. More on this here:
https://woocommerce.com/posts/how-to-customize-your-online-store-with-woocommerce-blocks/
Should you need additional help with your self-hosted WordPress site, you will want to contact your host.
You can view the differences between WordPress.com and WordPress.org here:
https://wordpress.com/support/com-vs-org/
For more help with your WordPress.org website, visit the support forum at https://wordpress.org/support.
- The topic ‘How to make get_the_ID() function show the id of the page correct?’ is closed to new replies.