php - Modify code to pass a post id as a parameter in order to create a breadcrumb via AJAX in Wordpress -


I have a function that I use to create breadcrumbs on a WordPress site:

 < Code> function The_breadcrumb () {$ delimiter = '& gt;'; $ CurrentBefore = '& lt; Li & gt; & Lt; A & gt; '; $ CurrentAfter = '& lt; / A & gt; & Lt; / Li & gt; '; If (! Is_home () and! Is_front_page () || is_paged ()) {echo '& lt; Nav class = "breadcrumb" & gt; & Lt; Ul & gt; '; Global $ post; If (is_page ()) & amp;; $ Post- & gt; Post_perrent) {$ current before echo; Title(); Copy $ currentAfter; } Otherwise (is_page () and $ post- & gt; Post_paint) {$ parent_id = $ post- & gt; Post_paint; $ Breadcrumbs = array (); While ($ parent_id) {$ page = get_page ($ parent_id); $ Breadcrumb [] = '& lt; Li & gt; & Lt; A href = "'get_permalink ($ page-> ID)." & Gt; '. Get_the_title ($ page-> ID) '& lt; / A & gt; & Lt; / Li & gt; '; $ Parent_id = $ page- & gt; Post_perrent; } $ Breadcrumbs = array_reverse ($ breadcrumbs); Exorbitant $ currency crunch ($ Breadcrumbs as dollar pieces); Copy $ currentBefore; Title(); Copy $ currentAfter; } Echo & lt; / Ul & gt; & Lt; / Nav> '; }}   

But I would like to take a post_id (id's ID) as a parameter to use this function in an AGX function, which creates breadcrumbs for that page . function ajaxify () {$ post_id = $ _POST ['post_id']; $ Breadcrumb = the_breadcrumb ($ post_id); Print_r ($ breadcrumb); Die (); // trailing 0}

How can I get it?

Many thanks for your help.

You must pass post_id as an argument and in this way Retrieve post information:

  function The_breadcrumb ($ post_id) {$ delimiter = '& gt;'; $ CurrentBefore = '& lt; Li & gt; & Lt; A & gt; '; $ CurrentAfter = '& lt; / A & gt; & Lt; / Li & gt; '; // your query here $ args = array ('page_id' =>; $ post_id, // one page ID, post, or custom type 'post_type' = & gt; any '); // Here the information is $ myPost = new WP_Query ($ ARG); If (! Is_home () and! Is_front_page () || is_paged ()) {echo '& lt; Nav class = "breadcrumb" & gt; & Lt; Ul & gt; '; If (is_page () & amp; amp;! $ MyPost- & gt; Post_paint) {echo $ currentBefore; Title(); Copy $ currentAfter; } Otherwise (is_page () and $ myPost- & gt; post_paint) {$ parent_id = $ myPost-> Post_paint; $ Breadcrumbs = array (); While ($ parent_id) {$ page = get_page ($ parent_id); $ Breadcrumb [] = '& lt; Li & gt; & Lt; A href = "'get_permalink ($ page-> ID)." & Gt; '. Get_the_title ($ page-> ID) '& lt; / A & gt; & Lt; / Li & gt; '; $ Parent_id = $ page- & gt; Post_perrent; } $ Breadcrumbs = array_reverse ($ breadcrumbs); Exorbitant $ currency crunch ($ Breadcrumbs as dollar pieces); Copy $ currentBefore; Title(); Copy $ currentAfter; } Echo & lt; / Ul & gt; & Lt; / Nav> '; }    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -