2013-11-21 3 views
0

woocommerce를 비 woocommerce 테마에 통합하려고합니다. 하나의 문제를 제외하고는 괜찮습니다.Woocommerce wordpress functions.php - div에 PHP 추가

내 테마에는 콘텐츠를 숨기고 패딩을 추가하는 block이라는 div가 있습니다. 나는 이것도 woocommerce 페이지에 있기를 원한다.

사업부는 내 함수 PHP에이를 넣어 노력이 http://docs.woothemes.com/document/third-party-custom-theme-compatibility/

사용이

<div id="block" <?php 
    if ($detect->isMobile()) {if($detect->isTablet()){ 
    /* Tab */ 
    if (get_field("search_override_header_position", "options") && get_field("search_tablet_header_position", "options")) {echo 'data-header-position="'.get_field("search_tablet_header_position", "options").'"';} else {echo 'data-header-position="'.$tablet_header_position.'"';}; 
} else { 
    /* Mob */ } 
    if (get_field("search_override_header_position", "options") && get_field("search_mobile_header_position", "options")) {echo 'data-header-position="'.get_field("search_mobile_header_position", "options").'"';} else {echo 'data-header-position="'.$mobile_header_position.'"';}; 
} else { 
    /* Desc */ 
    if (get_field("search_override_header_position", "options") && get_field("search_header_position", "options")) {echo 'data-header-position="'.get_field("search_header_position", "options").'"';} else {echo 'data-header-position="'.$header_position.'"';}; 
} 
?>>&nbsp;</div> 

처럼 내가 얻을 수있는 모든 구문 오류의 흰색 페이지와 많이입니다

remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10); 
remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10); 

add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10); 
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10); 
' 
function my_theme_wrapper_start() { 
    echo ' 

    <div id="block" <?php 
     if ($detect->isMobile()) {if($detect->isTablet()){ 
     /* Tab */ 
     if (get_field("search_override_header_position", "options") && get_field("search_tablet_header_position", "options")) {echo 'data-header-position="'.get_field("search_tablet_header_position", "options").'"';} else {echo 'data-header-position="'.$tablet_header_position.'"';}; 
    } else { 
     /* Mob */ } 
     if (get_field("search_override_header_position", "options") && get_field("search_mobile_header_position", "options")) {echo 'data-header-position="'.get_field("search_mobile_header_position", "options").'"';} else {echo 'data-header-position="'.$mobile_header_position.'"';}; 
    } else { 
     /* Desc */ 
     if (get_field("search_override_header_position", "options") && get_field("search_header_position", "options")) {echo 'data-header-position="'.get_field("search_header_position", "options").'"';} else {echo 'data-header-position="'.$header_position.'"';}; 
    } 
    ?>>&nbsp;</div><section id="main">'; 
} 

function my_theme_wrapper_end() { 
    echo '</section>'; 
} 

답변

0

이스케이프 처리되지 않은 문자열에서 작은 따옴표를 사용하고 있기 때문에 게시 한 코드에 구문 오류가 있습니다. 이 코드는 출력 코드가 나중에 PHP 프로세서에 의해 해석 될 경우에만 가능한 PHP를 삽입하려고 시도합니다.

이렇게 접근 할 수있는 방법은 두 가지가 있습니다. 출력 버퍼를 생성하고 나중에 파이프를 통해 출력을 보내고 include 문으로 처리하거나 php eval 함수로 보내면됩니다. 보안 위험 때문에 이러한 옵션을 사용하지 않아야합니다.

다음 코드는 PHP 주입 보안 위험없이 스크립트가 의도 한 결과를 제공 할 것입니다.

remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10); 
remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10); 

add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10); 
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10); 
//' Not sure why this quote was here.... 
function my_theme_wrapper_start() { 
    //echo ' 

// ending PHP processor instruction here will cause code to execute when current function is called 

?> 

<div id="block" <?php 
    if ($detect->isMobile()) {if($detect->isTablet()){ 
    /* Tab */ 
    if (get_field("search_override_header_position", "options") && get_field("search_tablet_header_position", "options")) {echo 'data-header-position="'.get_field("search_tablet_header_position", "options").'"';} else {echo 'data-header-position="'.$tablet_header_position.'"';}; 
} else { 
    /* Mob */ } 
    if (get_field("search_override_header_position", "options") && get_field("search_mobile_header_position", "options")) {echo 'data-header-position="'.get_field("search_mobile_header_position", "options").'"';} else {echo 'data-header-position="'.$mobile_header_position.'"';}; 
} else { 
    /* Desc */ 
    if (get_field("search_override_header_position", "options") && get_field("search_header_position", "options")) {echo 'data-header-position="'.get_field("search_header_position", "options").'"';} else {echo 'data-header-position="'.$header_position.'"';}; 
} 
?>>&nbsp;</div><section id="main"><?php 

// '; // no need for ending quote here but we do need to reopen the PHP processor instruction that we closed above instead of using an echo 
} 

function my_theme_wrapper_end() { 
    echo '</section>'; 
} 
관련 문제