PHP: Yi amfani da WordPress API don Gina wata Gajeriyar hanya don Jera Subananan Shafi

PHP na WordPress

Muna aiki kan wani hadadden aiwatarwa ga abokin harka a yanzu. Ana gina rukunin yanar gizon a cikin WordPress amma yana da tarin kararrawa da bushe-bushe. Sau da yawa, lokacin da nake yin irin wannan aikin, Ina son adana lambar al'ada don sake dawowa daga baya akan wasu shafuka. A wannan yanayin, nayi tsammanin wannan aiki ne mai amfani, ina so in raba shi ga duniya. Muna amfani da Avada WordPress taken tare da Fusion Page magini a matsayin taken iyaye, da tura wasu abubuwa na lambar al'ada a cikin taken yaranmu.

WordPress ya riga yana da ayyuka guda biyu a cikin API ɗin sa wanda za'a iya amfani dasu don lissafa ƙananan shafuka, kamar wp_list_pages da get_pages. Matsalar ita ce ba su dawo da cikakken bayani ba idan kuna fatan ƙirƙirar jeri tare da tarin bayanai.

Ga wannan abokin cinikin, suna son sanya bayanan aiki kuma suna da jerin ayyukan buɗewa kai tsaye ana samar dasu ta hanyar saukowa ta kwanan wata. Sun kuma so su nuna wani yanki na shafin.

Don haka, da farko, dole ne mu ƙara goyan bayan yanki zuwa samfurin shafin. A cikin ayyuka.php don taken su, mun ƙara:

add_post_type_support ('shafi', 'karin bayani');

Bayan haka, muna buƙatar yin rijistar wata gajeriyar hanya wacce za ta samar da jerin ƙananan shafukan yanar gizo, hanyoyin haɗi zuwa gare su, da abin da ke cikin su. Shin yin wannan, dole ne muyi amfani da Madauki na WordPress. A cikin ayyuka.php, mun kara da cewa:

// Jerin Shafuka a cikin aikin Jerin dknm_list_child_pages ($ atts, $ content = "") {post na duniya $; $ atts = shortcode_atts (tsararru ('ifempty' => 'Babu Rikodi', 'aclass' => ''), $ atts, 'list_subpages'); $ args = tsararru ('post_type' => 'shafi', 'posts_per_page' => -1, 'post_parent' => $ post-> ID, 'orderby' => 'bugawa_date', 'order' => 'DESC' ,); $ iyaye = sabon WP_Query ($ args); idan ($ parent-> have_posts ()) {$ string. = $ abun ciki. ' '; yayin ($ parent-> have_posts ()): $ parent-> the_post (); $ kirtani. = ' '.samu_title ().' '; idan (has_excerpt ($ post-> ID)) {$ string. = '-' .get_the_excerpt (); } $ kirtani. = ' '; ƙarshe; } kuma {$ string = ' '. $ atts [' idan babu komai '].' '; } wp_reset_postdata (); dawo da $ kirtani; } add_shortcode ('list_subpages', 'dknm_list_child_pages');

Yanzu, ana iya aiwatar da lambar gajeriyar ko'ina cikin shafin don nuna shafukan yaran tare da hanyar haɗi da wani yanki. Anfani:

[list_subpages aclass = "button" ifempty = "Yi haƙuri, a halin yanzu ba mu da buɗaɗɗun aiki."] Jerin Ayyuka [/ jerin_ shafuka]

Sakamakon yana da kyau, tsabtataccen jerin ayyukan da aka buga, waɗanda sune shafukan yara ƙarƙashin shafin aikin su.

Idan babu ayyukan da aka buga (babu shafukan yara), zai buga:

Yi haƙuri, a halin yanzu ba mu da wani buɗaɗɗun aiki.

Idan akwai ayyukan da aka buga (shafukan yara), zai buga:

Jerin Ayyuka:

Me kuke tunani?

Wannan shafin yana amfani da Akismet don rage spam. Koyi yadda aka sarrafa bayanan bayaninka.