Detect the browsed page from url in wordpress

2019-09-18 09:38发布

问题:

I have underlined and italicized the post titles in homepage via jquery. I have written the jquery code in footer. The header and footer are commonly called in all inside pages and homepage as well. So when I click on the post titles in the homepage, the single post page is browsed but I can still see the same style for the post title like in the homepage. I need to detect the page through url as i have set the url pattern to %post_name% in the admin panel. Moreover I have to place a condition to detect the pages. If it is the homepage I have to enable the code else nothing.

Please help me with this.

回答1:

Just add a simple:

if (is_front_page()) { do this }
else { do that }

A little bit more about conditional wordpress tags: http://codex.wordpress.org/Conditional_Tags



回答2:

wp_list_pages function should get you what you're looking for.