워드프레스 테마를 위한 옵션 트리를 통합하는 방법
플러그인을 설치하고 활성화하지 않고 옵션 트리 프레임워크를 워드프레스 테마와 통합하고 싶은데 어떻게 해야 합니까?
버전 2.0 이후로 플러그인 개발자는 당신의 함수에 사용할 수 있는 많은 필터를 포함하고 있습니다.php.다음을 포함합니다.Theme Mode
, 그리고 오트 loader 안에 있는 댓글들.php 상태;
* For developers: Theme mode.
*
* Run a filter and set to true to enable OptionTree theme mode.
* You must have this files parent directory inside of
* your themes root directory. As well, you must include
* a reference to this file in your themes functions.php.
* @since 2.0
*/
define( 'OT_THEME_MODE', apply_filters( 'ot_theme_mode', false ) );
플러그인이 아닌 테마에서 Options Tree를 활성화하려면 테마의 루트 디렉터리에 모든 플러그인 파일을 포함합니다.
/wp-content/themes/my-awesome-theme/options-트리
그리고 안에functions.php
이 필터를 실행한 다음 OT- loader를 포함합니다.php 파일.저는 아래에 이것을 보여주었고, show_pages 필터도 보여주었습니다;
add_filter( 'ot_theme_mode', '__return_true' );
add_filter( 'ot_show_pages', '__return_true' );
require_once ('option-tree/ot-loader.php');
show_pages 필터는 테마와 옵션을 설정한 후에 들어가서 false로 설정하면 클라이언트에 기본 옵션 트리 관리 메뉴가 주어지지 않으므로 '팅킹'을 시작하여 모든 것을 버릴 수 없기 때문에 유용합니다.다음으로 변경합니다.
add_filter( 'ot_show_pages', '__return_false' );
하위 테마를 사용하다가 테마 모드에서 OptionTree 플러그인을 사용할 때 "열지 못함" 오류가 발생하는 경우 다음을 수행합니다.
오트 loaderphp, 128번 행을 중심으로 이것을 바꿉니다.
if ( false == OT_THEME_MODE ) {
define( 'OT_DIR', plugin_dir_path( __FILE__ ) );
define( 'OT_URL', plugin_dir_url( __FILE__ ) );
} else {
define( 'OT_DIR', trailingslashit( get_template_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
define( 'OT_URL', trailingslashit( get_template_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
}
대상:
if ( false == OT_THEME_MODE ) {
define( 'OT_DIR', plugin_dir_path( __FILE__ ) );
define( 'OT_URL', plugin_dir_url( __FILE__ ) );
} elseif ( is_child_theme() ) {
define( 'OT_DIR', trailingslashit( get_stylesheet_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
define( 'OT_URL', trailingslashit( get_stylesheet_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
} else {
define( 'OT_DIR', trailingslashit( get_template_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
define( 'OT_URL', trailingslashit( get_template_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
}
코드는 사용 중인 테마가 하위 테마(is_child_theme())인지 확인하고 get_stylesheet_directory() 및 get_stylesheet_directory_uri()를 사용하여 dir와 url을 설정합니다.
이것이 이 문제에 직면한 다른 사람들에게 도움이 되길 바랍니다.
옵션 트리를 통합하기가 정말 쉽습니다.
동일한 플러그인 슬러그를 사용하려면 아래 링크를 방문하십시오.
또는 워드프레스 테마의 사용자 정의 폴더에 통합할 수도 있습니다.
비디오 가이드 여기 (3:44초):
add_filter('ot_show_pages','__return_false');
include_once('inc/theme-options.php');
내보내기 설정theme-options.php
파일.
add_filter('ot_theme_mode','__return_true');
require( trailingslashit( get_template_directory() ) . 'theme-option/ot-loader.php' );
add_filter('ot_show_new_layout','__return_false');
언급URL : https://stackoverflow.com/questions/12352451/how-to-integrate-option-tree-for-wordpress-theme
'sourcecode' 카테고리의 다른 글
SQL 개발자 사용자 지정 연결 문자열 (0) | 2023.10.05 |
---|---|
mysql java 프로그램에서 works를 선택, 삽입 및 삭제하지만 업데이트가 작동하지 않습니다. (0) | 2023.10.05 |
#DEBUG 정의 1 (0) | 2023.10.05 |
각도가 문서를 업데이트하기 전에 이미지를 찾을 수 없습니다. (0) | 2023.10.05 |
$exceptionHandler에서 $location - 종속성 충돌 (0) | 2023.10.05 |