WordPress Custom Post Type Template

WordPress Custom Post Type Template – जब हम Custom Post Type Create करते हैं, तब यदि हम हमारी functions.php नाम की File में has_archive Value को “true” Value Set कर देते हैं, यानी यदि हम हमारे functions.php File के Code को निम्नानुसार Modify करते हुए उसमें has_archive Option को Set देते हैं:

// File Name: /wp-content/themes/bccfalna/functions.php
<?php  
    add_action( 'init', 'cpt_newsletter' );
    function cpt_newsletter(){
        register_post_type( 
            'newsletter', 
            array(
                'labels' => array('name' => __( 'Newsletter' ),'singular_name' => __( 'Newsletter' )),
                'public' => true,
                'supports' => array('title','editor'),
                'query_var' => true,
                'has_archive' => true
            )
        );
    }
?>

तो अब यदि हम Web Browser के Addressbar में निम्न URL Use करते हैं:

      http://localhost/wp/newsletter/

तो WordPress Automatically इस URL के लिए Currently Activated Theme में सबसे पहले archive-newsletter.php नाम के Template को Search करता है और यदि इस नाम का Template Exist होता है, तो WordPress सबसे पहले “newsletter” Type के सभी Posts के Archive को Render करने के लिए इसी Custom Post Type Template को Use करता है।

लेकिन यदि इस नाम का Template Exist न हो, तो WordPress Automatically archive.php नाम के Template को Use करते हुए newsletter Custom Post Type के सभी Posts की Listing कर देता है।

यानी यदि हमारी Currently Activated bccfalna नाम की Theme में archive-newsletter.php नाम के Template में निम्नानुसार Code लिखे हों-

// File Name: /wp-content/themes/bccfalna/archive-newsletter.php
<h1>Newsletter Custom Post Type</h1>
<p>This is the archive-newsletter.php template.</p>

तो उपरोक्त URL को Web Browser द्वारा Render करने पर हमें निम्नानुसार Output Web Page प्राप्त होगा-

WordPress Custom Post Type Template - Hindi

इस Webpage के दिखाई देने का मतलब यही है कि newsletter नाम के Custom Post Type का Archive Render हो रहा है।

WordPress के इस Custom Post Type Template Selection की प्रक्रिया को हम निम्न चित्रानुसार ज्यादा बेहतर तरीके से समझ सकते हैं:

WordPress Custom Post Type Template - Hindi

WordPress हमें उपरोक्त तरीके से उसी स्थिति में Custom Post Type के Posts की Archive को Render करता है, जबकि हमने अपनी functions.php File में “has_archive” नाम की Property को “true” Value से Set किया हो।

यदि हम इस Property को “true” Set करते हैं और अपनी Currently Activated Theme में archive-newsletter.php नाम का Template भी Create करते हैं, तो निम्नानुसार URL के माध्‍यम से सभी Custom Post Type Posts के Archive List को Render करते समय WordPress सबसे पहले archive-newsletter.php नाम के Template को Use करेगा।

लेकिन यदि हमने has_archive Property को “true” Set करने के बावजूद archive-newsletter.php नाम के Template को Create नहीं किया है, तो WordPress Custom Post Type के Post की Archive को Render करने के लिए archive.php Template को Use कर लेता है।

यदि archive.php नाम का Template भी Exist न हो, तो Paged Listing होने की स्थिति में WordPress paged.php Template को Use कर लेता है जबकि Paged Listing न होने पर WordPress index.php नाम के Default Template को Use करते हुए newsletter Custom Post Type के Posts के Archive की Listing कर देता है।

WordPress in Hindi - BccFalna.comये Article इस वेबसाईट पर Selling हेतु उपलब्‍ध EBook Advance WordPress in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी है, तो निश्चित रूप से ये EBook भी आपके लिए काफी उपयोगी साबित होगी।

Advance WordPress in Hindi | Page: 835 | Format: PDF

BUY NOW GET DEMO REVIEWS