PHP WordPress Development
In this page:
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
// 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";
?>
Login to try C/C++/Java/PHP code in the editor
WordPress Hooks
Hooks WordPress का extension mechanism हैं: actions आपके code को request lifecycle में एक specific point पर चलने देते हैं, जबकि filters आपको data को WordPress के इस्तेमाल या display करने से पहले intercept और modify करने देते हैं।
उदाहरण: WordPress Hooks
<?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";
?>
Login to try C/C++/Java/PHP code in the editor
The Loop
Loop वह standard block of code है जिसे हर WordPress theme posts की एक list fetch और display करने के लिए इस्तेमाल करता है, query results में iterate करते हुए और theme के markup के हिसाब से हर एक को render करते हुए।
उदाहरण: The Loop
<?php
// while (have_posts()) { the_post(); the_title(); }
echo "The Loop iterates through queried posts and renders each one";
?>
Login to try C/C++/Java/PHP code in the editor
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
// register_post_type('product', ['public' => true]);
echo "Extends WordPress beyond posts and pages with its own admin screens";
?>
Login to try C/C++/Java/PHP code in the editor
Shortcodes
Shortcodes content editors को page editor के अंदर से [gallery] जैसा एक bracketed tag type करके PHP functionality trigger करने देते हैं, बिना किसी template file को directly touch किए।
उदाहरण: Shortcodes
<?php
// add_shortcode('gallery', 'render_gallery_shortcode');
echo "Editors type [gallery] to trigger PHP functionality from the editor";
?>
Login to try C/C++/Java/PHP code in the editor
- WordPress core files edit करना, जो update पर overwrite हो जाती हैं; hooks या एक child theme इस्तेमाल करें।
- सही hook name के साथ
add_actionयाadd_filterइस्तेमाल करना भूल जाना। - एक
WP_Queryloop इस्तेमाल करना और बाद मेंwp_reset_postdata()भूल जाना।
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: