最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to load page template according to the Searched Page

matteradmin6PV0评论

I have a search form which uses RELEVANSSI plugin to perform search and display Search Results. On my Search Results page there is pagination and Search Filters(hyperlinks) which allows user to show 10, 20 or 30 records on screen.

The Issue: In my website I have some internal pages which have different HEADER AND FOOTER and a Search BOX. By adding some checks If user performs search from these internal pages then it will load relevant and correct header and footer. But if I click on Pagination Filter or Search Filters (Show 10 Records, show 20 records) then it will load main website header and footer.

I need a way to pass some variable which recognizes that from which page user come and according to that variable it will load header and footer.

Thanks

I have a search form which uses RELEVANSSI plugin to perform search and display Search Results. On my Search Results page there is pagination and Search Filters(hyperlinks) which allows user to show 10, 20 or 30 records on screen.

The Issue: In my website I have some internal pages which have different HEADER AND FOOTER and a Search BOX. By adding some checks If user performs search from these internal pages then it will load relevant and correct header and footer. But if I click on Pagination Filter or Search Filters (Show 10 Records, show 20 records) then it will load main website header and footer.

I need a way to pass some variable which recognizes that from which page user come and according to that variable it will load header and footer.

Thanks

Share Improve this question edited Mar 19, 2019 at 7:55 Eshban Bahadur asked Mar 19, 2019 at 7:43 Eshban BahadurEshban Bahadur 1251 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Just use wp_get_referer(), and a few other functions to get the simple name of the referring page, e.g.

if (basename(parse_url(wp_get_referer(), PHP_URL_PATH)) == 'my-search-page') {

(Or you could use string searching or matching instead of parse_urland basename).

(Also note wp_get_referer is deliberately misspelled. It originates in a misspelling in one of the web standards)

Addendum
Might have to tweak this a bit to deal with the case where there's no referrer (e.g. a bookmark was used to get to the page).

Post a comment

comment list (0)

  1. No comments so far