← Back to PHP Course | Chapter 15: Web Development | Lesson 4 of 12

PHP WordPress Development

WordPress बिना सब कुछ खुद लिखे websites बनाने के लिए एक popular tool है, और यह PHP से बना है। Developers इसे कैसा दिखना और काम करना चाहिए यह बदलने के लिए अपनी themes और plugins add कर सकते हैं।
Syntax
php
add_action("hook_name", "callback_function");
add_filter("hook_name", "callback_function");

if (have_posts()) {
    while (have_posts()) {
        the_post();   // The Loop
    }
}

add_shortcode("tag_name", "callback_function");

WordPress क्या है?

WordPress एक PHP-based content management system है जो web के एक बड़े हिस्से को power देता है, non-developers को content manage करने का एक तरीका देते हुए साथ ही custom development के लिए एक पूरा PHP API expose करते हुए।

उदाहरण: What is WordPress?

php
<?php
// Print "WordPress: a PHP-based CMS with a full API for custom development" to the output
echo "WordPress: a PHP-based CMS with a full API for custom development";
?>

WordPress Hooks

Hooks WordPress का extension mechanism हैं: actions आपके code को request lifecycle में एक specific point पर चलने देते हैं, जबकि filters आपको data को WordPress के इस्तेमाल या display करने से पहले intercept और modify करने देते हैं।

उदाहरण: WordPress Hooks

php
<?php
// add_action('init', 'my_custom_function');
// add_filter('the_content', 'modify_content');
echo "Actions run code at a point in the lifecycle; filters modify data";
?>

The Loop

Loop वह standard block of code है जिसे हर WordPress theme posts की एक list fetch और display करने के लिए इस्तेमाल करता है, query results में iterate करते हुए और theme के markup के हिसाब से हर एक को render करते हुए।

उदाहरण: The Loop

php
<?php
// while (have_posts()) { the_post(); the_title(); }
echo "The Loop iterates through queried posts and renders each one";
?>

Custom Post Types

Custom Post Types आपको WordPress को blog posts और pages से आगे extend करने देते हैं -- products या reviews जैसे structures define करना जिन्हें अपनी admin screens मिलती हैं और उन्हें built-in content जैसे ही query किया जा सकता है।

उदाहरण: Custom Post Types

php
<?php
// register_post_type('product', ['public' => true]);
echo "Extends WordPress beyond posts and pages with its own admin screens";
?>

Shortcodes

Shortcodes content editors को page editor के अंदर से [gallery] जैसा एक bracketed tag type करके PHP functionality trigger करने देते हैं, बिना किसी template file को directly touch किए।

उदाहरण: Shortcodes

php
<?php
// add_shortcode('gallery', 'render_gallery_shortcode');
echo "Editors type [gallery] to trigger PHP functionality from the editor";
?>
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. WordPress core files edit करना, जो update पर overwrite हो जाती हैं; hooks या एक child theme इस्तेमाल करें।
  2. सही hook name के साथ add_action या add_filter इस्तेमाल करना भूल जाना।
  3. एक WP_Query loop इस्तेमाल करना और बाद में wp_reset_postdata() भूल जाना।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.