រចនា​ទំព័រ​ស្វែង​រក


នៅ​ពេលដែលយើង​សរសេរ​ពាក្យ​ស្វែង​រកការផ្សាយ​ណាមួយ លទ្ធផល​នៃការស្វែង​រក​នឹង​ត្រូវ​បង្ហាញ​នៅ​លើទំព័រ​ពិសេស​ម៉្យាង​ ដែល​យើង​អាច​ហៅ​ជា​ភាសា​ខ្មែរ​ថា «ទំព័រ​ស្វែងរក» ។ ហើយ​ដើម្បី​រចនា​ទំព័រ​ស្វែង​រក​អោយ​មាន​រូបរាង​ទៅ​តាមការចង់​បាន​របស់​យើង ជា​ដំបូង​យើងត្រូវ​បើក​ឯកសារ​ឈ្មោះ search.php និងសរសេរកូដ​មួយ​ចំនួន​នៅ​ក្នុង​ឯកសារ​នោះ ដូច​ខាង​ក្រោម​នេះ៖
<?php
/**
 * The template for displaying search results pages
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
 *
 * @package Lotus_Blue
 */

get_header();
?>


<?php
if(!wp_is_mobile()){
  get_template_part( 'template-parts/home', 'ad' );
}
?>

<?php if ( have_posts() ) : ?> <?php /* Start the Loop */ while ( have_posts() ) : the_post(); /** * Run the loop for the search to output the results. * If you want to overload this in a child theme then include a file * called content-search.php and that will be used instead. */ get_template_part( 'template-parts/content', 'search' ); endwhile; the_posts_navigation(); else : get_template_part( 'template-parts/content', 'none' ); endif; ?>
<?php get_sidebar(); get_footer();

បន្ទាប់មកទៀត យើងចាំ​បាច់​ត្រូវ​បើក​ឯកសារ​មានឈ្មោះថា content-search.php នៅ​ក្នុង​ថត​ template-parts រួច​សរសេរ​កូដ​មួយ​ចំនួន​ដូច​ខាង​ក្រោម​នេះ៖
<?php
/**
 * Template part for displaying results in search pages
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Lotus_Blue
 */

?>



<article id="post-" <?php post_class(); ?>>
  
<?php the_title( sprintf( '

', esc_url( get_permalink() ) ), '

' ); ?> <?php if ( 'post' === get_post_type() ) : ?> <?php endif; ?>
</article>