I-PHP: Sebenzisa i-WordPress ye-API ukwakha iKhowudi emfutshane kuluhlu lwezihlomelo

I-WordPress ye-WordPress

Sisebenza kumiliselo oluntsonkothileyo kumthengi weshishini ngoku. Indawo iyakhiwa kwiWordPress kodwa inetoni yeentsimbi kunye neempempe. Rhoqo, xa ndisenza olu hlobo lomsebenzi, ndiyathanda ukugcina ikhowudi yesiko yokubuyela kwakhona kamva kwezinye iisayithi. Kule meko, bendicinga ukuba ngumsebenzi oluncedo kangako, ndifuna ukwabelana ngawo nehlabathi. Sisebenzisa ifayile ye- Umxholo we-Avada WordPress kunye noMakhi wePhepha leFusion njengomxholo womzali, kunye nokuhambisa ikhowudi yesiko kumxholo womntwana.

IWordPress sele inemisebenzi embalwa kwi-API yayo enokusetyenziselwa ukudwelisa iziqendwana, njenge-wp_list_pages kunye ne-get_pages. Ingxaki kukuba ababuyisi lwazi lwaneleyo ukuba unethemba lokwenza ngamandla uluhlu kunye neqela lolwazi.

Ukulungiselela lo mthengi, bafuna ukuthumela iinkcazo zomsebenzi kwaye banoluhlu lokuvuleka kwemisebenzi ngokuzenzekelayo luya kwenziwa ngokuhla komhla wabo wokupapasha. Baye bafuna ukubonisa isicatshulwa sephepha.

Ke, okokuqala, kuye kwafuneka songeze inkxaso kwinkcazo yephepha. Kwiimisebenzi.php ngomxholo wabo, songeze:

yongeza_post_type_support ('iphepha', 'isicatshulwa');

Emva koko, kuye kwafuneka sibhalise ikhowudi emfutshane yesiko eya kuthi ivelise uluhlu lweziqendwana, amakhonkco kubo, kunye nesicatshulwa sabo. Yenza oku, kuya kufuneka sisebenzise i I-WordPress Loop. Kwiimisebenzi.php, songeze:

// Uluhlu lwezihlomelo kuLuhlu lomsebenzi dknm_list_child_pages ($ atts, $ content = "") {global $ post; $ atts = i-shortcode_atts (uluhlu ('ifempty' => 'Akukho ziRekhodi', 'aclass' => ''), ii-atts zeedola, 'uluhlu_subpages'); $ args = uluhlu ('post_type' => 'iphepha', 'posts_per_page' => -1, 'post_parent' => $ post-> ID, 'orderby' => 'publish_date', 'order' => 'DESC' ,); $ parent = entsha WP_Query ($ args); ukuba ($ umzali-> une_post ()) {$ umtya. = $ umxholo. ' '; ngelixa ($ parent-> have_post ()): $ parent-> the_post (); $ umtya. = ' '. fumana_i_ihloko ().' '; ukuba (has_excerpt ($ post-> ID)) {$ string. = '-'. get_the_excerpt (); } $ umtya. = ' '; okokugqibela; } enye {$ string = ' '. Iimali zeedola [' ifempty '].' '; } wp_reset_postdata (); buyisela umtya weedola; } ukongeza_shortcode ('uluhlu_subpages', 'dknm_list_child_pages');

Ngoku, ikhowudi emfutshane inokumiliselwa kwisiza sonke ukubonisa amaphepha omntwana ngekhonkco kunye nesicatshulwa. Ukusetyenziswa:

[list_subpages aclass = "button" ifempty = "Uxolo, okwangoku asinamisebenzi."] Uluhlu lweMisebenzi [/ uluhlu_subpages]

Iziphumo ziluhlu oluhle, nolungacocekanga lwemisebenzi epapashiweyo, engamaphepha abantwana phantsi kwephepha labo lomsebenzi.

Ukuba bekungekho misebenzi ipapashiweyo (akukho maphepha omntwana), iya kupapasha:

Uxolo, okwangoku asinayo nayiphi na imisebenzi evulekileyo.

Ukuba kukho imisebenzi epapashiweyo (amaphepha omntwana), iya kupapasha:

Uluhlu lweMisebenzi:

Ingaba ucinga ntoni?

Le sayithi isebenzisa i-Akismet ukunciphisa ugaxekile. Funda indlela idatha yakho yokubhaliweyo isetyenziswe ngayo.