گاهی برای شما لازم می شود تا کد خاصی را فقط در صفحه خانه وردپرس لود کنید برای تشخیص صفحه اصلی از کد زیر استفاده کنید: if ( is_front_page() ) : get_header( 'front' ); else : get_header(); endif; is_front_page() /* is_front_page() returns true if the user is on the page or page of posts that is set to the front page on Settings->Reading->Your homepage displays. */ is_home() /* is_home() return true when on the posts list page, This is usually the page that shows the latest 10 posts. */ is_home()
ادامه مطلبدوشنبه, 04 مهر 1401
آموزش برنامه نویسی وردپرس
تشخیص وجود تصویر شاخص کوچک در وردپرس
برای تشخیص وجود تصویر شاخص کوچک در وردپرس از روش زیر استفاده کنید: <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } else { ?> <img src="/<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" /> <?php } ?>
ادامه مطلبدوشنبه, 04 مهر 1401
آموزش برنامه نویسی وردپرس
تشخیص مدیر بودن یک کاربر در وردپرس
برای تشخیص مدیر بودن یک کاربر در وردپرس باید از روش زیر استفاده کنید: <?php if(current_user_can('editor')) { ?> <!-- Stuff here for editors --> <?php } ?> <?php if(current_user_can('administrator')) { ?> <!-- Stuff here for administrators --> <?php } ?>
ادامه مطلبدوشنبه, 04 مهر 1401
آموزش برنامه نویسی وردپرس
بدست آورد کلاس html در وردپرس
برای این کار می توانید کد زیر را در هدر سایت بگذارید: <body <?php body_class(); ?>> <!-- This adds the wordpress body classes markup that you can use for CSS configuration -->
ادامه مطلبدوشنبه, 04 مهر 1401
آموزش برنامه نویسی وردپرس
چگونه فایل functions.php را بشکنیم و سبک تر کنیم در وردپرس
شما می توانید یک پوشه درست کرده و هر بخش از فایل functions.php را درون آن قرار دهید و در فایل functions.php آنها را صدا بزنید: <?php /* * functions.php * */ require_once( __DIR__ . '/includes/null-meta-compare.php'); require_once( __DIR__ . '/includes/older-examples.php'); require_once( __DIR__ . '/includes/wp-admin-menu-classes.php'); require_once( __DIR__ . '/includes/admin-menu-function-examples.php'); // WA: Adding a Taxonomy Filter to Admin List for a Custom Post Type? // http://wordpress.stackexchange.com/questions/578/ require_once( __DIR__ . '/includes/cpt-filtering-in-admin.php'); require_once( __DIR__ . '/includes/category-fields.php'); require_once( __DIR__ . '/includes/post-list-shortcode.php'); require_once( __DIR__ . '/includes/car-type-urls.php'); require_once( __DIR__ . '/includes/buffer-all.php'); require_once( __DIR__ . '/includes/get-page-selector.php'); // http://wordpress.stackexchange.com/questions/907/ require_once( __DIR__ . '/includes/top-5-posts-per-category.php'); // http://wordpress.stackexchange.com/questions/951/ require_once( __DIR__ . '/includes/alternate-category-metabox.php'); // http://lists.automattic.com/pipermail/wp-hackers/2010-August/034384.html require_once( __DIR__ . '/includes/remove-status.php'); // http://wordpress.stackexchange.com/questions/1027/removing-the-your-backup-folder-might-be-visible-to-the-public-message-generate require_once( __DIR__ . '/includes/301-redirects.php');
ادامه مطلبدوشنبه, 04 مهر 1401
آموزش برنامه نویسی وردپرس
نحوه نمایش مسیر سایت در تم یا قالب به صورت برنامه ریزی شده در وردپرس
برای نمایش مسیر سایت در تم یا قالب به صورت برنامه ریزی شده در وردپرس از روش زیر استفاده کنید: add_filter( 'the_content', function( $content ) { if( function_exists( 'rank_math_get_breadcrumbs' ) ) { $content = rank_math_get_breadcrumbs() . $content; } return $content; });
ادامه مطلبدوشنبه, 04 مهر 1401
آموزش برنامه نویسی وردپرس
بدست آوردن تاریخ امروز در وردپرس
برای بدست آوردن تاریخ امروز در وردپرس از روش زیر استفاده کنید: <?php echo get_the_date( 'l F j, Y' ); ?>
ادامه مطلبدوشنبه, 04 مهر 1401
آموزش برنامه نویسی وردپرس
بدست آوردن نام کاربری یک کاربر در وردپرس
برای بدست آوردن نام کاربری یک کاربر در وردپرس از روش زیر استفاده کنید: $current_user = wp_get_current_user(); echo($current_user->user_login); $current_user_id = get_current_user_id(); $current_user = wp_get_current_user();
ادامه مطلبدوشنبه, 04 مهر 1401
آموزش برنامه نویسی وردپرس
بدست آوردن ادرس اواتار یک کاربر در وردپرس
برای پیدا کردن مسیر تصویر اواتار یک کارب می توانید از کد زیر استفاده کنید: get_avatar_url($user_id);
ادامه مطلبدوشنبه, 04 مهر 1401
آموزش برنامه نویسی وردپرس
بدست اوردن اطلاعات یک کاربر از روی ایمیل در وردپرس
شما می توانید از روی ایمیل یک کاربر اطلاعات او را بدست آوردید برای این کار می توانید از روش زیر اقدام کنید: global $current_user; get_currentuserinfo(); echo $current_user->user_email; $user_obj = get_user_by('id', 1); $user = get_user_by( 'email', 'user@example.com' ); $userId = $user->ID;
ادامه مطلبدوشنبه, 04 مهر 1401
آموزش برنامه نویسی وردپرس
بدست آوردن اطلاعات یک کاربر در وردپرس براساس شناسه کاربری
برای بدست آوردن اطلاعات یک کاربر در وردپرس براساس شناسه کاربری از روش زیر می توانید استفاده کنید: <?php $user_id = get_current_user_id(); ?> $current_user = wp_get_current_user(); echo($current_user->user_login); echo get_the_ID(); function get_the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid $post = get_post(); return ! empty( $post ) ? $post->ID : false; } $user_obj = get_user_by('id', 1); $user = get_user_by( 'email', 'user@example.com' ); $userId = $user->ID;
ادامه مطلبدوشنبه, 04 مهر 1401
آموزش برنامه نویسی وردپرس
افزودن آدرس پوشه قالب به یک تصویر
برای اینکه یک تصویر در قالب نمایش داده شود باید ادرس پوشه قالب قبل از ادرس تصویر صدا زده شود: // Get template directory example: <img src="/<?php echo get_template_directory_uri(); ?>/images/logo.png" /> // If you use child theme you will have to use another function: <img src="/<?php echo get_stylesheet_directory_uri(); ?>/images/logo.png" /> <img src="/<?php echo get_template_directory_uri(); ?>/images/logo.png"> include( get_template_directory_uri() . '/includes/my_file.php' ); add_action('wp_enqueue_scripts', 'wpdocs_scripts_method'); /* * Enqueue a script with the correct path. */ function wpdocs_scripts_method() { wp_enqueue_script( 'custom_script', get_template_directory_uri() . '/js/custom_script.js', array('jquery') ); }
ادامه مطلبدوشنبه, 04 مهر 1401
آموزش برنامه نویسی وردپرس
وردپرس پیوند ثابت کوتاه را دریافت کنید
برای بدست اوردن لینک کوتاه یک مطلب از دستور های زیر استفاده کنید: // Get post permalink (you can use it inside a wp_query loop) <?php the_permalink(); ?> // or <?php $link = get_the_permalink(); ?> // outside the loop: <?php echo get_permalink( $post->ID ); ?> // Get shortlink (short permalink) <?php echo wp_get_shortlink(); ?>
ادامه مطلبدوشنبه, 04 مهر 1401
آموزش برنامه نویسی وردپرس
وردپرس آدرس اصلی را دریافت کنید
برای بدست اوردن ادرس اصلی سایت در وردپرس از این کد php استفاده کنید. <?php echo get_site_url(); ?> کاربرد این دستور در صدا زدن لینک هایی است که به صفحه اصلی سایت مربوط می شود مثل لینک بر روی تصویر لوگو
ادامه مطلب