programing

WooCommerce 검색 결과 템플릿

muds 2023. 3. 22. 22:17
반응형

WooCommerce 검색 결과 템플릿

저는 WooCommerce WordPress 사이트에서 일하고 있습니다.제품에 대한 WooCommerce 검색 기능을 추가했습니다.그러나 메인 숍 페이지와 검색 결과 페이지 모두 동일한 템플릿 archive-product.php를 가지고 있습니다.하지만 두 페이지 모두 별도의 디자인을 원합니다.내가 어떻게 그럴 수 있을까?

@arun이 코멘트에서 말한 것처럼 archive-product.php를 복사하여 테마 내의 woocommerce 폴더에 붙여넣습니다(이 폴더가 없는 경우 작성하십시오).

파일을 열고 php if 문을 사용하여 파일 내의 콘텐츠를 분할합니다.

if ( is_search() ) {
    //put your search results markup here (you can copy some code from archive-product.php file and also from content-product.php to create a standard markup
} else {
    // here goes the content that is already in that file (archive-product.php) 
}

이 코드 행은 항상 파일 맨 위에 있어야 합니다.

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

@Capital Themes 답변에 따라 함수를 반전하여 검색 이외의 폼 카테고리에 코드를 추가할 수 있습니다.

<?php   if (! is_search() ) {
//Added code for non search form
} else {
// if want something only for search
}   ?>

woocommerce/directore에서 product-searchform.directore 파일을 사용해야 합니다.

검색 페이지를 woocomerce/woocomerce/global directore의 루프 파일로 커스터마이즈합니다.

그 후 is_search() 메서드를 사용하여 검색 페이지에 있는지 여부를 확인할 수 있습니다.

언급URL : https://stackoverflow.com/questions/23490317/woocommerce-search-result-template

반응형