Ne do të përfshijmë gjithashtu një veçori të redaktuesit të postimeve Fushat e personalizuara (me porosi ose fusha me porosi) për çdo lloj dhe shfaqni fushat në shabllone të reja.
Në WordPress, llojet e postimeve të personalizuara ju japin kontroll të plotë se si t'u shfaqni përmbajtjen përdoruesve tuaj. Nëse krijoni postime në blogun tuaj, mund të krijoni stile të personalizuara vetëm për ta. Nëse shkruani komente për muzikën ose filmat, mund të shtoni zona shtesë të hyrjes në postimet që dëshironi dhe ato nuk do të shfaqen në postimet e tjera të blogut.
Por para se të vazhdojmë, le të kuptojmë se çfarë janë postimet e përdoruesve.
Cilat janë llojet e postimeve me porosi të WordPress?
Me pak fjalë, llojet e postimeve me porosi të WordPress ju lejojnë të renditni postimet bazuar në përmbajtjen e tyre. Në WordPress, llojet e postimeve të paracaktuara janë Post, Faqe, Media, etj.
Në mënyrë tipike, ju shkruani të gjitha postimet tuaja në seksionin Posts të tastierës së administratorit dhe më pas caktoni një kategori për to. Të gjitha hyrjet lloje të ndryshme janë në të njëjtën listë, duke e bërë të vështirë dallimin e tyre sipas llojit të përmbajtjes.
Llojet e personalizuara të postimeve me lidhjet e tyre në tastierën e administratorit ju çojnë në një listë postimesh të atij lloji. Postimeve të krijuara në këtë mënyrë mund t'u caktohen kategori si një postim i rregullt, kështu që ju keni liri absolute për të renditur dhe paraqitur postimet në çdo mënyrë që dëshironi.
Në shembullin e mësipërm, nëse një përdorues shkon në seksionin e bazës së të dhënave të filmave të faqes tuaj, postimet e rishikimit nuk do të përfshihen. Nëse bëni kategoritë "Aksion" dhe "Romancë", për shembull, përdoruesit tuaj do të mund të shkojnë në kategorinë e filmave aksion dhe të shohin të gjitha komentet dhe filmat në kategori.
Kur krijoni lloj i ri publikim, keni shumë cilësime, si: ku do të vendoset lidhja në menynë e administratorit, nëse ky lloj do të përfshihet në rezultatet e kërkimit, nëse do të mbështetet shfaqja e një fragmenti teksti, nëse lejohen komentet etj.
Ju mund të ndryshoni tekste të ndryshme të titullit (të përcaktuara duke përdorur një grup $etiketa), të tilla si riemërtimi Shto postim të ri V Shto film të ri. Për shembull, mund ta riemërtoni tekstin Imazhi i veçuar V Shto poster.
Ju gjithashtu mund të aktivizoni funksionin e fushave të personalizuara në redaktuesin tuaj të postimit, i cili është i fshehur si parazgjedhje dhe duhet të aktivizohet nëpërmjet një lidhjeje Opsionet e ekranit në krye të redaktorit.
Duke vazhduar me shembullin e Filmave dhe Rishikimeve të Filmit, botimet e filmave mund të shtojnë fusha të personalizuara/të personalizuara për parametra të tillë si viti i publikimit, regjisori, vlerësimet dhe shumë të tjera me një pasqyrë e shkurtër filmat si përmbajtje regjistrimi.
Zakonisht çdo fushë që krijoni është e disponueshme në çdo lloj postimi, kështu që shtojca kërkon kufizime në secilën fushë ku mund të aksesohet.
Krijimi i llojeve të reja të postimeve
Kur krijoni ndryshime të rëndësishme në WordPress, një nga opsionet e disponueshme të zbatimit është krijimi i një shtojce. Ju gjithashtu mund të krijoni lloje të reja postimi me porosi në skedar funksionet.php. Për këtë udhëzues ne Le të krijojmë një shtojcë dhe të vazhdojmë të përdorim shembullin me bazën e të dhënave të filmave/rishikimeve.
Për të krijuar një lloj postimi të personalizuar, duhet të shkruani disa funksione që thërrasin një funksion të WordPress register_post_type () me dy parametra. Funksioni juaj duhet të jetë i lidhur me një goditje veprimi në fillim, përndryshe lloji i postës me porosi nuk do të regjistrohet saktë.
// Funksioni i personalizuar DUHET të jetë i lidhur me fiksimin e veprimit init add_action("init", "lc_register_movie_post_type"); // Një funksion i personalizuar që thërret funksionin register_post_type lc_register_movie_post_type() ( // Vendosni pjesë të ndryshme të tekstit, $labels përdoret brenda grupit $args $labels = array("name" => _x("Filma", "lloj postimi i përgjithshëm emri"), "emri_singular" => _x("Filmi", "emri i njëjës i llojit të postimit"), ...); // Vendosni pjesë të ndryshme informacioni rreth llojit të postimit $args = array ("etiketat" => $ etiketat, "description" => "Lloji im i personalizuar i postimit", "publik" => i vërtetë, ... // Regjistro llojin e postimit të filmit me të gjithë informacionin e përmbajtur në grupin $arguments register_post_type("film", $); args);
Të gjitha funksionet e personalizuara duhet të parashtesohen për të shmangur konfliktet me shtojcat e tjera ose funksionet e temave. Këtu do të përdoret prefiksi LC.
Dy parametra për funksionin register_post_type () Kjo:
- Emri i llojit të regjistrimit, maksimumi 20 karaktere dhe nuk duhet të përmbajë hapësira ose shkronja të mëdha
- Një grup shoqërues i quajtur $args, i cili përmban informacion për llojin e rekordit në formën e çifteve çelës-vlerë 'key' => 'vlera'
Vargu $args
Tastet më të përdorura për një grup $args treguar më poshtë, të gjitha janë opsionale:
- etiketat– varg varg, i cili specifikon pjesë të ndryshme të tekstit, për shembull "Shto hyrje të re" mund të riemërtohet në "Shto film i ri’. Çelësat për grupin e etiketave janë përshkruar më poshtë me shpjegime;
- përshkrimi– një përshkrim i shkurtër dhe i përmbledhur i llojit të regjistrimit, ai mund të shfaqet në shabllone të tipit, por nuk përdoret askund tjetër;
- publike– a është lloji i postimit i dukshëm për autorin dhe vizitorët, vlera e paracaktuar është FALSE, që do të thotë se nuk shfaqet as në panelin e administratorit;
- përjashtoj_nga_kërkimi– nëse të dhënat e këtij lloji do të shfaqen në rezultatet e rregullta të kërkimit, vlera e paracaktuar kuptimi i kundërt publike;
- publicly_queryable– a mund të merret ky lloj postimi duke përdorur një URL, si p.sh. http://www.mywebsite.com/?post_type=movie, ose në përdorim të avancuar nëpërmjet funksionit query_posts(). Vlera e paracaktuar është publike;
- show_ui– nëse lidhjet e menysë dhe redaktori i mesazheve janë të lidhura në panelin e kontrollit të administratorit. Vlera e paracaktuar është publike;
- shfaq_në_meny_nav– nëse hyrjet e këtij lloji do të shtohen në menynë e navigimit të krijuar në faqe Pamja e jashtme->Menyja, vlera e paracaktuar është publike;
- shfaq_në_meny– nëse lidhja e llojit të postimit shfaqet në navigimin e tastierës së administratorit. FALSE – fsheh lidhjen. E VËRTETË – shton lidhjen si një lidhje të re të nivelit të lartë. Futja e një rreshti ju lejon të vendosni një lidhje brenda një lidhjeje ekzistuese të nivelit të lartë, domethënë të vendosni parametrat opsionet-e përgjithshme.php e vendos nën lidhjen e Cilësimeve.
- show_në_admin_bar– a do të shfaqet ky lloj postimi mbi shiritin e administratorit, nën lidhjen + E re
- pozicioni_menu– pozicioni lidhje e re në menunë e navigimit të tastierës së administratorit, 5 ndodhet poshtë Postimeve, 100 ndodhet poshtë Cilësimeve, e gjithë lista e pozicioneve mund të gjendet në Codex WordPress
- hierarkike– nëse një rekord mund t'i caktohet një rekord prind, nëse vlera është TRUE, atëherë grupi $mbështet duhet të përmbajë parametrin "page-atributes".
- mbështet– aktivizon në mënyrë selektive funksionet e postimit si: imazhe, fragmente teksti, fusha të personalizuara, etj. Nëse vendoset në FALSE, atëherë në vend të një grupi, redaktori për këtë lloj postimi fiket - i dobishëm nëse doni të mbyllni të gjitha postimet e këtij shkruani nga redaktimi, por lini ato të dukshme (lista e vlerave të grupit nee)
- taksonomitë– një grup taksonomish që mund të aplikohen në botime të këtij lloji, taksonomitë duhet të jenë tashmë të regjistruara - ato nuk janë krijuar nga këtu!
- ka_arkiv– a do të kenë postimet e këtij lloji faqe arkivimi, URL-ja ka një strukturë lidhjeje të përhershme dhe pjesa përshkruese e URL-së është parametri 1 i funksionit register_post_types(), domethënë, http://www.mywebsite.com/movie_reviews/ do të tregojë të gjitha postimet e rishikimit të filmit.
- query_var– E VËRTETË ose E FALSE përcakton nëse një postim mund të shfaqet duke kërkuar URL-në me llojin e postimit dhe emrin e postimit, p.sh. 'http://www.mywebsite.com/? film=matrica'. Nëse futni një rresht teksti, duhet ta vendosni tekstin pas karakterit, kështu që 'filmi' do të përfundojë si '? film=matrica‘.
Vargje etiketash
Tasti i parë në grup $args thirrur etiketat dhe duhet të jetë një grup. Ai specifikon pjesë të ndryshme të tekstit që lidhen me llojin e postimit. Meqenëse mund të ketë shumë të dhëna këtu, është më mirë të krijoni një grup të quajtur $etiketa për ruajtjen e tyre. Kodi i mësipërm e bën pak më të qartë se çfarë do të thotë kjo.
Më poshtë janë disa çelësa të rëndësishëm për grupin e etiketave, të gjitha janë opsionale:
- emri – emra të zakonshëm për një lloj mesazhi, për shembull filma
- njëjës_emër– emri për një hyrje të këtij lloji, për shembull, film (film)
- shtoni_të reja– duke zëvendësuar tekstin "Shto të re" me tekstin e specifikuar, për shembull, "Shto film"
- shtoni_artikullin e ri– zëvendësimi i "Shto postim të ri", për shembull, me "Shto një film të ri"
- redakto_artikull– zëvendësimi i ‘Edit Post’, për shembull, me ‘Edit Movie’
- i paraqitur_imazhi– zëvendësimi i "Imazhi i veçuar" në redaktuesin e postimit, për shembull, me "Poster filmi"
- vendosur_imazhin_e veçuar– duke zëvendësuar "Vendosni imazhin e veçuar", për shembull, me këtë opsion "Shto posterin e filmit"
- emri_menu– ndryshimi i tekstit të lidhjes në niveli i sipërm, emri i parazgjedhur i tekstit të lidhjes
Array mbështet
// Aktivizo veçori specifike në redaktuesin e postimit për llojin tim të postimit $supports = grup ("titulli", "redaktori", "autori", "miniaturë"); // Çaktivizo TË GJITHA tiparet e redaktuesit të postimeve për llojin tim të postimit $mbështetje = FALSE;Një nga çelësat në grup $args thirrur mbështet. Ky është një grup i thjeshtë ku regjistroni një listë të veçorive të redaktuesit të postimeve që dëshironi të aktivizoni për llojin tuaj të postimit. Si parazgjedhje, vetëm titulli dhe redaktori janë të aktivizuara.
Ju gjithashtu mund të vendosni FALSE në vend të grupit për të çaktivizuar të gjitha funksionet e redaktuesit, duke çaktivizuar titullin dhe zonën e shtimit të përmbajtjes. Kjo do të thotë që hyrja nuk mund të modifikohet, por është ende plotësisht e dukshme.
Këtu është një listë e funksioneve që mund të përfshini në një grup $mbështet:
- titulli (emri)
- redaktor
- autori – SHËNIM: kjo ju lejon të ndryshoni autorin e postimit
- miniaturë (ikona)
- fragment (fragment teksti)
- backbacks
- fushat e personalizuara (fusha e personalizuar)
- komentet
- rishikimet (versionet)
- faqe-atribute
- post-formatet (formatet e postimit)
Krijimi i një lloji postimi të personalizuar të WordPress përmes një shtojce
Tani që e dimë se cilat parametra nevojiten për funksionin, mund të krijojmë shtojcën tonë, të shkruajmë funksionin e vet dhe bashkëngjitni atë në ngjarje në fillim.
lc_custom_post_movie() te fiksimi i veprimit init add_action("init", "lc_custom_post_movie"); // Funksioni i personalizuar për të regjistruar një funksion të llojit të postimit të filmit lc_custom_post_movie() ( // Vendosni etiketat, kjo ndryshore përdoret në grupin $args $labels = array("name" => __("Filma"), "singular_name " => __("Film"), "add_new" => __("Shto film të ri"), "add_new_item" => __("Shto film të ri"), "edit_item" => __("Modifiko filmin") , "new_item" => __("Filmi i ri"), "all_items" => __("Të gjithë filmat"), "view_item" => __("Shiko filmin"), "search_items" => __("Kërko filmat" "), "featured_image" => "Poster", "set_featured_image" => "Shto poster"); // Argumentet për llojin tonë të postimit, që do të futen si parametri 2 i register_post_type() $args = array ("etiketat" => $labels, "description" => "Mban filmat tanë dhe të dhënat specifike të filmit", "public" => true, "menu_position" => 5, "supports" => array("title", "redaktor", " thumbnail", "excerpt", "comments", "custom-fields"), "has_archive" => true, "show_in_admin_bar" => true, "show_in_nav_menus" => true, "has_archive" => true, "query_var" = > "film"); ) // Hook lc_custom_post_movie_reviews() te fiksimi i veprimit init add_action("init", "lc_custom_post_movie_reviews"); // Funksioni i personalizuar për të regjistruar një postim të rishikimit të filmit, funksioni i tipit lc_custom_post_movie_reviews() ( // Vendosni etiketat, kjo ndryshore përdoret në grupin $args $labels = array("name" => __("Shqyrtime filmash"), "singular_name" => __("Komenti i filmit"), "add_new" => __("Shto rishikim të ri filmi"), "add_new_item" => __("Shto rishikim të ri filmi"), "edit_item" => __( "Modifiko rishikimin e filmit"), "new_item" => __("Rishikimi i ri i filmit"), "all_items" => __("Të gjitha komentet e filmit"), "view_item" => __("Shiko komentet e filmit"), " search_items" => __("Kërko komentet e filmave")); // Argumentet për llojin tonë të postimit, që do të futen si parametri 2 i register_post_type() $args = array("labels" => $labels, "description" = > "Mban komentet tona të filmit", "public" => true, "menu_position" => 6, "supports" => grup("titulli", "redaktori", "miniaturë", "fragment", "komente", " custom-fields"), "has_archive" => true, "show_in_admin_bar" => true, "show_in_nav_menus" => true, "has_archive" => true); // Thirrni funksionin aktual të WordPress // Parametri 1 është një emër për lloji i postimit // vargu $args shkon në parametrin 2. register_post_type("rishikim", $args); )
Nëse aktivizoni këtë shtojcë, do të shihni një lidhje të re në shiritin e navigimit të tastierës së administratorit, menjëherë pas lidhjes Posts.
Kur rri pezull miun, do të shfaqen artikujt e menysë "Shiko të gjitha" dhe "Shto të re", teksti do të korrespondojë me atë që është specifikuar në grup $etiketa. Shikoni në redaktorin ku kanë ndryshuar lidhjet.
Kufizoni fushat e personalizuara për regjistrimet e dhëna
Kur shtoni fushat tuaja në një regjistrim, fushat ruhen dhe ju mund të shtoni shpejt ndonjë në rekordin e ri. Fushat e personalizuara që keni shtuar do të shfaqen në listën rënëse të çdo hyrjeje. Kjo mund ta bëjë të vështirë gjetjen e fushës që po kërkoni në disa lloje postimesh. Nëse dëshironi të kufizoni fushat e personalizuara në mënyrë që ato të jenë të disponueshme vetëm për disa lloje postimesh, atëherë mënyra më e lehtë është përmes një shtojce.
get_post_meta ()
- merr 3 parametra dhe kthehet rezultat
- parametri i parë është ID-ja e postimit, mund ta përdorni këtu $post->ID për të marrë ID-në e hyrjes së shfaqur aktualisht
- parametri i dytë është emri i një fushe regjistrimi të personalizuar, të ndjeshme ndaj shkronjave të vogla
- parametri i tretë është i tipit boolean, i quajtur $beqare dhe mund të jetë TRUE (e kthen rezultatin si varg) ose FALSE (kthehet një grup).
ID, "Arti i kutisë", E VËRTETË); nëse (!empty($movie_box_art)) ( ?>SHËNIM: Mund të krijoni shumë fusha të personalizuara me të njëjtin emër dhe vlera të ndryshme. Nëse ka shumë fusha me të njëjtin emër, vendosja e FALSE do të kthejë një grup prej tyre.
Që nga funksioni get_post_meta () kthen një vlerë, ju mund ta përdorni vlerën në një shprehje të kushtëzuar për të ndryshuar pamjen në përputhje me rrethanat.
Në shembullin e mësipërm, ne kontrollojmë për të parë nëse filmi përmban artin e kutisë që i është caktuar si një fushë e personalizuar. Nëse $movie_box_art jo bosh, shfaq div dhe imazh.
Shfaqja e fushave të avancuara të personalizuara
// Afisho vlerën e fushës the_field("EMRI I FUSHËS"); // Vlera e fushës së kthimit get_field ("EMRI I FUSHËS");Shtojca Advanced Custom Fields ofron funksionet e veta dhe kodet e shkurtra për shfaqjen e fushave.
the_field ('EMRI I FUSHËS');
Shfaq vlerën e një fushe të specifikuar, duhet të përdorni emrin e fushës që keni specifikuar kur krijoni grupin e fushave.
get_field ('EMRI FUSHËS');
Kthen vlerën e fushës së specifikuar, e dobishme për shprehjet e kushtëzuara.
Këto janë veçoritë që me shumë mundësi do t'ju nevojiten. Ka shumë veçori shtesë dhe mund t'i gjeni në.
Kodet e shkurtra
Ju mund të shfaqni fushat direkt në një postim duke përdorur kodin e shkurtër të mësipërm.
Shfaq një lloj postimi të personalizuar në faqen kryesore
// Lidhni funksionin tonë të personalizuar në pre_get_posts hook add_action("pre_get_posts", "add_reviews_to_frontpage"); // Ndrysho funksionin e pyetjes kryesore add_reviews_to_frontpage($query) ( if (is_home() && $query->is_main_query()) ( $query->set("post_type", array("post", "film", "review ")); ) ktheni $query;)Llojet e personalizuara të postimeve nuk shfaqen në faqen kryesore si parazgjedhje, kështu që ju duhet të krijoni një funksion të ri që thërret metodën e vendosjes së objektit WP_Query WordPress.
Funksioni kontrollon nëse vizitori është në faqen kryesore dhe nëse kërkesa aktive është primare e krijuar nga WordPress.
$query->set() merr dy parametra:
- parametri i parë është prioriteti që dëshironi të ndryshoni, në rastin tonë ne e ndryshojmë prioritetin post_lloj
- parametri i dytë është grupi që dëshironi të kaloni si vlerë atributi post_lloj
Në shembullin e kodit të mësipërm, grupi fillon me 'post' - kjo është arsyeja pse çdo postim i WordPress është i llojit 'post' dhe ne ende duam ta përfshijmë atë në faqen kryesore.
Nëse dëshironi të përdorni vetëm postime të personalizuara të një lloji të caktuar në faqen tuaj kryesore, mund të hiqni 'postimet' dhe të përdorni llojin tuaj të postimit.
Vlera që futni duhet të përputhet me parametrin 1 të funksionit register_post_type ().
konkluzioni
Në këtë tutorial, ne tregojmë se si të krijoni lloje të personalizuara dhe çfarë të dhënash duhet të keni për ta bërë këtë. Fleksibiliteti i llojeve të postimeve me porosi ofron funksionalitet të vlefshëm për çdo faqe të WordPress.
WordPress ka të bëjë me personalizimin/përshtatjen. Është krijuar në atë mënyrë që absolutisht çdo seksion mund të personalizohet. Në këtë tutorial do të shikojmë llojet e postimeve me porosi, një nga veçoritë më domethënëse dhe më të shquara të WordPress, me ndihmën e së cilës WordPress ka mundur të arrijë lartësi të reja.
Cilat janë llojet e postimeve me porosi?
Le të themi se dëshironi që blogu juaj të ketë një seksion të veçantë për rishikimet e filmave. Duke përdorur llojet e postimeve të personalizuara, mund të krijoni një lloj të ri, për shembull, Posts and Pages, i cili do të përmbajë një lloj tjetër të dhënash. Ai do të ketë menunë e vet të administratorit, faqe të veçanta për redaktim, taksonomitë e veta dhe shumë mjete të tjera që nevojiten për të punuar plotësisht me botimet.
Llojet e personalizuara të postimeve janë një grup shtesë i cilësimeve të administratorit që ekzistojnë së bashku me cilësimet për llojet e postimeve të paracaktuara si p.sh rekorde, faqet, skedarët e bashkangjitur, etj. Llojet e postimeve të personalizuara mund të ruajnë çdo lloj të dhënash. Ata kanë një redaktues të veçantë, ngarkues të mediave dhe përdorin strukturën para-ekzistuese të tabelës së WordPress, duke e bërë të lehtë menaxhimin e të dhënave. Avantazhi kryesor i llojeve të postimeve me porosi të krijuara duke përdorur API të WordPress është se ato janë të pajtueshme me temat dhe shabllonet ekzistuese. Gjithashtu, falë përdorimit të lidhjeve të përhershme, llojet e postimeve me porosi ndërveprojnë mirë me motorët e kërkimit.
Pse të përdorni llojet e postimeve të personalizuara?
Llojet e personalizuara të postimeve ju ndihmojnë të ruani lloje të ndryshme postimesh në vende të ndryshme. Kjo ndihmon në ndarjen e postimeve të rregullta nga të tjerët. Kjo është ajo.
Krijimi i një shtojce për një lloj postimi të personalizuar
Ne do të krijojmë një shtojcë për një lloj postimi të personalizuar që do të shfaqë komentet më të mira të filmit. Le të fillojmë.
Hapi 1. Krijoni një dosje për shtojcën WordPress
Hapni dosjen tuaj të shtojcave të WordPress dhe krijoni një dosje të re Film-Recensione.
Hapi 2: Krijoni një skedar PHP
Në dosjen e krijuar, krijoni një skedar PHP Movie-Reviews.php
Hapi 3: Shtoni një kokë
Hapni skedarin e krijuar dhe ngjitni kodin për kokën në krye.
Përpara etiketës mbyllëse të komandës PHP, futni rreshtin e mëposhtëm të kodit create_movie_review. Kur inicializohet, do të ekzekutojë funksionin e duhur personal sa herë që krijohet faqja.
Add_action("init", "create_file_review");
Hapi 5: Ekzekutoni funksionin
Kodi për të ekzekutuar funksionin create_movie_review.
Funksioni create_movie_review() ( register_post_type("movie_reviews", array("labels" => array("name" => "Komente të filmit", "singular_name" => "Rishikim filmi", "add_new" => "Shto të ri", "add_new_item" => "Shto rishikim të ri filmi", "edit" => "Ndrysho", "edit_item" => "Ndrysho rishikimin e filmit", "new_item" => "Rishikim i ri i filmit", "view" => "Shiko ", "view_item" => "Shiko rishikimin e filmit", "search_items" => "Kërko komente filmash", "not_found" => "Nuk u gjetën komente filmash", "not_found_in_trash" => "Nuk u gjetën komente filmash në kosh", "parent" => "Rishikimi i filmit prind"), "public" => true, "menu_position" => 15, "supports" => grup ("titulli", "redaktori", "komentet", "miniaturë", " fusha të personalizuara"), "taksonomi" => grup (""), "menu_icon" => shtojca_url ("imazhe/image.png", __FILE__), "has_arkivë" => e vërtetë)); )
Funksioni register_post_type do të bëjë pjesën më të madhe të punës në rastin tonë. Sapo të thirret, ai do të përgatisë konfigurimin e WordPress të nevojshëm për një postim të ri të përdoruesit, duke përfshirë seksione shtesë për administratorin. Dy lloje argumentesh i kalohen funksionit: emri unik i tipit të postimit të personalizuar dhe një grup me vetitë e tij. Ky është një grup tjetër me etiketa të ndryshme që tregojnë se cilat vargje teksti do të shfaqen në pjesë të ndryshme të llojit të postimit të personalizuar, për shembull: "emri" shfaq emrin e llojit të postimit të personalizuar në panelin e kontrollit, "redakto" dhe "shiko" butonat e ekranit Redakto Dhe Shiko. Mendoj se të gjitha argumentet e tjera flasin vetë.
Pra, në argumentet e mëposhtme:
- "public" => true vendos dukshmërinë e llojit të postimit të personalizuar si në panelin e kontrollit të administratorit ashtu edhe në pjesën e përparme.
- "menu_position" => 15 specifikon se ku në meny do të vendoset lloji i postimit të personalizuar.
- "supports" => vargu ("titulli", "redaktori", "komentet", "miniaturë", "fushat e personalizuara") specifikon ato atribute të tipit të postimit të personalizuar që do të shfaqen.
- "taxonomies" => array("") krijon taksonomi me porosi. Në këtë rast ato nuk janë të përcaktuara.
- "menu_icon" => plugins_url("images/image.png", __FILE__) tregon ikonën në menunë e administratorit.
- "has_archive" => true lejon arkivimin e llojeve të postimeve të personalizuara.
Mund të mësoni më shumë rreth argumenteve të tjera të përdorura në llojet e postimeve të personalizuara në faqen e WordPress Codex register_post_type.
Hapi 6: Ikona për llojin e postimit të personalizuar
Ruani ikonën 16x16 pixel në dosjen tuaj të shtojcave. Kjo është e nevojshme në mënyrë që lloji i postimit të personalizuar të ketë një ikonë në panelin e kontrollit.
Hapi 7: Aktivizoni shtojcën
Aktivizoni shtojcën dhe voila, ju keni një lloj postimi të personalizuar me aftësinë për të redaktuar tekstin, cilësimet për postimet, imazhet, komentet dhe një redaktues të personalizuar të fushës.
Hapi 8: Shtoni një hyrje të re
Zgjidhni Shto të reja për të hapur panelin e redaktimit të llojit të postimit të personalizuar. Shtoni titullin e filmit, rishikoni tekstin dhe zgjidhni një miniaturë imazhi.
Hapi 9: Publikimi
Publikoni postimin dhe klikoni Shikoni rishikimin e filmit për të parë rishikimin e filmit të krijuar.
Krijimi i fushave shtesë për llojet e postimeve të personalizuara
Mekanizmi i fushave shtesë (metaboxes) përdor sistemin e fushave shtesë të integruara në WordPress. Kjo ju ndihmon të shtoni fusha që janë specifike për llojet e postimeve të personalizuara pa përdorur fushat e paracaktuara të personalizuara në redaktues.
Hapi 1: Regjistroni një funksion të personalizuar
Hapni skedarin Movie-Reviews.php dhe shtoni kodin e mëposhtëm përpara etiketës mbyllëse. Ky kod regjistron një funksion që do të thirret kur vizitoni panelin e administratorit të WordPress.
Add_action ("admin_init", "my_admin");
Hapi 2: Ekzekutoni një funksion të personalizuar
Shto një ekzekutim funksioni my_admin që regjistron fusha shtesë dhe i lidh ato me llojin e postimit të personalizuar të filmit_reviews.
Funksioni my_admin() ( add_meta_box ("movie_review_meta_box", "Detajet e rishikimit të filmit", "display_movie_review_meta_box", "movie_reviews", "normal", "high"); )
Në këtë rast, funksioni add_meta_box përdoret për të shtuar fusha shtesë në një lloj postimi të personalizuar. Rreth atributeve:
- atributi film_review_meta_box i kërkuar për HTML id
- Teksti i detajeve të rishikimit të filmit që do të jetë i dukshëm në kokën e fushës shtesë
- Funksioni i kthimit të thirrjes display_movie_review_meta_box që shfaq përmbajtjen e fushave shtesë
- movie_review është emri i llojit të postimit të personalizuar ku do të shfaqen fushat shtesë
- normal përcakton se ku në faqe do të shfaqet blloku i redaktimit
- lartë përcakton prioritetin e fushave të shfaqura
Hapi 3: Ekzekutoni funksionin display_movie_review_meta_box
ID, "film_regjisori", e vërtetë));$movie_rating = intval(get_post_meta($movie_review->ID, "film_vlerësimi", e vërtetë)); | |
Regjisor filmi |
yjet Ky kod shfaq përmbajtjen e fushave shtesë. Kjo përdor një ndryshore objekti që përmban informacion për secilin nga rishikimet e filmit të shfaqur në panelin e redaktimit. Duke përdorur këtë objekt kemi marrë
ID e postës
dhe e përdori atë për të kërkuar në bazën e të dhënave për të marrë emrin dhe vlerësimin e drejtorit, i cili nga ana tjetër do të shfaqej në fusha në ekran. Kur shtoni një postim të ri, funksioni get_post_meta do të kthejë një varg bosh dhe fushat shtesë do të përfundojnë të zbrazëta.Hapi 4: Regjistroni funksionin e ruajtjes së regjistrimit
add_action("ruaj_postimin", "fushat e rishikimit_shto_film", 10, 2);
Ky funksion thirret kur një rekord ruhet në bazën e të dhënave.Hapi 5: Ekzekutoni funksionin add_movie_review_fields
funksioni add_movie_review_fields($movie_review_id, $movie_review) ( // Kontrollo llojin e postimit për komentet e filmit nëse ($movie_review->post_type == "movie_reviews") ( // Ruani të dhënat në tabelën post meta nëse janë të pranishme në të dhënat e postimit nëse (isset($ _POST["filmi_review_director_name"]) &&_POST["film_review_director_name"] != "") (update_post_meta($movie_review_id, "movie_director", $_POST["filmreview_review_director_name"]); ) nëse (isseting ]) && $_POST["vlerësimi_filmi_review"] != "") ( update_post_meta($movie_review_id, "vlerësimi_filmi", $_POST["vlerësimi_review_filmi"]); ) ) )
Ky funksion ekzekutohet kur shënimet ruhen ose fshihen në panelin e administratorit. Në këtë rast, kontrollohet lloji i rekordit që rezulton dhe nëse rekordi është i personalizuar, përsëri bëhet një kontroll për të parë nëse fushat shtesë kanë ndonjë vlerë dhe më pas këto vlera ruhen në këto fusha. Hapi 6: Çaktivizoni fushat standarde të personalizuara Kur krijonim një lloj postimi të personalizuar, ne specifikuam funksionin create_movie_review. Hiqni elementin custom-fields nga grupi mbështetës pasi nuk do të na duhet më. Tani nëse ruani skedarin dhe hapni panelin e redaktimit Shqyrtime filmash, do të shihni dy fusha në fushat shtesë: Autori i Filmit Dhe
Vlerësimi i Filmit
Do të ishte e saktë që çdo lloj regjistrimi i përdoruesit të përdorte shabllonet e veta për shfaqjen e të dhënave. Në rastin tonë, ne do të krijojmë një shabllon që shfaq të gjitha komentet e filmave që janë shtuar duke përdorur një lloj postimi të personalizuar Rishikimi i filmit.
Hapi 1: Regjistroni funksionin e nisjes së shabllonit
Hapni skedarin Movie-Reviews.php dhe para etiketës mbyllëse shtoni kodin e mëposhtëm. Ky kod regjistron një funksion që do të thirret kur vizitoni panelin e administratorit të WordPress.
Add_filter("model_përfshi", "përfshi_funksionin_shabllon", 1);
Hapi 2: Ekzekutoni funksionin
funksioni include_template_function($template_path) ( if (get_post_type() == "movie_reviews") ( if (is_single()) ( // kontrollon nëse skedari ekziston në temë së pari, // përndryshe shërbeje skedarin nga shtojca nëse ($ theme_file = locate_template(array ("single-movie_reviews.php"))) ( $template_path = $theme_file; ) other ( $template_path = plugin_dir_path(__FILE__) . "/single-movie_reviews.php"; )_) )Kjo kontrollon nëse dosja aktuale e temës ka një shabllon të ngjashëm single-(post-type-name).php. Nëse nuk është aty, atëherë kontrollohet prania e shabllonit në dosjen e shtojcave, ku do të vendosim shabllonin tonë si pjesë të shtojcës. Trajtuesi i ngjarjeve template_include (hook) përdoret për të ndryshuar ekzekutimin normal të programit dhe për të detyruar një shabllon të veçantë të ekzekutohet.
Hapi 3: Krijoni një skedar shabllon me një faqe të vetme
Pasi të keni ruajtur skedarin e hapur më parë me shtojcën, krijoni një skedar tjetër të quajtur single-movie_reviews.php dhe ngjisni kodin e mëposhtëm në të.
have_posts()) : $loop->the_post();?>
Titulli: Drejtori: "; } } ?>
Vlerësimi:
";) tjetër (jehonë" Në këtë rast, ne krijuam një shabllon bazë të faqes duke përdorur një lak. Funksioni query_posts merr elemente të një lloji postimi të personalizuar dhe i shfaq ato duke përdorur looping. Ky është sigurisht një cikël shumë i thjeshtë, mund ta ndryshoni sipas nevojës. Ju gjithashtu mund të përdorni stilet e nevojshme CSS për të ndryshuar pamjen.
Kujdes
: Duhet të krijoni një faqe të re nga paneli i kontrollit duke përdorur shabllonin e krijuar. Hapi 4: Imazhet, do të shihni dy fusha në fushat shtesë: Ruani dy imazhe të ikonës së yjeve 32x32 pixel në dosjen tuaj të shtojcave. Emërtoni ato në përputhje me rrethanat icon.png
Një kornizë e plotë që është më e shpejtë se shumica, nëse jo të gjitha kornizat mikro. Kjo kornizë nuk është për fillestarët. Ai ju jep mjetet, por i takon zhvilluesit t'i zbatojë ato. Nëse keni një kuptim të vërtetë të PHP-së dhe performanca është shqetësuese, mos kërkoni më tej. Dokumentacioni është i plotë, por jo i orientuar drejt fillestarëve dhe komuniteti është disi e rrallë, por nuk mund ta theksoj mjaftueshëm performancën. Ky kuadër i vendos aplikacionet e mia PHP në një nivel të performancës me aplikacionet JAVA.
Phlacon nga këndvështrimi im është jo vetëm korniza më e shpejtë në treg, por gjithashtu ofron veçori të ndryshme dhe komponentë të këndshëm. Gjithashtu shumë i mirë për t'u përdorur si MicroFramework për API-të qetësuese ose kornizë të plotë MVC. Vjen me C ORM dhe motorin e shabllonit twig. Gjithashtu ajo që vlerësoj shumë është se si korniza është dinamike, ju përdorni vetëm atë që dëshironi, thjesht mund të zëvendësoni klasat dhe bibliotekat për ato me porosi ose ndikojnë në rrjedhën e ngjarjeve.
Punë shumë e mirë, vetëm një problem është komuniteti por besoj se do të rritet shumë shpejt :)
Phalcon është padyshim një nga kornizat më të shpejta atje, dhe kjo është pika e tij e fortë. Nga ana tjetër, dokumentacioni është pak i çorganizuar, mjetet e uebit (gjeneruesi i kodit) kanë probleme të mëdha në Windows dhe ende i mungon pak më shumë një komunitet për të ndihmuar zhvilluesit e rinj, por edhe një herë, performanca, WOW.
Merrni një reagim të vlefshëm nga klientët tuaj duke u dhënë atyre lirinë për të ndarë lirisht përshtypjet e tyre. Lërini ata të vlerësojnë produktet dhe/ose shërbimet tuaja direkt në faqen tuaj të internetit. Shikoni më poshtë veçoritë kryesore që vijnë standarde me sistemin tonë të rishikimit në internet.
Vlerësime dhe Vlerësime
Vendosni PHP Review Script në faqen tuaj të internetit dhe lërini klientët të ndajnë përvojën e tyre me produktet dhe shërbimet që ofroni. Ata mund të vlerësojnë sipas kritereve dhe të japin reagime pozitive dhe negative.
Gjuhë të shumta
Sistemi i rishikimit PHP mund të flasë jo vetëm anglisht, por çdo gjuhë që ju nevojitet. Ju mund të përktheni të gjithë titujt dhe mesazhet e sistemit nga faqja e administratorit duke përdorur ID unike për secilën pjesë të tekstit.
Kriteret e vlerësimit të modifikueshëm
Në varësi të llojit të biznesit, administratorët e sistemit të rishikimit munden
caktoni kritere të ndryshme vlerësimi që do të shfaqen në formën e përparme.
Secili prej këtyre kritereve vlerësohet me 1 deri në 5 yje.
Njoftimet me email dhe SMS
Vendosni sistemin e rishikimit në internet për të dërguar njoftime me email dhe SMS kur të jetë postuar një rishikim i ri. Mund të specifikoni lehtësisht se cilët përdorues do t'i marrin këto mesazhe nga menyja e Përdoruesve.
Llojet e shumë përdoruesve
Krijoni lloje të pakufizuar klientësh në varësi të industrisë dhe shërbimeve të përdorura. Vlerësimet e hoteleve mund të shkojnë me llojet e mëposhtme të përdoruesve: Familje me fëmijë, Çift, Udhëtim pune etj. Ato shfaqen si etiketa në rishikime.
E përgjegjshme dhe tërheqëse
Skripti i rishikimit dhe vlerësimit funksionon në të gjitha pajisjet, duke u përshtatur pa probleme me madhësi të ndryshme të ekranit. Në përputhje me markën e faqes suaj të internetit, ju mund të zgjidhni temën më të mirë që përputhet në pjesën e përparme midis 10 opsioneve të ngjyrave.
Një kuti me këshilla të shpejta pranë formularit të rishikimit ju lejon të shtoni disa fjalë të mprehta dhe të tërheqni klientët jashtë. Sistemi i rishikimit filtron komentet sipas llojit të përdoruesit. Klientët mund të vlerësojnë edhe vlerësimet e klientëve të tjerë.
Me një Licencë Zhvilluesi ju merrni kodin burimor dhe mund të bëni çdo ndryshim të personalizuar në Skriptin e Rishikimit PHP. Ne gjithashtu mund të modifikojmë sistemin e rishikimit të klientit sipas kërkesës.
Së pari, nga pikëpamja e organizatës së kodit, do të ishte më mirë të vendosni të gjithë logjikën e rishikimit në një ose më shumë skedarë të përfshirë dhe më pas ta përfshini në faqet e produktit:
Include("përfshin/rishikon.php");
Në këtë mënyrë, faqet e produktit mund të mbeten të pandryshuara dhe i njëjti kod rishikimi mund të përdoret lehtësisht, ose modifikohet, sipas nevojës. Skripti reviews.php do të bënte disa gjëra:
- Trego formularin e rishikimit
- Trajtoni formularin e rishikimit
- Listoni rishikimet ekzistuese
- Trajtoni veprime dytësore, të tilla si raportimi i komenteve ose komenteve si të papërshtatshme, duke treguar se komentet ishin të dobishme, duke shtuar komente në komente, duke treguar se komentet ishin të dobishme, etj.
Shpresojmë që tashmë keni bërë shumë zhvillim në internet, kështu që ju e dini se një formë për të shtuar komente do të ishte thjesht kështu:
Është e qartë se do të dëshironit të përdorni disa CSS për ta bërë atë të bukur, por kjo është ideja bazë. Kapja kryesore është se ID-ja e produktit dhe lloji i produktit (ose çfarëdo që duhet të ketë baza e të dhënave për të lidhur një rishikim me një artikull) duhet të ruhen në inpute të fshehura. Ju do të kishit skriptin PHP që shfaq produktin t'i shkruani këto vlera në hyrje.
Nëse kërkohet identifikimi, mund të shtoni kodin (PHP) që tregon vetëm formularin për përdoruesit e regjistruar, ose printon një koment duke thënë se përdoruesi duhet të identifikohet për të rishikuar produktin. Në mënyrë të ngjashme, nëse keni një sistem për të garantuar që një person të rishikojë një produkt vetëm një herë, do të duhet të kontrolloni PHP për atë skenar përpara se të tregoni këtë formular.
Dorëzimi i formularit mund shkoni në një faqe të re, por më pas përdoruesi do të duhet të klikojë butonin Prapa për t'u kthyer në faqen e produktit, gjë që nuk është ideale. Në vend të kësaj, unë do ta dorëzoja formularin në faqen e produktit. Për shembull, në çdo faqe interneti dinamike, i njëjti script PHP përdoret për të shfaqur të gjithë përmbajtjen e një lloji specifik. Në timin Tregti elektronike pa mundim me PHP dhe MySQL libër, siti i parë shembull përdor skriptin page.php për të treguar çdo faqe të përmbajtjes. Atributi i veprimit i formularit do të tregonte në të njëjtën faqe.php. Ju mund ta arrini këtë thjesht duke e lënë bosh atributin, ose duke përdorur PHP për të vendosur në mënyrë dinamike vlerën.
Nëse faqja PHP që liston produktet kërkon që një vlerë që identifikon produktin të kalojë në URL, atëherë formulari duhet ta ruajë atë vlerë edhe në një hyrje të fshehur. (Ky mund të jetë tashmë rasti, me hyrjen product_id, në varësi të mënyrës se si është konfiguruar faqja.) Së dyti, skripti i produktit do të duhet gjithashtu të përditësohet për të lejuar marrjen e vlerës së produktit nëpërmjet POST.
Që skripti reviews.php të dijë se kur duhet të trajtojë një paraqitje formulari, ai mund të kontrollojë se si është aksesuar skripti:
Nëse ($_SERVER["REQUEST_METHOD"] == "POST") ( // Trajto formularin.
Kur të dorëzohet formulari i rishikimit, të dhënat e formularit duhet të vërtetohen. Ju gjithashtu duhet të aplikoni strip_tags() në të dhënat për të parandaluar sulmet e skriptimit ndër-site (XSS) ose sjellje të tjera të këqija. Dhe vlerat jo-numerike do të ekzekutohen përmes një funksioni ikjeje, siç është mysqli_real_escape_string(). Ose thjesht mund të përdorni deklarata të përgatitura ose procedura të ruajtura për siguri dhe performancë më të mirë.
Nëse shtoni një spirancë në atributin e veprimit të formularit action="page.php#reviews", përdoruesi do të dërgohet në seksionin e rishikimeve të faqes pas dorëzimit, gjë që është një prekje e bukur.
Nëse skripti reviews.php po trajton gjithashtu disa nga veprimet e tjera si komente ose komente të përshtatshme, tregues të dobishëm, etj., skenari do të duhet të shikojë edhe për ato paraqitje. Do të përdorja të dhëna të fshehura të quajtura "detyrë" për të treguar se cili veprim po ndërmerret.
Në një artikull të veçantë, unë demonstroj se si të përdorni Ajax për një sistem të thjeshtë vlerësimi. Kodi i ngjashëm Ajax mund të përdoret gjithashtu për sistemin e rishikimit.