Attachment Template – जब हम हमारी WordPress Website या Blog में किसी Media File (Audio, Video, Application, etc…) को Upload करते हैं, तो इस File को भी WordPress द्वारा Web Browser में Render करने के लिए पूरी एक Template Hierarchy को Follow किया जाता है और हमारी Theme में हम किसी Specific MIME Type के लिए जिस Template को उपयोग में लेना चाहते हैं, उस Template का नाम mime_type.php Format में Specify कर सकते हैं।
Internet पर कई प्रकार के Documents व Media होते हैं और इन सभी प्रकार के Media Types की Detailed Information को http://en.wikipedia.org/wiki/Internet_media_type से प्राप्त किया जा सकता है। हालांकि इन सभी में से बहुत कम Media Types ऐसे हैं, जिन्हें बहुत ज्यादा उपयोग में लिया जाता है।
विभिन्न प्रकार के Media Types को अलग-अलग तरह से Render या Treat करने के लिए हम अलग-अलग Media Template Create कर सकते हैं। जैसे image_gif.php Template को WordPress द्वारा केवल GIF Type की Image Files के लिए Use किया जाएगा जबकि image_png.php Template को WordPress द्वारा केवल PNG Type की Image Files के लिए Use किया जाएगा। जबकि यदि हम सभी प्रकार की Image Files के लिए एक Single Template Create करना चाहें, तो हमारे Template का नाम image.php होगा।
इसी तरह से विभिन्न Format के Audio, Video तथा Application Files के लिए audio.php, video.php या application.php नाम का Template बनाया जा सकता है, जिन्हें क्रमश% सभी प्रकार की Audio Files, Video Files व Application Files (JavaScript, PDF Files, etc…) को Render करते समय WordPress द्वारा Use किया जाएगा।
जबकि autio_mp3.php नाम के Template को WordPress द्वारा केवल MP3 Type की Audio Files के fy, Use किया जाएगा व video_avi.php नाम के Template को WordPress द्वारा केवल AVI Type की Video Files के लिए ही Use किया जाएगा। इसी तरह से हम किसी भी प्रकार के MIME Type के लिए एक अलग Template File को Design कर सकते हैं।
जब WordPress किसी Attachment Post यानी जिस Post में कोई ऐसा MIME Type का File हो, जिसे WordPress Dashboard => Media द्वारा Upload किया गया हो, को WordPress में Render करने के लिए Define करना चाहता है, तब वह सबसे पहले mimetype.php नाम के Template को Search करता है और यदि Currently Activated Theme में mimetype.php Template Exist हो, तो WordPress सबसे पहले इसी Template File के आधार पर Attachment Post को Display करता है।
लेकिन यदि Currently Active Theme में mimetype.php Template Exist न हो, तो WordPress Attachment Post को Display करने के लिए subtype.php Template को Search करता है।
कुछ या ज्यादातर MIME Types दो हिस्सों में Divide होते हैं, जो कि Type व Subtype को Represent करते हैं और इनके बीच सामान्यत: एक Slash Symbol होता है। जैसे:
“text/css”” //text is MIME Type and css is MIME Subtype
“audio/mp3” //audio is MIME Type and mp3 is MIME Subtype
इसलिए यदि Currently Active Theme में WordPress में mimetype.php Template प्राप्त नहीं होताए तो उस स्थिति में WordPress subtype.php नाम के Template को Search करता है और इस Template के Theme में उपलब्ध होने पर WordPress subtype.php Template को Execute करके Current Attachment को Render करता है।
लेकिन subtype.php Template File भी Currently Activated Theme में Exist न हो, तो WordPress mimetype_subtype.php Template को Search करता है और उपलब्ध होने पर इसे Use करते हुए Attachment Post को Render करता है।
जबकि यदि mimetype_subtype.php Template File भी Currently Activated Theme में Exist न हो, तो WordPress single-attachment.php Template को Search करता है और उपलब्ध होने पर इसे Use करते हुए Attachment Post को Render करता है।
यदि single-attachment.php Template File भी Currently Activated Theme में Exist न हो, तो WordPress attachment.php Template को Search करता है और उपलब्ध होने पर इसे Use करते हुए Attachment Post को Render करता है।
यदि attachment.php Template File भी Currently Activated Theme में Exist न हो, तो WordPress single.php Template को Search करता है और उपलब्ध होने पर इसे Use करते हुए Attachment Post को Render करता है।
और यदि single.php Template File भी Currently Activated Theme में Exist न हो, तो WordPress Default index.php Template को Use करते हुए Attachment Post को Render कर देता है।
WordPress की Attachments के लिए Template Selection की पूरी प्रक्रिया को हम निम्नानुसार भी समझ सकते हैं:
For Attachment Posts: IF mimetype.php Exists Then Run mimetype.php ELSE IF mimetype.php NOT EXISTS Then Run subtype.php ELSE IF mimetype.php & subtype.php Both NOT EXISTS Then Run mimetype_subtype.php ELSE IF mimetype.php, subtype.php & mimetype_subtype.php all three NOT EXISTS Then Run single-attachment.php ELSE IF mimetype.php, subtype.php, mimetype_subtype.php & single-attachment.php all four NOT EXISTS Then Run single.php ELSE Run index.php
यदि एक उदाहरण द्वारा इस पूरी प्रक्रिया को समझने की कोशिश करें, तो मानलो कि हमने किसी PNG Image को WordPress Dashboard => Media द्वारा Upload किया। अब यदि इस Uploaded Image को Web Browser में देखने के लिए Web Server पर Request Perform किया जाए, तो WordPress इस Image को Web Browser में Response के रूप में Return करने के लिए सबसे पहले
- Currently Activated Theme में php नाम के Template को Use करेगा।
- यदि php Template Exist नहीं होगा, तो WordPress png.php नाम के Template को Use करते हुए Image को Display करेगा।
- यदि php Template Exist नहीं होगा, तो WordPress image_png.php नाम के Template को Use करते हुए Image को Display करेगा।
- यदि php Template Exist नहीं होगा, तो WordPress attachment.php नाम के Template को Use करते हुए Image को Display करेगा।
- यदि php Template Exist नहीं होगा, तो WordPress single-attachment.php नाम के Template को Use करते हुए Image को Display करेगा।
- यदि single-attachment.php Template Exist नहीं होगा, तो WordPress php नाम के Template को Use करते हुए Image को Display करेगा। और
- यदि php Template भी Exist नहीं होगा, तो WordPress Default रूप से index.php नाम के Template को Use करते हुए Image को Display कर देगा।
चलिए, एक उदाहरण द्वारा इस पूरी प्रक्रिया को समझने की कोशिश करते हैं। लेकिन सबसे पहले हम निम्नानुसार WordPress Dashboard => Media द्वारा एक JPEG Image Upload करते हैं:

मानलो कि इस Image का Attachment URL http://localhost/wp/?attachment_id=32 है। इसलिए यदि हम इस ULR को Web Browser के Addressbar में Use करें, तो हमें निम्न चित्रानुसार Output दिखाई देता है:

हम देख सकते हैं कि इस Attachment Post को Render करने के लिए हमारी Theme का single.php Template Use हो रहा है, क्योंकि हमारी Theme में किसी MIME Type के Attachment Post को अलग तरीके से Render करने के लिए कोई भी Special Template नहीं है।
अब हम हमारे bccfalna नाम के Currently Activated Theme में निम्नानुसार attachment.php नाम का एक Template Create करते हैं:
File Name: /wp-content/themes/bccfalna/attachment.php
<h1> Attachment Post</h1>
<p>This is from the attachment.php Template and it is useful for displaying a Particular Attachment File.</p>
इस Template File को Create करने के बाद यदि हम फिर से अपने पिछले Attachment URL को ही Web Browser द्वारा Load करें, तो इस बार उसी Attachment के लिए attachment.php Template Use होता है और हमें Resultant Output निम्न चित्रानुसार प्राप्त होता है:

ऐसा इसीलिए हो रहा है क्योंकि जब WordPress इस Attachment को Render करने के लिए Best Appropriate Template की Searching करना शुरू करता है, तो उसे attachment.php नाम का Template प्राप्त हो जाता है। परिणामस्वरूप इस बार हमें उपरोक्तानुसार Output प्राप्त होता है।
इसी तरह से यदि हम हमारे bccfalna नाम के Currently Activated Theme में निम्नानुसार jpeg.php नाम का एक Template Create करते हैं:
File Name: /wp-content/themes/bccfalna/jpeg.php
<h1> Attachment Post for JPEG Images</h1>
<p>This is from the jpeg.php Template and it is useful for displaying only JPEG Type Image Files.</p>
इस Template File को Create करने के बाद यदि हम फिर से अपने पिछले Attachment URL को Web Browser में Load करें, तो इस बार उसी Attachment के लिए jpeg.php Template Use होता है और हमें Resultant Output निम्न चित्रानुसार प्राप्त होता है:

ऐसा इसलिए होता है क्योंकि जब WordPress इस Attachment को Render करने के लिए इस बार Best Appropriate Template की Searching करना शुरू करता है, तो उसे jpeg.php नाम का Template प्राप्त हो जाता है। परिणामस्वरूप इस बार हमें उपरोक्तानुसार Output प्राप्त होता है।
जब हम इस Template को Specify करते हैं, तो ये Template केवल JEPG Type की Mages के लिए ही Use होता है। जबकि यदि हम सभी प्रकार की Images के लिए किसी Template को क्मपिदम करना चाहें तो हम हमारे bccfalna नाम के Currently Activated Theme में निम्नानुसार image.php नाम का एक Template Create कर सकते हैं:
File Name: /wp-content/themes/bccfalna/image.php
<h1> Attachment Post for Image Files</h1>
<p>This is from the image.php Template and it is useful for displaying only All Type Image Files.</p>
इस Template File को Create करके जब हम फिर से अपने पिछले Attachment URL को Web Browser में Load करते हैं, तो इस बार उसी Attachment के लिए image.php Template Use होता है और हमें Resultant Output निम्न चित्रानुसार प्राप्त होता है:

इस प्रकार से हम समझ सकते हैं कि WordPress किस प्रकार से Particular Template की Existence के आधार पर किसी Specific MIME Type के Attachment Post के लिए अलग-अलग Output Generate करता है।
WordPress द्वारा Page Template के Selection की प्रक्रिया को हम हमारे चित्र के निम्न हिस्से द्वारा बेहतर तरीके से समझ सकते हैं:

ये Article इस वेबसाईट पर Selling हेतु उपलब्ध EBook Advance WordPress in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी है, तो निश्चित रूप से ये EBook भी आपके लिए काफी उपयोगी साबित होगी।
Advance WordPress in Hindi | Page: 835 | Format: PDF