I-PHP: Sebenzisa i-WordPress API ukwakha i-Shortcode kuhlu lohlu olungaphansi

I-WordPress PHP

Sisebenzela ukuqaliswa okuyinkimbinkimbi kweklayenti lebhizinisi khona manje. Isayithi lakhiwa ngeWordPress kepha linethoni yezinsimbi namakhwela. Imvamisa, lapho ngenza lolu hlobo lomsebenzi, ngithanda ukugcina ikhodi yangokwezifiso yokuphindaphinda kamuva kwamanye amasayithi. Kulokhu, bengicabanga ukuthi kuwumsebenzi owusizo kangako, bengifuna ukuwabelana nomhlaba. Sisebenzisa i- Itimu ye-Avada WordPress neFusion Page Builder njengetimu yomzali, futhi sisebenzisa ikhodi ethile yangokwezifiso engqikithini yethu yengane.

I-WordPress isivele inemisebenzi embalwa ku-API yayo engasetshenziswa ukwenza uhlu lwamakhasi amancane, njenge-wp_list_pages kanye ne-get_pages. Inkinga ukuthi ababuyisi imininingwane eyanele uma unethemba lokudala ngamandla uhlu olunenqwaba yolwazi.

Kuleli khasimende, bebefuna ukuthumela izincazelo zomsebenzi futhi babe nohlu lokuvuleka kwemisebenzi okuzotholakala ngokuzenzekelayo ngokulandelana ngosuku lwabo lokushicilela. Bafuna nokukhipha ingqikithi yekhasi.

Ngakho-ke, okokuqala, bekufanele sengeze ukwesekwa kwengcaphuno kuthempulethi yekhasi. Ku-works.php yetimu yabo, singeze:

i-add_post_type_support ('ikhasi', 'ngcaphuno');

Ngemuva kwalokho, besidinga ukubhalisa i-shortcode yangokwezifiso ezokhiqiza uhlu lwezingxenye ezingaphansi, izixhumanisi zazo, kanye nengcaphuno yazo. Yenza lokhu, kufanele sisebenzise indlela ye- I-WordPress Loop. Ku-works.php, singeze:

// Uhlu Lokungenayo Emsebenzini wohlu dknm_list_child_pages ($ atts, $ content = "") {global $ post; $ atts = shortcode_atts (uhlu ('ifempty' => 'Awekho Amarekhodi', 'aclass' => ''), $ atts, 'list_subpages'); $ args = array ('post_type' => 'ikhasi', 'posts_per_page' => -1, 'post_parent' => $ post-> ID, 'orderby' => 'publish_date', 'order' => 'DESC' ,); $ parent = okusha WP_Query ($ args); uma ($ parent-> have_posts ()) {$ string. = $ content. ' '; ngenkathi ($ parent-> have_posts ()): $ parent-> the_post (); $ string. = ' '.thola_isihloko ().' '; uma (has_excerpt ($ post-> ID)) {$ string. = '-' .get_the_excerpt (); } $ umucu. = ' '; ekugcineni; } okunye {$ string = ' '. $ atts [' ifempty '].' '; } wp_reset_postdata (); buyisela intambo engu- $; } engeza_ikhodi emfushane ('uhlu lwamakhasi', 'dknm_list_child_pages');

Manje, i-shortcode ingasetshenziswa kulo lonke isayithi ukukhombisa amakhasi ezingane ngesixhumanisi nengcaphuno. Ukusetshenziswa:

[list_subpages aclass = "button" ifempty = "Uxolo, okwamanje asinakho ukuvuleka kwemisebenzi."] Uhlu lwemisebenzi [/ uhlu_subpages]

Umphumela uba uhlu oluhle, oluhlanzekile olungabhalwanga lwemisebenzi eshicilelwe, engamakhasi ezingane ngaphansi kwekhasi labo lomsebenzi.

Ukube beyingekho imisebenzi eshicilelwe (ayikho amakhasi ezingane), izoshicilela:

Uxolo, okwamanje asinakho ukuvuleka kwemisebenzi.

Ukube bekunemisebenzi eshicilelwe (amakhasi ezingane), izoshicilela:

Uhlu lwemisebenzi:

UCABANGANI?

Le sayithi isebenzisa i-Akismet ukunciphisa ugaxekile. Funda ukuthi idatha yakho yokuphawula isetshenziswa kanjani.