PHP: Whakamahia te API WordPress ki te Hanga i tetahi Panui Poto ki te Rarangi Wharangi

WordPress PHP

Kei te mahi maatau i tetahi mahi uaua mo te kaihoko umanga inaianei. Kei te hangaia te papaanga i roto i te WordPress engari he maha nga pere me nga whiowheo. I te nuinga o nga wa, i te wa e mahi ana ahau i tenei tu mahi, ka hiahia au ki te penapena i te waehere ritenga mo te whakahoki ano i etahi atu papaanga I tenei keehi, i whakaaro ahau he mahi whaihua tenei, i hiahia ahau ki te tohatoha atu ki te ao. Kei te whakamahi matou i te Kaupapa Avada WordPress me te Kaihanga Wharangi Fusion hei kaupapa matua, me te whakamahi i te waehere ritenga i roto i ta maatau tamaiti kaupapa.

He maha nga mahi a WordPress i roto i tana API ka taea te whakamahi ki te whakararangi i nga waahanga, penei i te wp_list_pages me te get_pages. Ko te raru kaore i te hoki mai i a ratau nga korero mena kei te tumanako koe kia kaha te hanga raarangi me nga tini korero.

Mo tenei kaihoko, i hiahia ratou ki te tuku whakaahuatanga mahi me te hanga i te raarangi o nga whakatuwheratanga mahi kia heke tonu mai i te ra whakaputa. I hiahia hoki ratau ki te whakaatu i tetahi waahanga o te whaarangi.

Na, ko te tuatahi, me taapiri atu ki te tautoko whiti ki te tauira wharangi. I roto i nga mahi.php mo ta raatau kaupapa, ka tapiritia e matou:

add_post_type_support ('whaarangi', 'excerpt');

Na, me rehita e maatau tetahi waahanga poto hei whakaputa i te raarangi whaarangi, hononga ki a raatau, me te waahanga mo ratou. Mahia tenei, me whakamahi e maatau te Matapihi WordPress. I nga mahi.php, i tapiritia e matou:

// Rarangi Wharangi i roto i te Raarangi mahi dknm_list_child_pages ($ atts, $ content = "") {ao $ pou; $ atts = shortcode_atts (array ('ifempty' => 'No Records', 'aclass' => ')), $ atts,' list_subpages '); $ args = array ('post_type' => 'whaarangi', 'posts_per_page' => -1, 'post_parent' => $ pou-> ID, 'orderby' => 'publish_date', 'order' => 'DESC' ,); $ matua = WP_Query hou ($ args); mena ($ matua-> whai_post ()) {$ string. = $ ihirangi. ' '; i te ($ matua-> whai_post ()): $ matua-> te_pou (); $ string. = ' '.get_the_title ().' '; mena (has_excerpt ($ post-> ID)) {$ string. = '-' .get_the_excerpt (); } $ string. = ' '; mutunga; } atu {$ string = ' '. $ atts [' ifempty '].' '; } wp_reset_postdata (); whakahoki $ string; } add_shortcode ('list_subpages', 'dknm_list_child_pages');

Na, ka taea te whakamahi i te waeatuhi poto puta noa i te papaanga ki te whakaatu ki nga wharangi tamariki me te hono me te waahanga. Whakamahi:

[list_subpages aclass = "button" ifempty = "Aroha mai, kaore o maatau mahi i tenei wa."] Rarangi Mahi [/ list_subpages]

Ko te mutunga he rarangi maamaa, maamaa kaore ano kia rangahauhia nga mahi kua whakaputahia, he wharangi tamariki kei raro i te whaarangi umanga.

Mena kaore he mahi i whakaputaina (kaore he wharangi tamariki), ka whakaputahia:

Aroha mai, kaore o maatau mahi i tenei wa.

Mena he mahi i whakaputaina (wharangi tamariki), ka whakaputahia:

Rarangi Mahi:

He aha koutou whakaaro?

Whakamahia ai e tenei pae i te Akismet hei whakaiti i te mokowhiti. Akohia te tukatuka o to raraunga korero.