અમે પોસ્ટ એડિટર સુવિધા પણ સામેલ કરીશું કસ્ટમ ફીલ્ડ્સ (કસ્ટમ અથવા કસ્ટમ ક્ષેત્રો) દરેક પ્રકાર માટે અને નવા નમૂનાઓમાં ક્ષેત્રો દર્શાવો.
WordPress માં, કસ્ટમ પોસ્ટ પ્રકારો તમને તમારા વપરાશકર્તાઓને સામગ્રી કેવી રીતે પ્રદર્શિત કરવી તેના પર સંપૂર્ણ નિયંત્રણ આપે છે. જો તમે તમારા બ્લોગ પર પોસ્ટ્સ બનાવો છો, તો તમે બનાવી શકો છો કસ્ટમ શૈલીઓમાત્ર તેમના માટે. જો તમે સંગીત અથવા મૂવી વિશે સમીક્ષાઓ લખો છો, તો તમે ઇચ્છો તે પોસ્ટ્સમાં વધારાના ઇનપુટ વિસ્તારો ઉમેરી શકો છો અને તે અન્ય બ્લોગ પોસ્ટ્સમાં દેખાશે નહીં.
પરંતુ અમે ચાલુ રાખતા પહેલા, ચાલો સમજીએ કે વપરાશકર્તા પોસ્ટ્સ શું છે.
વર્ડપ્રેસ કસ્ટમ પોસ્ટ પ્રકારો શું છે?
ટૂંકમાં, WordPress કસ્ટમ પોસ્ટ પ્રકારો તમને તેમની સામગ્રીના આધારે પોસ્ટ્સને સૉર્ટ કરવાની મંજૂરી આપે છે. વર્ડપ્રેસમાં, ડિફોલ્ટ પોસ્ટ પ્રકારો પોસ્ટ, પેજ, મીડિયા વગેરે છે.
સામાન્ય રીતે, તમે એડમિન કન્સોલના પોસ્ટ વિભાગમાં તમારી બધી પોસ્ટ્સ લખો છો, પછી તેમને એક શ્રેણી સોંપો. બધી એન્ટ્રીઓ વિવિધ પ્રકારોસમાન સૂચિમાં છે, સામગ્રી પ્રકાર દ્વારા તેમને અલગ પાડવાનું મુશ્કેલ બનાવે છે.
એડમિન કન્સોલમાં તેમની પોતાની લિંક્સ સાથે કસ્ટમ પોસ્ટ પ્રકારો તમને તે પ્રકારની પોસ્ટ્સની સૂચિ પર લઈ જાય છે. આ રીતે બનાવેલી પોસ્ટને નિયમિત પોસ્ટની જેમ કેટેગરીઝ અસાઇન કરી શકાય છે, જેથી તમે ઇચ્છો તે રીતે પોસ્ટ્સને સૉર્ટ કરવા અને પ્રસ્તુત કરવાની તમારી પાસે સંપૂર્ણ સ્વતંત્રતા છે.
ઉપરના ઉદાહરણમાં, જો કોઈ વપરાશકર્તા તમારી સાઇટના મૂવી ડેટાબેઝ વિભાગમાં જાય છે, તો સમીક્ષા પોસ્ટ્સ શામેલ કરવામાં આવશે નહીં. જો તમે 'એક્શન' અને 'રોમાન્સ' કેટેગરીઝ બનાવો છો, ઉદાહરણ તરીકે, તમારા યુઝર્સ એક્શન મૂવી કેટેગરીમાં જઈને કેટેગરીના તમામ રિવ્યુ અને મૂવીઝ જોઈ શકશે.
જ્યારે તમે બનાવો છો નવો પ્રકારપ્રકાશન, તમારી પાસે ઘણી સેટિંગ્સ છે, જેમ કે: એડમિન મેનૂમાં લિંક ક્યાં સ્થિત હશે, શું આ પ્રકાર શોધ પરિણામોમાં શામેલ કરવામાં આવશે કે કેમ, ટેક્સ્ટ ફ્રેગમેન્ટ પ્રદર્શિત કરવું સપોર્ટેડ હશે કે કેમ, ટિપ્પણીઓને મંજૂરી છે કે કેમ, વગેરે.
તમે વિવિધ શીર્ષક પાઠો બદલી શકો છો (એરેનો ઉપયોગ કરીને વ્યાખ્યાયિત $લેબલ્સ), જેમ કે નામ બદલો નવી પોસ્ટ ઉમેરોવી નવી મૂવી ઉમેરો. ઉદાહરણ તરીકે, તમે ટેક્સ્ટનું નામ બદલી શકો છો ફીચર્ડ ઈમેજવી પોસ્ટર ઉમેરો.
તમે તમારા પોસ્ટ એડિટરમાં કસ્ટમ ફીલ્ડ ફીચરને પણ સક્ષમ કરી શકો છો, જે ડિફોલ્ટ રૂપે છુપાયેલ છે અને લિંક દ્વારા સક્ષમ હોવું આવશ્યક છે. સ્ક્રીન વિકલ્પોસંપાદકની ટોચ પર.
મૂવીઝ અને મૂવી રિવ્યુઝના ઉદાહરણ સાથે આગળ વધીને, મૂવી પ્રકાશનો પેરામીટર્સ માટે કસ્ટમ/કસ્ટમ ફીલ્ડ ઉમેરી શકે છે જેમ કે રિલીઝનું વર્ષ, ડિરેક્ટર, રેટિંગ અને ઘણા બધા સંક્ષિપ્ત ઝાંખીરેકોર્ડિંગ સામગ્રી તરીકે મૂવીઝ.
સામાન્ય રીતે તમે બનાવેલ કોઈપણ ફીલ્ડ કોઈપણ પોસ્ટ પ્રકારમાં ઉપલબ્ધ છે, તેથી પ્લગઇનને દરેક ફીલ્ડ પર પ્રતિબંધોની જરૂર છે જ્યાં તેને ઍક્સેસ કરી શકાય છે.
નવા પોસ્ટ પ્રકારો બનાવી રહ્યા છે
જ્યારે તમે WordPress માં નોંધપાત્ર ફેરફારો કરો છો, ત્યારે ઉપલબ્ધ અમલીકરણ વિકલ્પોમાંથી એક પ્લગઇન બનાવવાનું છે. તમે ફાઇલમાં નવા કસ્ટમ પોસ્ટ પ્રકારો પણ બનાવી શકો છો functions.php. આ માર્ગદર્શિકા માટે અમે ચાલો એક પ્લગઈન બનાવીએ અને મૂવી/રિવ્યુ ડેટાબેઝ સાથે ઉદાહરણનો ઉપયોગ કરવાનું ચાલુ રાખીએ.
કસ્ટમ પોસ્ટ પ્રકાર બનાવવા માટે, તમારે ઘણા ફંક્શન લખવાની જરૂર છે જે વર્ડપ્રેસ ફંક્શનને કૉલ કરે છે નોંધણી_પોસ્ટ_પ્રકાર()બે પરિમાણો સાથે. તમારું કાર્ય જોઈએક્રિયા હૂક સાથે બંધાયેલા રહો init, અન્યથા કસ્ટમ પોસ્ટ પ્રકાર યોગ્ય રીતે રજીસ્ટર થશે નહીં.
// કસ્ટમ ફંક્શનને init એક્શન હૂક add_action("init", "lc_register_movie_post_type") સાથે જોડવું આવશ્યક છે; // કસ્ટમ ફંક્શન કે જે register_post_type ફંક્શનને કૉલ કરે છે lc_register_movie_post_type() ( // ટેક્સ્ટના વિવિધ ટુકડાઓ સેટ કરો, $labelsનો ઉપયોગ $args array $labels = array("name" => _x("Movies", "post type General) ની અંદર થાય છે નામ"), "singular_name" => _x("મૂવી", "પોસ્ટ પ્રકાર એકવચન નામ"), ...); // પોસ્ટ પ્રકાર $args = array("labels" => $ વિશે માહિતીના વિવિધ ટુકડાઓ સેટ કરો labels, "description" => "મારી કસ્ટમ પોસ્ટ પ્રકાર", "public" => true, ...); args);
અન્ય પ્લગિન્સ અથવા થીમ ફંક્શન્સ સાથે વિરોધાભાસ ટાળવા માટે તમામ કસ્ટમ ફંક્શન્સ ઉપસર્ગમાં હોવા જોઈએ. અહીં ઉપસર્ગ LC નો ઉપયોગ કરવામાં આવશે.
કાર્ય માટે બે પરિમાણો નોંધણી_પોસ્ટ_પ્રકાર()આ:
- રેકોર્ડ પ્રકારનું નામ, મહત્તમ 20 અક્ષરો અને તેમાં સ્પેસ અથવા કેપિટલ લેટર ન હોવા જોઈએ
- એક સહયોગી એરે કહેવાય છે $args, જેમાં કી-વેલ્યુ જોડીના સ્વરૂપમાં રેકોર્ડ પ્રકાર વિશેની માહિતી શામેલ છે 'key' => 'મૂલ્ય'
અરે $args
એરે માટે સૌથી વધુ ઉપયોગમાં લેવાતી કી $argsનીચે બતાવેલ, બધા વૈકલ્પિક છે:
- લેબલ્સ- એરે એરે, જે ટેક્સ્ટના વિવિધ ભાગોનો ઉલ્લેખ કરે છે, ઉદાહરણ તરીકે 'નવી એન્ટ્રી ઉમેરો'નું નામ બદલીને 'ઉમેરો' કરી શકાય છે નવી ફિલ્મ'. લેબલ્સ એરે માટેની કીઓ નીચે સ્પષ્ટતા સાથે વર્ણવેલ છે;
- વર્ણન- રેકોર્ડ પ્રકારનું ટૂંકું અને સંક્ષિપ્ત વર્ણન, તે પ્રકારના નમૂનાઓમાં પ્રદર્શિત કરી શકાય છે, પરંતુ તેનો ક્યાંય ઉપયોગ થતો નથી;
- જાહેર- લેખક અને મુલાકાતીઓ માટે દૃશ્યમાન પોસ્ટ પ્રકાર છે, ડિફોલ્ટ મૂલ્ય FALSE છે, જેનો અર્થ છે કે તે એડમિન કન્સોલમાં પણ દેખાતું નથી;
- શોધમાંથી_બાકાત- શું આ પ્રકારના રેકોર્ડ્સ નિયમિત શોધ પરિણામોમાં દેખાશે, ડિફોલ્ટ મૂલ્ય વિરોધી અર્થજાહેર;
- સાર્વજનિક રીતે_ક્વેરી કરવા યોગ્ય– શું આ પ્રકારની પોસ્ટ URL નો ઉપયોગ કરીને પુનઃપ્રાપ્ત કરી શકાય છે, જેમ કે http://www.mywebsite.com/?post_type=movie, અથવા query_posts() ફંક્શન દ્વારા અદ્યતન ઉપયોગમાં. ડિફૉલ્ટ મૂલ્ય સાર્વજનિક છે;
- show_ui- મેનુ લિંક્સ અને મેસેજ એડિટર એડમિનિસ્ટ્રેટર કંટ્રોલ પેનલમાં જોડાયેલા છે કે કેમ. ડિફૉલ્ટ મૂલ્ય સાર્વજનિક છે;
- nav_menus માં બતાવો– શું આ પ્રકારની એન્ટ્રીઓ પેજ પર બનાવેલ નેવિગેશન મેનુમાં ઉમેરવામાં આવશે દેખાવ->મેનુ, ડિફૉલ્ટ મૂલ્ય સાર્વજનિક છે;
- બતાવો_માં_મેનુ- એડમિન કન્સોલના નેવિગેશનમાં પોસ્ટ ટાઇપ લિંક પ્રદર્શિત થાય છે કે કેમ. FALSE - લિંક છુપાવે છે. TRUE – લિંકને નવી ટોચ-સ્તરની લિંક તરીકે ઉમેરે છે. લાઇન દાખલ કરવાથી તમે હાલની ટોચ-સ્તરની લિંકની અંદર એક લિંક મૂકી શકો છો, એટલે કે પરિમાણો દાખલ કરો વિકલ્પો-general.phpતેને સેટિંગ્સ લિંક હેઠળ મૂકે છે.
- show_in_admin_bar- શું આ પ્રકારની પોસ્ટ એડમિન બારની ઉપર, લિંક હેઠળ દેખાશે + નવું
- મેનુ_સ્થિતિ- સ્થિતિ નવી લિંકએડમિન કન્સોલના નેવિગેશન મેનૂમાં, 5 પોસ્ટ્સની નીચે સ્થિત છે, 100 સેટિંગ્સની નીચે સ્થિત છે, સ્થિતિઓની સંપૂર્ણ સૂચિ WordPress કોડેક્સમાં મળી શકે છે
- વંશવેલો- શું પેરેન્ટ રેકોર્ડને રેકોર્ડ અસાઇન કરી શકાય છે, જો મૂલ્ય TRUE હોય, તો એરે $સપોર્ટ કરે છે'page-attributes' પરિમાણ ધરાવતું હોવું જોઈએ
- આધાર આપે છે- પસંદગીપૂર્વક પોસ્ટ કાર્યોને સક્ષમ કરે છે જેમ કે: છબીઓ, ટેક્સ્ટ ટુકડાઓ, કસ્ટમ ફીલ્ડ્સ, વગેરે. જો FALSE પર સેટ કરેલ હોય, તો પછી એરેને બદલે, આ પ્રકારની પોસ્ટ માટે સંપાદક બંધ કરવામાં આવે છે - જો તમે આની બધી પોસ્ટ બંધ કરવા માંગતા હોવ તો ઉપયોગી સંપાદનમાંથી ટાઇપ કરો, પરંતુ તેમને દૃશ્યમાન રહેવા દો ( એરે મૂલ્યોની સૂચિ nee)
- વર્ગીકરણ– વર્ગીકરણની શ્રેણી કે જે આ પ્રકારના પ્રકાશનો પર લાગુ કરી શકાય છે, વર્ગીકરણ પહેલેથી જ નોંધાયેલ હોવું જોઈએ - તે અહીંથી બનાવવામાં આવ્યું નથી!
- has_archive- શું આ પ્રકારની પોસ્ટમાં આર્કાઇવ પૃષ્ઠો હશે, URL માં પરમાલિંક માળખું હશે અને URL નો વર્ણનાત્મક ભાગ register_post_types() ફંક્શનનું પેરામીટર 1 છે, એટલે કે, http://www.mywebsite.com/movie_reviews/ દેખાશે બધી મૂવી_સમીક્ષા પોસ્ટ.
- query_var– સાચું કે ખોટું એ નક્કી કરે છે કે પોસ્ટના પ્રકાર અને પોસ્ટના નામ માટે URL ને પૂછીને પોસ્ટ બતાવી શકાય છે, એટલે કે 'http://www.mywebsite.com/? ફિલ્મ=મેટ્રિક્સ' જો તમે ટેક્સ્ટની લાઇન દાખલ કરો છો, તો તમારે ? ફિલ્મ=મેટ્રિક્સ‘.
લેબલ્સની એરે
એરેમાં પ્રથમ કી $argsકહેવાય છે લેબલ્સઅને એરે હોવી જોઈએ. તે પોસ્ટ પ્રકારથી સંબંધિત ટેક્સ્ટના વિવિધ ટુકડાઓનો ઉલ્લેખ કરે છે. અહીં ઘણા બધા ડેટા હોઈ શકે છે, તેથી નામની એરે બનાવવી શ્રેષ્ઠ છે $લેબલ્સતેમના સંગ્રહ માટે. ઉપરનો કોડ આનો અર્થ શું છે તે થોડું સ્પષ્ટ કરે છે.
નીચે લેબલ્સ એરે માટે કેટલીક મહત્વપૂર્ણ કી છે, બધી વૈકલ્પિક છે:
- નામ – સામાન્ય નામોસંદેશના પ્રકાર માટે, ઉદાહરણ તરીકે મૂવીઝ
- એકવચન_નામ- આ પ્રકારની એક એન્ટ્રી માટેનું નામ, ઉદાહરણ તરીકે, મૂવી (મૂવી)
- ઉમેરો_નવું- ઉલ્લેખિત ટેક્સ્ટ સાથે 'નવું ઉમેરો' ટેક્સ્ટને બદલવું, ઉદાહરણ તરીકે, 'મૂવી ઉમેરો'
- નવી_આઇટમ ઉમેરો- 'નવી પોસ્ટ ઉમેરો' માટે રિપ્લેસમેન્ટ, ઉદાહરણ તરીકે, 'નવી મૂવી ઉમેરો' સાથે
- આઇટમ સંપાદિત કરો- 'એડિટ પોસ્ટ' માટે રિપ્લેસમેન્ટ, ઉદાહરણ તરીકે, 'મૂવી એડિટ' સાથે
- વૈશિષ્ટિકૃત_છબી- પોસ્ટ એડિટરમાં 'ફીચર્ડ ઈમેજ' માટે રિપ્લેસમેન્ટ, ઉદાહરણ તરીકે, 'મૂવી પોસ્ટર' સાથે
- સેટ_વિશિષ્ટ_છબી- 'સેટ ફીચર્ડ ઇમેજ'ને બદલીને, ઉદાહરણ તરીકે, આ વિકલ્પ 'એડ મૂવી પોસ્ટર' સાથે
- મેનુ_નામ- લિંક ટેક્સ્ટને બદલવું ઉપલા સ્તર, ડિફૉલ્ટ લિંક ટેક્સ્ટ કી નામ
એરે આધાર આપે છે
// મારા પોસ્ટ પ્રકાર $supports = એરે ("શીર્ષક", "સંપાદક", "લેખક", "થંબનેલ") માટે પોસ્ટ સંપાદકમાં વિશિષ્ટ સુવિધાઓ સક્ષમ કરો; // મારા પોસ્ટ પ્રકાર $supports = FALSE માટે પોસ્ટ સંપાદકની તમામ સુવિધાઓને અક્ષમ કરો;એરેમાંની એક કી $argsકહેવાય છે આધાર આપે છે. આ એક સરળ એરે છે જ્યાં તમે પોસ્ટ એડિટર સુવિધાઓની સૂચિ રેકોર્ડ કરો છો જેને તમે તમારા પોસ્ટ પ્રકાર માટે સક્ષમ કરવા માંગો છો. મૂળભૂત રીતે, ફક્ત શીર્ષક અને સંપાદક સક્ષમ છે.
તમે બધા સંપાદક કાર્યોને અક્ષમ કરવા માટે એરેને બદલે FALSE પણ સેટ કરી શકો છો, શીર્ષક અને સામગ્રી ઉમેરવાનો વિસ્તાર બંનેને બંધ કરીને. આનો અર્થ એ છે કે એન્ટ્રી સંપાદિત કરી શકાતી નથી, પરંતુ હજુ પણ સંપૂર્ણ રીતે દૃશ્યમાન છે.
અહીં ફંક્શન્સની સૂચિ છે જે તમે એરેમાં શામેલ કરી શકો છો $સપોર્ટ કરે છે:
- શીર્ષક
- સંપાદક
- લેખક - નોંધ: આ તમને પોસ્ટના લેખકને બદલવાની મંજૂરી આપે છે
- થંબનેલ (ચિહ્ન)
- અવતરણ (ટેક્સ્ટ ફ્રેગમેન્ટ)
- ટ્રેકબેક્સ
- કસ્ટમ-ફીલ્ડ્સ (કસ્ટમ ફીલ્ડ)
- ટિપ્પણીઓ
- પુનરાવર્તનો (સંસ્કરણો)
- પૃષ્ઠ- વિશેષતાઓ
- પોસ્ટ-ફોર્મેટ્સ (પોસ્ટ ફોર્મેટ્સ)
પ્લગઇન દ્વારા કસ્ટમ વર્ડપ્રેસ પોસ્ટ પ્રકાર બનાવવો
હવે જ્યારે આપણે જાણીએ છીએ કે ફંક્શન માટે કયા પરિમાણો જરૂરી છે, તો આપણે આપણું પોતાનું પ્લગઈન બનાવી શકીએ છીએ, લખી શકીએ છીએ પોતાનું કાર્યઅને તેને ઇવેન્ટ સાથે જોડો init.
lc_custom_post_movie() init એક્શન હૂક add_action("init", "lc_custom_post_movie"); // મૂવી પોસ્ટ પ્રકાર ફંક્શન lc_custom_post_movie() ( // લેબલ્સ સેટ કરો, આ ચલનો ઉપયોગ $args array $labels = array("name" => __("Movies"), "singular_name" માં થાય છે " => __("મૂવી"), "add_new" => __("નવી મૂવી ઉમેરો"), "add_new_item" => __("નવી મૂવી ઉમેરો"), "edit_item" => __("મૂવી સંપાદિત કરો") , "new_item" => __("નવી મૂવી"), "all_items" => __("બધી ફિલ્મો"), "view_item" => __("મૂવી જુઓ"), "search_items" => __("ચલચિત્રો શોધો "), "featured_image" => "પોસ્ટર", "set_featured_image" => "પોસ્ટર ઉમેરો"); // અમારી પોસ્ટ પ્રકાર માટેની દલીલો, register_post_type() $args = array("labels" ના પરિમાણ 2 તરીકે દાખલ કરવાની છે. => $લેબલ્સ, "વર્ણન" => "અમારી મૂવીઝ અને મૂવી ચોક્કસ ડેટા ધરાવે છે", "સાર્વજનિક" => સાચું, "મેનુ_પોઝિશન" => 5, "સમર્થન" => એરે("શીર્ષક", "સંપાદક", " થંબનેલ", "અંતર", "ટિપ્પણીઓ", "કસ્ટમ-ફીલ્ડ્સ"), "has_archive" => true, "show_in_admin_bar" => true, "show_in_nav_menus" => true, "has_archive" => true, "query_var" = > "ફિલ્મ"); // વાસ્તવિક વર્ડપ્રેસ ફંક્શનને કૉલ કરો // પેરામીટર 1 એ પોસ્ટ પ્રકારનું નામ છે // પેરામીટર 2 એ $args એરે register_post_type("movie", $args); ) // હૂક lc_custom_post_movie_reviews() init એક્શન હૂક add_action("init", "lc_custom_post_movie_reviews"); // મૂવી રિવ્યુ પોસ્ટ ટાઇપ ફંક્શન lc_custom_post_movie_reviews() રજીસ્ટર કરવા માટે કસ્ટમ ફંક્શન ( // લેબલ્સ સેટ કરો, આ ચલનો ઉપયોગ $args array $labels = array("name" => __("Movie Reviews"), "singular_name" => __("મૂવી રીવ્યુ"), "add_new" => __("નવી મૂવી રીવ્યુ ઉમેરો"), "add_new_item" => __("નવી મૂવી રીવ્યુ ઉમેરો"), "edit_item" => __( "મૂવી રિવ્યુ સંપાદિત કરો"), "new_item" => __("નવી મૂવી રીવ્યુ"), "all_items" => __("બધી મૂવી રીવ્યુ"), "View_item" => __("મૂવી રીવ્યુ જુઓ"), " search_items" => __("ચલચિત્ર સમીક્ષાઓ શોધો")); // અમારી પોસ્ટ પ્રકાર માટેની દલીલો, register_post_type() $args = array("labels" => $labels, "description" = ના પરિમાણ 2 તરીકે દાખલ કરવી. > "અમારી મૂવી સમીક્ષાઓ ધરાવે છે", "સાર્વજનિક" => સાચું, "મેનુ_પોઝિશન" => 6, "સમર્થન" => એરે("શીર્ષક", "સંપાદક", "થંબનેલ", "અંતર", "ટિપ્પણીઓ", " custom-fields"), "has_archive" => true, "show_in_admin_bar" => true, "show_in_nav_menus" => true, "has_archive" => true); // વાસ્તવિક WordPress ફંક્શનને કૉલ કરો // પેરામીટર 1 એનું નામ છે પોસ્ટ પ્રકાર // $args એરે પરિમાણ 2 માં જાય છે. register_post_type("review", $args); )
જો તમે આ પ્લગઇનને સક્ષમ કરો છો, તો તમને પોસ્ટ્સ લિંકની બરાબર પછી એડમિન કન્સોલના નેવિગેશન બારમાં એક નવી લિંક દેખાશે.
માઉસને હોવર કરતી વખતે, મેનૂ આઇટમ્સ 'બધા જુઓ' અને 'નવું ઉમેરો' બતાવવામાં આવશે, ટેક્સ્ટ એરેમાં નિર્દિષ્ટ કરેલાને અનુરૂપ હશે. $લેબલ્સ. એડિટરમાં જુઓ જ્યાં લિંક્સ બદલાઈ છે.
આપેલ રેકોર્ડ્સ માટે કસ્ટમ ફીલ્ડ્સને મર્યાદિત કરો
જ્યારે તમે તમારા ફીલ્ડ્સને રેકોર્ડમાં ઉમેરો છો, ત્યારે ફીલ્ડ્સ સાચવવામાં આવે છે અને તમે નવા રેકોર્ડમાં ઝડપથી કોઈપણ ઉમેરી શકો છો. તમે ઉમેરેલ કસ્ટમ ફીલ્ડ દરેક એન્ટ્રીની ડ્રોપડાઉન સૂચિમાં દેખાશે. આનાથી અમુક પોસ્ટ પ્રકારોમાં તમે જે ફીલ્ડ શોધી રહ્યાં છો તે શોધવાનું મુશ્કેલ બનાવી શકે છે. જો તમે કસ્ટમ ફીલ્ડ્સને પ્રતિબંધિત કરવા માંગો છો જેથી કરીને તે માત્ર અમુક પોસ્ટ પ્રકારો માટે જ ઉપલબ્ધ હોય, તો સૌથી સહેલો રસ્તો પ્લગઇન દ્વારા છે.
get_post_meta()
- 3 પરિમાણો લે છે અને પરત કરે છેપરિણામ
- પ્રથમ પરિમાણ પોસ્ટ ID છે, તમે તેનો ઉપયોગ અહીં કરી શકો છો $post->IDહાલમાં પ્રદર્શિત એન્ટ્રીનું ID મેળવવા માટે
- બીજું પરિમાણ – કસ્ટમ રેકોર્ડ ફીલ્ડનું નામ, કેસ સેન્સિટિવ
- ત્રીજું પરિમાણ બુલિયન પ્રકારનું છે, જેને કહેવાય છે $સિંગલઅને TRUE હોઈ શકે છે (એક શબ્દમાળા તરીકે પરિણામ આપે છે) અથવા FALSE (એરે આપે છે).
ID, "બોક્સ આર્ટ", TRUE); જો (!ખાલી($movie_box_art)) ( ?>નોંધ:તમે સમાન નામ અને વિવિધ મૂલ્યો સાથે બહુવિધ કસ્ટમ ફીલ્ડ બનાવી શકો છો. જો ત્યાં સમાન નામ સાથે બહુવિધ ફીલ્ડ હોય, તો FALSE સેટ કરવાથી તેમાંથી એક એરે મળશે.
કાર્ય થી get_post_meta()મૂલ્ય પરત કરે છે, તમે તે મુજબ દેખાવ બદલવા માટે શરતી અભિવ્યક્તિમાં મૂલ્યનો ઉપયોગ કરી શકો છો.
ઉપરના ઉદાહરણમાં, અમે એ જોવા માટે તપાસીએ છીએ કે શું મૂવીમાં તેને કસ્ટમ ફીલ્ડ તરીકે સોંપેલ બોક્સ આર્ટ છે. જો $movie_box_artખાલી નથી, ડિસ્પ્લે ડીવી અને ઈમેજ.
અદ્યતન કસ્ટમ ફીલ્ડ્સ પ્રદર્શિત કરી રહ્યાં છે
// પ્રદર્શિત ક્ષેત્ર મૂલ્ય the_field("FIELD NAME"); // રીટર્ન ફીલ્ડ વેલ્યુ get_field("FIELD NAME");એડવાન્સ્ડ કસ્ટમ ફીલ્ડ્સ પ્લગઇન ક્ષેત્રો પ્રદર્શિત કરવા માટે તેના પોતાના કાર્યો અને શોર્ટકોડ્સ પ્રદાન કરે છે.
the_field('FIELD NAME');
ઉલ્લેખિત ફીલ્ડનું મૂલ્ય દર્શાવે છે, તમારે ફીલ્ડ જૂથ બનાવતી વખતે તમે ઉલ્લેખિત ક્ષેત્રના નામનો ઉપયોગ કરવો આવશ્યક છે.
get_field('FIELD NAME');
શરતી અભિવ્યક્તિઓ માટે ઉપયોગી, ઉલ્લેખિત ફીલ્ડનું મૂલ્ય પરત કરે છે.
આ તે સુવિધાઓ છે જે તમને મોટે ભાગે જરૂર પડશે. ત્યાં ઘણી વધારાની સુવિધાઓ છે અને તમે તેને માં શોધી શકો છો.
શોર્ટકોડ્સ
તમે ઉપરના શોર્ટકોડનો ઉપયોગ કરીને સીધા જ પોસ્ટ પર ફીલ્ડ પ્રદર્શિત કરી શકો છો.
મુખ્ય પૃષ્ઠ પર કસ્ટમ પોસ્ટ પ્રકાર દર્શાવો
// અમારા કસ્ટમ ફંક્શનને pre_get_posts એક્શન હૂક add_action("pre_get_posts", "add_reviews_to_frontpage"); // મુખ્ય ક્વેરી ફંક્શનને બદલો add_reviews_to_frontpage($query) ( if (is_home() && $query->is_main_query()) ( $query->set("post_type", array("post", "movie", "review) ")); ) $ક્વેરી પરત કરો;)કસ્ટમ પોસ્ટ પ્રકારો મૂળભૂત રીતે મુખ્ય પૃષ્ઠ પર દેખાતા નથી, તેથી તમારે એક નવું કાર્ય બનાવવાની જરૂર છે જે ઑબ્જેક્ટની સેટ પદ્ધતિને કૉલ કરે છે WP_Queryવર્ડપ્રેસ.
ફંક્શન તપાસે છે કે મુલાકાતી હોમ પેજ પર છે કે કેમ અને સક્રિય વિનંતી વર્ડપ્રેસ દ્વારા જનરેટ કરાયેલ પ્રાથમિક વિનંતી છે કે કેમ.
$query->સેટ()બે પરિમાણો લે છે:
- પ્રથમ પરિમાણ એ પ્રાથમિકતા છે જેને તમે બદલવા માંગો છો, અમારા કિસ્સામાં અમે અગ્રતા બદલીએ છીએ પોસ્ટ_પ્રકાર
- બીજું પરિમાણ એ એરે છે જે તમે વિશેષતા મૂલ્ય તરીકે પસાર કરવા માંગો છો પોસ્ટ_પ્રકાર
ઉપરના કોડ ઉદાહરણમાં, એરે 'પોસ્ટ' થી શરૂ થાય છે - તેથી જ દરેક વર્ડપ્રેસ પોસ્ટ 'પોસ્ટ' પ્રકારની હોય છે અને અમે હજી પણ તેને મુખ્ય પૃષ્ઠ પર શામેલ કરવા માંગીએ છીએ.
જો તમે તમારા હોમ પેજ પર આપેલ પ્રકારની કસ્ટમ પોસ્ટનો જ ઉપયોગ કરવા માંગતા હો, તો તમે 'પોસ્ટ્સ' દૂર કરી શકો છો અને તમારા પોતાના પોસ્ટ પ્રકારનો ઉપયોગ કરી શકો છો.
તમે દાખલ કરેલ મૂલ્ય ફંક્શનના પેરામીટર 1 સાથે મેળ ખાતું હોવું જોઈએ નોંધણી_પોસ્ટ_પ્રકાર().
નિષ્કર્ષ
આ ટ્યુટોરીયલમાં, અમે બતાવીએ છીએ કે કસ્ટમ પ્રકાર કેવી રીતે બનાવવો અને તે કરવા માટે તમારે કયા ડેટાની જરૂર છે. કસ્ટમ પોસ્ટ પ્રકારોની લવચીકતા કોઈપણ WordPress સાઇટ માટે મૂલ્યવાન કાર્યક્ષમતા પ્રદાન કરે છે.
વર્ડપ્રેસ બધું કસ્ટમાઇઝેશન/કસ્ટમાઇઝેશન વિશે છે. તે એવી રીતે બનાવવામાં આવ્યું હતું કે સંપૂર્ણપણે દરેક વિભાગને કસ્ટમાઇઝ કરી શકાય. આ ટ્યુટોરીયલમાં આપણે જોઈશું કસ્ટમ પોસ્ટ પ્રકારો, વર્ડપ્રેસની સૌથી નોંધપાત્ર અને નોંધપાત્ર વિશેષતાઓમાંની એક, જેની મદદથી વર્ડપ્રેસ નવી ઊંચાઈઓ સુધી પહોંચવામાં સફળ રહ્યું છે.
કસ્ટમ પોસ્ટ પ્રકારો શું છે?
ચાલો કહીએ કે તમે ઈચ્છો છો કે તમારા બ્લોગમાં મૂવી સમીક્ષાઓ માટે એક અલગ વિભાગ હોય. કસ્ટમ પોસ્ટ પ્રકારોનો ઉપયોગ કરીને તમે એક નવો પ્રકાર બનાવી શકો છો, ઉદાહરણ તરીકે, પોસ્ટ્સ અને પેજીસ, જેમાં અલગ પ્રકારનો ડેટા હશે. તેનું પોતાનું એડમિન મેનૂ, સંપાદન માટે વિશેષ પૃષ્ઠો, તેના પોતાના વર્ગીકરણ અને અન્ય ઘણા સાધનો હશે જે પ્રકાશનો સાથે સંપૂર્ણ રીતે કામ કરવા માટે જરૂરી છે.
કસ્ટમ પોસ્ટ પ્રકારો એ એડમિન સેટિંગ્સનો વધારાનો સમૂહ છે જે ડિફોલ્ટ પોસ્ટ પ્રકારો માટે સેટિંગ્સની સાથે અસ્તિત્વ ધરાવે છે જેમ કે રેકોર્ડ, પૃષ્ઠો, જોડાયેલ ફાઇલો, વગેરે કસ્ટમ પોસ્ટ પ્રકારો કોઈપણ પ્રકારનો ડેટા સ્ટોર કરી શકે છે. તેમની પાસે એક અલગ એડિટર, મીડિયા અપલોડર છે અને તે પહેલાથી અસ્તિત્વમાં રહેલા વર્ડપ્રેસ ટેબલ સ્ટ્રક્ચરનો ઉપયોગ કરે છે, જે ડેટા મેનેજમેન્ટને સરળ બનાવે છે. વર્ડપ્રેસ API નો ઉપયોગ કરીને બનાવેલ કસ્ટમ પોસ્ટ પ્રકારોનો મુખ્ય ફાયદો એ છે કે તે હાલની થીમ્સ અને ટેમ્પ્લેટ્સ સાથે સુસંગત છે. ઉપરાંત, પરમાલિંક્સના ઉપયોગ માટે આભાર, કસ્ટમ પોસ્ટ પ્રકારો સર્ચ એન્જિન સાથે સારી રીતે સંપર્ક કરે છે.
કસ્ટમ પોસ્ટ પ્રકારો શા માટે વાપરો?
કસ્ટમ પોસ્ટ પ્રકારો તમને વિવિધ સ્થળોએ વિવિધ પ્રકારની પોસ્ટ સ્ટોર કરવામાં મદદ કરે છે. આ નિયમિત પોસ્ટને અન્ય લોકોથી અલગ કરવામાં મદદ કરે છે. બસ એટલું જ.
કસ્ટમ પોસ્ટ પ્રકાર માટે પ્લગઇન બનાવવું
અમે કસ્ટમ પોસ્ટ પ્રકાર માટે એક પ્લગઇન બનાવીશું જે શ્રેષ્ઠ મૂવી સમીક્ષાઓ પ્રદર્શિત કરશે. ચાલો શરુ કરીએ.
પગલું 1. વર્ડપ્રેસ પ્લગઇન માટે ફોલ્ડર બનાવો
તમારું વર્ડપ્રેસ પ્લગઈન્સ ફોલ્ડર ખોલો અને નવું ફોલ્ડર બનાવો મૂવી-સમીક્ષાઓ.
પગલું 2: PHP ફાઇલ બનાવો
બનાવેલ ફોલ્ડરમાં, PHP ફાઇલ બનાવો Movie-Reviews.php
પગલું 3: હેડર ઉમેરો
બનાવેલ ફાઈલ ખોલો અને ટોચ પર હેડર માટે કોડ પેસ્ટ કરો.
PHP કમાન્ડના ક્લોઝિંગ ટૅગ પહેલાં, નીચેની કોડની લાઇન દાખલ કરો create_movie_review. જ્યારે પ્રારંભ કરવામાં આવે છે, ત્યારે તે દર વખતે પૃષ્ઠ જનરેટ થાય ત્યારે યોગ્ય કસ્ટમ ફંક્શન ચલાવશે.
ઍડ_એક્શન("init", "create_movie_review");
પગલું 5: કાર્ય ચલાવો
Create_movie_review ફંક્શનને ચલાવવા માટેનો કોડ.
ફંક્શન create_movie_review() ( register_post_type("movie_reviews", array("labels" => array("name" => "Movie Reviews", "singular_name" => "Movie Review", "add_new" => "નવું ઉમેરો", "add_new_item" => "નવી મૂવી સમીક્ષા ઉમેરો", "edit" => "સંપાદિત કરો", "edit_item" => "મૂવી સમીક્ષા સંપાદિત કરો", "new_item" => "નવી મૂવી સમીક્ષા", "જુઓ" => જુઓ ", "view_item" => "મૂવી રિવ્યુ જુઓ", "search_items" => "મૂવી રિવ્યુ શોધો", "not_found" => "કોઈ મૂવી રિવ્યુ મળ્યા નથી", "not_found_in_trash" => "કચરાપેટીમાં કોઈ મૂવી રિવ્યુ મળ્યા નથી", "પેરેન્ટ" => "પેરેંટ મૂવી રિવ્યુ"), "સાર્વજનિક" => સાચું, "મેનુ_પોઝિશન" => 15, "સમર્થન" => એરે("શીર્ષક", "સંપાદક", "ટિપ્પણીઓ", "થંબનેલ", " custom-fields"), "taxonomies" => array(""), "menu_icon" => plugins_url("images/image.png", __FILE__), "has_archive" => true));)
register_post_type ફંક્શન અમારા કિસ્સામાં મોટા ભાગનું કામ કરશે. જલદી તેને બોલાવવામાં આવે છે, તે એડમિનિસ્ટ્રેટર માટે વધારાના વિભાગો સહિત, નવી વપરાશકર્તા પોસ્ટ માટે જરૂરી WordPress રૂપરેખાંકન તૈયાર કરશે. ફંક્શનમાં બે પ્રકારની દલીલો પસાર કરવામાં આવે છે: કસ્ટમ પોસ્ટ પ્રકારનું અનન્ય નામ અને તેની પ્રોપર્ટીઝ સાથેની એરે. આ અલગ અલગ લેબલ્સ સાથેનો બીજો એરે છે જે દર્શાવે છે કે કસ્ટમ પોસ્ટ પ્રકારના વિવિધ ભાગોમાં કઈ ટેક્સ્ટ સ્ટ્રિંગ્સ બતાવવામાં આવશે, ઉદાહરણ તરીકે: "નામ" કંટ્રોલ પેનલમાં કસ્ટમ પોસ્ટ પ્રકારનું નામ દર્શાવે છે, "સંપાદિત કરો" અને "જુઓ" પ્રદર્શન બટનો સંપાદિત કરોઅને જુઓ. મને લાગે છે કે અન્ય તમામ દલીલો પોતાને માટે બોલે છે.
તેથી, નીચેની દલીલોમાં:
- "public" => ટ્રુ એડમિન કંટ્રોલ પેનલ અને ફ્રન્ટ-એન્ડ બંનેમાં કસ્ટમ પોસ્ટ પ્રકારની દૃશ્યતા સેટ કરે છે.
- "menu_position" => 15 સ્પષ્ટ કરે છે કે મેનુમાં કસ્ટમ પોસ્ટ પ્રકાર ક્યાં સ્થિત હશે.
- "સમર્થન" => એરે("શીર્ષક", "સંપાદક", "ટિપ્પણીઓ", "થંબનેલ", "કસ્ટમ-ફીલ્ડ્સ") તે કસ્ટમ પોસ્ટ પ્રકારના લક્ષણોનો ઉલ્લેખ કરે છે જે પ્રદર્શિત થશે.
- "taxonomies" => એરે("") કસ્ટમ વર્ગીકરણ બનાવે છે. આ કિસ્સામાં તેઓ વ્યાખ્યાયિત નથી.
- "menu_icon" => plugins_url("images/image.png", __FILE__) એડમિન મેનૂમાં આઇકન બતાવે છે.
- "has_archive" => સાચું કસ્ટમ પોસ્ટ પ્રકારોને આર્કાઇવ કરવાની મંજૂરી આપે છે.
તમે WordPress Codex register_post_type પૃષ્ઠ પર કસ્ટમ પોસ્ટ પ્રકારોમાં ઉપયોગમાં લેવાતી અન્ય દલીલો વિશે વધુ જાણી શકો છો.
પગલું 6: કસ્ટમ પોસ્ટ પ્રકાર માટે આયકન
તમારા પ્લગઇન ફોલ્ડરમાં 16x16 પિક્સેલ આઇકન સાચવો. આ જરૂરી છે જેથી કંટ્રોલ પેનલ પર કસ્ટમ પોસ્ટ પ્રકારનું આઇકન હોય.
પગલું 7: પ્લગઇન સક્રિય કરો
પ્લગઇન અને વોઇલાને સક્રિય કરો, તમારી પાસે ટેક્સ્ટ સંપાદિત કરવાની ક્ષમતા, પોસ્ટ્સ, છબીઓ, ટિપ્પણીઓ અને કસ્ટમ ફીલ્ડ એડિટર માટે સેટિંગ્સ સાથે કસ્ટમ પોસ્ટ પ્રકાર છે.
પગલું 8: નવી એન્ટ્રી ઉમેરો
પસંદ કરો નવું ઉમેરોકસ્ટમ પોસ્ટ ટાઇપ એડિટિંગ પેનલ ખોલવા માટે. મૂવી શીર્ષક ઉમેરો, ટેક્સ્ટની સમીક્ષા કરો અને છબી થંબનેલ પસંદ કરો.
પગલું 9: પ્રકાશિત કરો
પોસ્ટ પ્રકાશિત કરો અને ક્લિક કરો મૂવી સમીક્ષા જુઓબનાવેલ મૂવી સમીક્ષા જોવા માટે.
કસ્ટમ પોસ્ટ પ્રકારો માટે વધારાના ક્ષેત્રો બનાવવું
વધારાના ક્ષેત્રો (મેટાબોક્સ) ની પદ્ધતિ વર્ડપ્રેસમાં બનેલ વધારાના ક્ષેત્રોની સિસ્ટમનો ઉપયોગ કરે છે. આ તમને એડિટરમાં ડિફૉલ્ટ કસ્ટમ ફીલ્ડનો ઉપયોગ કર્યા વિના કસ્ટમ પોસ્ટ પ્રકારો માટે વિશિષ્ટ ફીલ્ડ ઉમેરવામાં મદદ કરે છે.
પગલું 1: કસ્ટમ ફંક્શનની નોંધણી કરો
ફાઈલ ખોલો Movie-Reviews.phpઅને ક્લોઝિંગ ટેગ પહેલા નીચેનો કોડ ઉમેરો. આ કોડ એક ફંક્શન રજીસ્ટર કરે છે જેને વર્ડપ્રેસ એડમિન પેનલની મુલાકાત લેતી વખતે બોલાવવામાં આવશે.
ઍડ_એક્શન("એડમિન_ઇનિટ", "માય_એડમિન");
પગલું 2: કસ્ટમ કાર્ય ચલાવો
એક ફંક્શન એક્ઝેક્યુશન my_admin ઉમેરો જે વધારાના ફીલ્ડની નોંધણી કરે છે અને તેમને movie_reviews કસ્ટમ પોસ્ટ પ્રકાર સાથે સાંકળે છે.
ફંક્શન my_admin() ( add_meta_box("movie_review_meta_box", "મૂવી સમીક્ષા વિગતો", "display_movie_review_meta_box", "movie_reviews", "normal", "high");)
આ કિસ્સામાં, add_meta_box ફંક્શનનો ઉપયોગ કસ્ટમ પોસ્ટ પ્રકારમાં વધારાના ફીલ્ડ ઉમેરવા માટે થાય છે. વિશેષતાઓ વિશે:
- movie_review_meta_box HTML id માટે જરૂરી વિશેષતા
- મૂવી સમીક્ષા વિગતો ટેક્સ્ટ કે જે વધારાના ફીલ્ડના હેડરમાં દેખાશે
- display_movie_review_meta_box કૉલબેક ફંક્શન જે વધારાના ફીલ્ડની સામગ્રી દર્શાવે છે
- movie_review એ કસ્ટમ પોસ્ટ પ્રકારનું નામ છે જ્યાં વધારાના ફીલ્ડ્સ પ્રદર્શિત થશે
- સામાન્ય વ્યાખ્યાયિત કરે છે કે પૃષ્ઠ પર સંપાદન બ્લોક ક્યાં બતાવવામાં આવશે
- ઉચ્ચ પ્રદર્શિત ક્ષેત્રોની પ્રાથમિકતા નક્કી કરે છે
પગલું 3: ફંક્શન ડિસ્પ્લે_મૂવી_રીવ્યુ_મેટા_બોક્સ ચલાવો
ID, "movie_director", true));$movie_rating = intval(get_post_meta($movie_review->ID, "movie_rating", true)); | |
મૂવી ડિરેક્ટર |
તારાઓઆ કોડ વધારાના ક્ષેત્રોની સામગ્રી દર્શાવે છે. આ એક ઑબ્જેક્ટ વેરીએબલનો ઉપયોગ કરે છે જેમાં એડિટિંગ પેનલમાં બતાવેલ દરેક મૂવી રિવ્યૂ વિશેની માહિતી હોય છે. આ ઑબ્જેક્ટનો ઉપયોગ કરીને અમને મળ્યું
પોસ્ટ આઈડી
અને ડાયરેક્ટરનું નામ અને રેટિંગ મેળવવા માટે ડેટાબેઝની ક્વેરી કરવા માટે તેનો ઉપયોગ કર્યો, જે બદલામાં સ્ક્રીન પર ફીલ્ડ્સમાં પ્રદર્શિત થશે. નવી પોસ્ટ ઉમેરતી વખતે, get_post_meta ફંક્શન ખાલી સ્ટ્રિંગ આપશે અને વધારાના ફીલ્ડ્સ ખાલી થઈ જશે.પગલું 4: રેકોર્ડિંગ સેવિંગ ફંક્શનની નોંધણી કરો
એડ_એક્શન("સેવ_પોસ્ટ", "એડ_મૂવી_સમીક્ષા_ક્ષેત્રો", 10, 2);
ડેટાબેઝમાં રેકોર્ડ સાચવવામાં આવે ત્યારે આ ફંક્શન કહેવામાં આવે છે.પગલું 5: add_movie_review_fields ફંક્શનને એક્ઝિક્યુટ કરો
ફંક્શન add_movie_review_fields($movie_review_id, $movie_review) ( // મૂવી સમીક્ષાઓ માટે પોસ્ટ પ્રકાર તપાસો જો ($movie_review->post_type == "movie_reviews") ( // પોસ્ટ ડેટામાં હાજર હોય તો પોસ્ટ મેટા ટેબલમાં ડેટા સ્ટોર કરો જો (isset($) _POST["movie_review_director_name"]) && $_POST["movie_review_director_name"] != "") ( update_post_meta($movie_review_id, "movie_director", $_POST["movie_review_director_name"]);"_POST["movie_review_director_name"]); ]) && $_POST["movie_review_rating"] != "") ( update_post_meta($movie_review_id, "movie_rating", $_POST["movie_review_rating"]); ) ) )
જ્યારે એડમિન પેનલમાં એન્ટ્રીઓ સેવ અથવા ડિલીટ કરવામાં આવે ત્યારે આ ફંક્શન એક્ઝિક્યુટ થાય છે. આ કિસ્સામાં, પરિણામી રેકોર્ડનો પ્રકાર તપાસવામાં આવે છે, અને જો રેકોર્ડ કસ્ટમ છે, તો વધારાના ફીલ્ડ્સમાં કોઈ મૂલ્યો છે કે કેમ તે જોવા માટે ફરીથી તપાસ કરવામાં આવે છે, અને પછી આ મૂલ્યો આ ક્ષેત્રોમાં સંગ્રહિત થાય છે. પગલું 6: માનક કસ્ટમ ફીલ્ડ્સને અક્ષમ કરોકસ્ટમ પોસ્ટ પ્રકાર બનાવતી વખતે, અમે create_movie_review ફંક્શનનો ઉલ્લેખ કર્યો છે. સપોર્ટ એરેમાંથી કસ્ટમ-ફીલ્ડ એલિમેન્ટને દૂર કરો કારણ કે અમને હવે તેની જરૂર રહેશે નહીં. હવે જો તમે ફાઈલ સેવ કરો અને એડિટ પેનલ ઓપન કરો મૂવી સમીક્ષાઓ, તમે વધારાના ક્ષેત્રોમાં બે ક્ષેત્રો જોશો: મૂવી લેખકઅને
મૂવી રેટિંગ
દરેક પ્રકારના વપરાશકર્તા રેકોર્ડ માટે ડેટા પ્રદર્શિત કરવા માટે તેના પોતાના નમૂનાઓનો ઉપયોગ કરવો તે યોગ્ય રહેશે. અમારા કિસ્સામાં, અમે એક નમૂનો બનાવીશું જે બધી મૂવી સમીક્ષાઓ દર્શાવે છે જે કસ્ટમ પોસ્ટ પ્રકારનો ઉપયોગ કરીને ઉમેરવામાં આવી હતી મૂવી સમીક્ષા.
પગલું 1: ટેમ્પલેટ લોન્ચ ફંક્શનની નોંધણી કરો
ફાઈલ ખોલો Movie-Reviews.phpઅને ક્લોઝિંગ ટેગ પહેલા નીચેનો કોડ ઉમેરો. આ કોડ એક ફંક્શન રજીસ્ટર કરે છે જેને વર્ડપ્રેસ એડમિન પેનલની મુલાકાત લેતી વખતે બોલાવવામાં આવશે.
ઉમેરો_ફિલ્ટર("ટેમ્પલેટ_સમાવેશ કરો", "સમાવેશ_ટેમ્પલેટ_ફંક્શન", 1);
પગલું 2: કાર્ય ચલાવો
ફંક્શન include_template_function($template_path) ( if (get_post_type() == "movie_reviews") ( if (is_single()) ( // પહેલા થીમમાં ફાઇલ અસ્તિત્વમાં છે કે કેમ તે તપાસે છે, // અન્યથા પ્લગઇનમાંથી ફાઇલને સર્વ કરો જો ($ theme_file = locate_template(એરે ("single-movie_reviews.php"))) ( $template_path = $theme_file; ) અન્ય ( $template_path = plugin_dir_path(__FILE__) ."/single-movie_reviews.php"; ) ) _ ) )આ વર્તમાન થીમ ફોલ્ડરમાં ટેમ્પલેટ જેવું છે કે કેમ તે તપાસે છે સિંગલ-(પોસ્ટ-ટાઈપ-નામ).php. જો તે ત્યાં ન હોય, તો પછી પ્લગઇન ફોલ્ડરમાં નમૂનાની હાજરી તપાસવામાં આવે છે, જ્યાં અમે પ્લગઇનના ભાગ તરીકે અમારા નમૂનાને મૂકીશું. template_include ઇવેન્ટ હેન્ડલર (હૂક) નો ઉપયોગ પ્રોગ્રામના સામાન્ય એક્ઝેક્યુશનને બદલવા અને ખાસ ટેમ્પલેટને ચલાવવા માટે દબાણ કરવા માટે થાય છે.
પગલું 3: સિંગલ પેજ ટેમ્પલેટ ફાઇલ બનાવો
અગાઉ ખોલેલી ફાઈલને પ્લગઈન વડે સેવ કર્યા પછી, નામની બીજી ફાઈલ બનાવો single-movie_reviews.phpઅને તેમાં નીચેનો કોડ પેસ્ટ કરો.
have_posts()): $loop->the_post();?>
શીર્ષક: દિગ્દર્શક: "; } } ?>
રેટિંગ:
";) બીજું ( પડઘો "આ કિસ્સામાં, અમે લૂપનો ઉપયોગ કરીને મૂળભૂત પૃષ્ઠ ટેમ્પલેટ બનાવ્યું છે. query_posts ફંક્શન કસ્ટમ પોસ્ટ પ્રકારના ઘટકો લે છે અને તેમને લૂપિંગનો ઉપયોગ કરીને પ્રદર્શિત કરે છે. આ અલબત્ત ખૂબ જ સરળ ચક્ર છે, તમે તેને જરૂર મુજબ બદલી શકો છો. તમે દેખાવ બદલવા માટે જરૂરી CSS શૈલીઓનો પણ ઉપયોગ કરી શકો છો.
ધ્યાન
: તમારે બનાવેલ નમૂનાનો ઉપયોગ કરીને નિયંત્રણ પેનલમાંથી એક નવું પૃષ્ઠ બનાવવાની જરૂર છે. પગલું 4: છબીઓ, તમે વધારાના ક્ષેત્રોમાં બે ક્ષેત્રો જોશો: તમારા પ્લગઇન ફોલ્ડરમાં બે 32x32 પિક્સેલ સ્ટાર આઇકન છબીઓ સાચવો. તે મુજબ તેમને નામ આપો icon.png
એક સંપૂર્ણ સ્ટેક ફ્રેમવર્ક જે તમામ માઇક્રો ફ્રેમવર્ક ન હોય તો મોટાભાગના કરતાં વધુ ઝડપી છે. આ ફ્રેમવર્ક નવા નિશાળીયા માટે નથી. તે તમને ટૂલ્સ આપે છે, પરંતુ તેનો અમલ કરવાનું ડેવલપર પર નિર્ભર છે. જો તમને PHP ની સાચી સમજ હોય, અને પ્રદર્શન ચિંતાજનક હોય, તો આગળ ન જુઓ. દસ્તાવેજીકરણ સંપૂર્ણ છે, પરંતુ શિખાઉ લક્ષી નથી, અને સમુદાય કંઈક અંશે છૂટાછવાયા છે, પરંતુ હું કામગીરી પર પૂરતો ભાર આપી શકતો નથી. આ ફ્રેમવર્ક મારી PHP એપ્લિકેશન્સને JAVA એપ્લિકેશન્સ સાથે પ્રદર્શન સ્તર પર મૂકે છે.
મારા દૃષ્ટિકોણથી Phlacon એ બજાર પરનું સૌથી ઝડપી ફ્રેમવર્ક નથી, પરંતુ તે વિવિધ સુવિધાઓ અને સરસ ઘટકો પણ પ્રદાન કરે છે. રેસ્ટફુલ API" અથવા સંપૂર્ણ MVC ફ્રેમવર્ક માટે માઇક્રોફ્રેમવર્ક તરીકે ઉપયોગ કરવા માટે પણ ખૂબ જ સારું છે. C ORM, અને ટ્વિગ ટેમ્પલેટ એન્જિન સાથે આવે છે. સાથે જ હું ખરેખર પ્રશંસા કરું છું કે ફ્રેમવર્ક કેવી રીતે ગતિશીલ છે, તમે જે ઇચ્છો તેનો જ ઉપયોગ કરો, તમે ફક્ત બદલી શકો છો. કસ્ટમ માટેના વર્ગો અને પુસ્તકાલયો અથવા ઇવેન્ટ સાથેના પ્રવાહને અસર કરે છે.
ખૂબ સારું કામ, માત્ર એક જ સમસ્યા સમુદાયની છે પરંતુ હું માનું છું કે તે ખૂબ જ ઝડપથી વધશે :)
ફાલ્કન નિઃશંકપણે ત્યાંના સૌથી ઝડપી ફ્રેમવર્કમાંનું એક છે, અને તે તેનો મજબૂત મુદ્દો છે. બીજી બાજુ, દસ્તાવેજીકરણ થોડું અવ્યવસ્થિત છે, વેબ ટૂલ્સ (કોડ જનરેટર) વિન્ડોઝમાં મુખ્ય સમસ્યાઓ ધરાવે છે, અને તેમાં હજુ પણ થોડો અભાવ છે. નવા વિકાસકર્તાઓને મદદ કરવા માટે વધુ એક સમુદાય પરંતુ ફરી એકવાર, પ્રદર્શન, વાહ.
તમારા ગ્રાહકોને તેમની છાપ મુક્તપણે શેર કરવાની સ્વતંત્રતા આપીને તેમના તરફથી મૂલ્યવાન પ્રતિસાદ મેળવો. તેમને તમારા ઉત્પાદનો અને/અથવા સેવાઓને સીધી તમારી વેબસાઇટ પર રેટ કરવા દો. અમારી ઓનલાઈન રિવ્યૂ સિસ્ટમ સાથે પ્રમાણભૂત આવતા મુખ્ય લક્ષણો નીચે જુઓ.
સમીક્ષાઓ અને રેટિંગ્સ
તમારી વેબસાઇટમાં PHP રિવ્યૂ સ્ક્રિપ્ટ એમ્બેડ કરો અને ગ્રાહકોને તમે ઑફર કરો છો તે ઉત્પાદનો અને સેવાઓ સાથે તેમનો અનુભવ શેર કરવા દો. તેઓ માપદંડ દ્વારા રેટ કરી શકે છે અને હકારાત્મક અને નકારાત્મક બંને પ્રતિસાદ આપી શકે છે.
બહુવિધ ભાષાઓ
PHP રિવ્યૂ સિસ્ટમ માત્ર અંગ્રેજી જ નહીં, પરંતુ તમને જરૂર પડી શકે તેવી કોઈપણ ભાષા બોલી શકે છે. તમે ટેક્સ્ટના દરેક ભાગ માટે અનન્ય ID નો ઉપયોગ કરીને એડમિન પૃષ્ઠમાંથી તમામ શીર્ષકો અને સિસ્ટમ સંદેશાઓનો અનુવાદ કરી શકો છો.
સંપાદનયોગ્ય રેટિંગ માપદંડ
વ્યવસાયના પ્રકાર પર આધાર રાખીને, સિસ્ટમ સંચાલકો સમીક્ષા કરી શકે છે
ફ્રન્ટ-એન્ડ ફોર્મમાં બતાવવા માટે વિવિધ રેટિંગ માપદંડો સેટ કરો.
આમાંના દરેક માપદંડને 1 થી 5 સ્ટાર્સ સાથે રેટ કરવામાં આવે છે.
ઇમેઇલ અને SMS સૂચનાઓ
જ્યારે નવી સમીક્ષા પોસ્ટ કરવામાં આવે ત્યારે ઈમેલ અને SMS ચેતવણીઓ મોકલવા માટે ઓનલાઈન સમીક્ષા સિસ્ટમ સેટ કરો. તમે વપરાશકર્તાઓ મેનૂમાંથી આ સંદેશાઓ કયા વપરાશકર્તાઓને પ્રાપ્ત કરવા તે સરળતાથી સ્પષ્ટ કરી શકો છો.
બહુવિધ વપરાશકર્તા પ્રકારો
ઉદ્યોગ અને ઉપયોગમાં લેવાતી સેવાઓના આધારે અમર્યાદિત ક્લાયંટ પ્રકારો બનાવો. હોટેલ રેટિંગ્સ નીચેના પ્રકારના વપરાશકર્તા સાથે જઈ શકે છે: બાળકો સાથેનું કુટુંબ, યુગલ, વ્યવસાયિક સફર વગેરે. તેઓ સમીક્ષાઓમાં લેબલ તરીકે દેખાય છે.
રિસ્પોન્સિવ અને આકર્ષક
સમીક્ષા અને રેટિંગ સ્ક્રિપ્ટ તમામ ઉપકરણો પર ચાલે છે, વિવિધ સ્ક્રીન માપોને એકીકૃત રીતે સ્વીકારે છે. તમારી વેબસાઇટ બ્રાન્ડિંગ અનુસાર, તમે 10 રંગ વિકલ્પોમાંથી શ્રેષ્ઠ મેચિંગ ફ્રન્ટ-એન્ડ થીમ પસંદ કરી શકો છો.
સમીક્ષા ફોર્મની બાજુમાં એક ઝડપી ટીપ્સ બોક્સ તમને કેટલાક વિનોદી શબ્દો ઉમેરવા અને ગ્રાહકોને આકર્ષિત કરવાની મંજૂરી આપે છે. સમીક્ષા સિસ્ટમ વપરાશકર્તા પ્રકાર દ્વારા સમીક્ષાઓ ફિલ્ટર કરે છે. ગ્રાહકો અન્ય ક્લાયંટના રેટિંગને પણ રેટ કરી શકે છે.
ડેવલપર લાયસન્સ સાથે તમને સોર્સ કોડ મળે છે અને તમે PHP રિવ્યુ સ્ક્રિપ્ટમાં કોઈપણ કસ્ટમ ફેરફારો કરી શકો છો. અમે વિનંતી પર ગ્રાહક સમીક્ષા સિસ્ટમમાં પણ ફેરફાર કરી શકીએ છીએ.
પ્રથમ, કોડ સંસ્થાના દૃષ્ટિકોણથી, સમીક્ષાના તમામ તર્કને એક અથવા વધુ સમાવિષ્ટ ફાઇલોમાં મૂકવું અને પછી તેને ઉત્પાદન પૃષ્ઠો પર શામેલ કરવું વધુ સારું રહેશે:
શામેલ કરો("includes/reviews.php");
આ રીતે, ઉત્પાદન પૃષ્ઠો ભેળસેળ રહિત રહી શકે છે અને સમાન સમીક્ષા કોડનો સરળતાથી ઉપયોગ કરી શકાય છે, અથવા જરૂર મુજબ સુધારી શકાય છે. reviews.php સ્ક્રિપ્ટ ઘણી વસ્તુઓ કરશે:
- સમીક્ષા ફોર્મ બતાવો
- સમીક્ષા ફોર્મ હેન્ડલ કરો
- હાલની સમીક્ષાઓની સૂચિ બનાવો
- ગૌણ ક્રિયાઓને હેન્ડલ કરો, જેમ કે સમીક્ષાઓ અથવા ટિપ્પણીઓને અયોગ્ય તરીકે ફ્લેગ કરવી, જે દર્શાવે છે કે સમીક્ષાઓ મદદરૂપ હતી, સમીક્ષાઓમાં ટિપ્પણીઓ ઉમેરવી, ટિપ્પણીઓ જ્યાં મદદરૂપ થાય છે તે દર્શાવે છે, વગેરે.
આશા છે કે તમે પહેલેથી જ પુષ્કળ વેબ ડેવલપમેન્ટ કર્યું છે, તેથી તમે જાણો છો કે સમીક્ષાઓ ઉમેરવા માટેનું ફોર્મ આના જેવું હશે:
સ્પષ્ટપણે તમે તેને સુંદર બનાવવા માટે કેટલાક CSS નો ઉપયોગ કરવા માંગો છો, પરંતુ તે મૂળભૂત વિચાર છે. મુખ્ય કેચ એ છે કે ઉત્પાદન ID અને ઉત્પાદન પ્રકાર (અથવા આઇટમ સાથે સમીક્ષાને સાંકળવા માટે ડેટાબેઝમાં જે પણ હોવું જોઈએ) છુપાયેલા ઇનપુટ્સમાં સંગ્રહિત હોવું આવશ્યક છે. તમારી પાસે PHP સ્ક્રિપ્ટ હશે જે ઉત્પાદન દર્શાવે છે કે આ મૂલ્યો ઇનપુટ્સ પર લખે છે.
જો લૉગિન જરૂરી હોય, તો તમે (PHP) કોડ ઉમેરી શકો છો જે ફક્ત લૉગ-ઇન થયેલા વપરાશકર્તાઓને જ ફોર્મ બતાવે છે અથવા એવી ટિપ્પણી છાપે છે કે વપરાશકર્તાએ પ્રોડક્ટની સમીક્ષા કરવા માટે લૉગ ઇન કરવું આવશ્યક છે. તેવી જ રીતે, જો તમારી પાસે કોઈ વ્યક્તિ ફક્ત એક જ વાર ઉત્પાદનની સમીક્ષા કરે છે તેની ખાતરી આપવા માટે કોઈ સિસ્ટમ હોય, તો તમારે આ ફોર્મ બતાવતા પહેલા તે દૃશ્ય માટે PHP તપાસ કરવી પડશે.
ફોર્મ સબમિશન શકે છેનવા પૃષ્ઠ પર જાઓ, પરંતુ પછી વપરાશકર્તાને ઉત્પાદન પૃષ્ઠ પર પાછા જવા માટે પાછા બટનને ક્લિક કરવાની જરૂર પડશે, જે આદર્શ નથી. તેના બદલે હું ઉત્પાદન પૃષ્ઠ પર ફોર્મ પરત સબમિટ કરીશ. ઉદાહરણ તરીકે, કોઈપણ ગતિશીલ વેબસાઇટ પર, ચોક્કસ પ્રકારની તમામ સામગ્રી પ્રદર્શિત કરવા માટે સમાન PHP સ્ક્રિપ્ટનો ઉપયોગ કરવામાં આવે છે. મારા માં PHP અને MySQL સાથે પ્રયાસરહિત ઈ-કોમર્સપુસ્તક, પ્રથમ ઉદાહરણ સાઇટ સામગ્રીના કોઈપણ પૃષ્ઠને બતાવવા માટે page.php સ્ક્રિપ્ટનો ઉપયોગ કરે છે. ફોર્મની ક્રિયા વિશેષતા એ જ page.php તરફ નિર્દેશ કરશે. તમે માત્ર વિશેષતા ખાલી છોડીને અથવા ગતિશીલ રીતે મૂલ્ય સેટ કરવા માટે PHP નો ઉપયોગ કરીને આ પરિપૂર્ણ કરી શકો છો.
જો PHP પેજ કે જે ઉત્પાદનોની યાદી આપે છે તે જરૂરી છે કે ઉત્પાદનને ઓળખતું મૂલ્ય URL માં પાસ કરવામાં આવે, તો ફોર્મને તે મૂલ્યને છુપાયેલા ઇનપુટમાં પણ સંગ્રહિત કરવાની જરૂર પડશે. (તે સાઈટ કેવી રીતે સેટ કરવામાં આવે છે તેના આધારે, product_id ઇનપુટ સાથે પહેલેથી જ એવું હોઈ શકે છે.) બીજું, POST દ્વારા ઉત્પાદન મૂલ્ય પ્રાપ્ત કરવા માટે ઉત્પાદન સ્ક્રિપ્ટને પણ અપડેટ કરવાની જરૂર પડશે.
ફોર્મ સબમિશન ક્યારે હેન્ડલ કરવું તે જાણવા માટે reviews.php સ્ક્રિપ્ટ માટે, તે સ્ક્રિપ્ટને કેવી રીતે એક્સેસ કરવામાં આવી તે તપાસી શકે છે:
જો ($_SERVER["REQUEST_METHOD"] == "પોસ્ટ") ( // ફોર્મ હેન્ડલ કરો.
જ્યારે સમીક્ષા ફોર્મ સબમિટ કરવામાં આવે છે, ત્યારે ફોર્મનો ડેટા માન્ય હોવો જોઈએ. તમારે ક્રોસ-સાઇટ સ્ક્રિપ્ટીંગ (XSS) હુમલાઓ અથવા અન્ય ખરાબ વર્તનને રોકવા માટે ડેટા પર strip_tags() પણ લાગુ કરવું જોઈએ. અને બિન-સંખ્યાત્મક મૂલ્યો એસ્કેપિંગ ફંક્શન દ્વારા ચલાવવામાં આવશે, જેમ કે mysqli_real_escape_string() . અથવા તમે બહેતર સુરક્ષા અને પ્રદર્શન માટે તૈયાર નિવેદનો અથવા સંગ્રહિત પ્રક્રિયાઓનો ઉપયોગ કરી શકો છો.
જો તમે ફોર્મના એક્શન એટ્રિબ્યુટ action="page.php#reviews"માં એન્કર ઉમેરો છો, તો સબમિશન પર વપરાશકર્તાને પૃષ્ઠના સમીક્ષા વિભાગમાં લઈ જવામાં આવશે, જે એક સરસ સ્પર્શ છે.
જો reviews.php સ્ક્રિપ્ટ અન્ય કેટલીક અયોગ્ય સમીક્ષાઓ અથવા ટિપ્પણીઓ, મદદરૂપ સૂચકો વગેરેને પણ સંભાળી રહી હોય તો સ્ક્રિપ્ટને તે સબમિશન્સ માટે પણ જોવાની જરૂર પડશે. કઈ કાર્યવાહી કરવામાં આવી રહી છે તે દર્શાવવા માટે હું "કાર્ય" નામના છુપાયેલા ઇનપુટ્સનો ઉપયોગ કરીશ.
એક અલગ લેખમાં, હું એક સરળ રેટિંગ સિસ્ટમ માટે Ajax નો ઉપયોગ કેવી રીતે કરવો તે દર્શાવું છું. સમાન એજેક્સ કોડનો ઉપયોગ સમીક્ષા સિસ્ટમ માટે પણ થઈ શકે છે.