programing

헤더에 위젯을 추가하는 방법.wordpress로 php?

javamemo 2023. 3. 26. 09:17
반응형

헤더에 위젯을 추가하는 방법.wordpress로 php?

나는 이름이 '인 플러진'을 설치했다.Translator Box짧은 코드를 사용하여 워드프레스 테마 헤더에 넣습니다.

 [translation_box languages="english,russian,german,spanish,french,chinese" width="100%" height="200px" bgcolor="white" txtcolor="#000000"]

근데 안 돼!

또한 위젯 파트의 사용 위젯에서 위젯을 생성합니다. 헤더에서 일부 코드를 사용하는 방법이 있습니다.위젯을 호출할 수 있는 php?감사해요.

헤더에 부품을 정의할 수 있습니다.php를 클릭하여 위젯을 표시합니다.직무상.php는 다음과 같이 만듭니다.

function my_widgets_init() {

register_sidebar( array(
    'name' => __( 'Main Sidebar', 'your-theme' ),
    'id' => 'sidebar-1',
    'before_widget' => '<div id="%1$s" class="widget %2$s">',
    'after_widget' => "</div>",
    'before_title' => '<h3>',
    'after_title' => '</h3>',
) );

register_sidebar( array(
    'name' => __( 'Header Area', 'your-theme' ),
    'id' => 'sidebar-2',
    'description' => __( 'An optional widget area for your site header', 'your-theme' ),
    'before_widget' => '<div id="%1$s" class="headwidget %2$s">',
    'after_widget' => "</div>",
    'before_title' => '<h3>',
    'after_title' => '</h3>',
) );
}
add_action( 'widgets_init', 'my_widgets_init' );

예를 들어 첫 번째 부분은 사이드바의 위젯 영역이고 두 번째 부분은 헤더의 위젯 영역입니다.

이제 헤더에 포함시킵니다.php 파일:

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-2') ) : ?>
<?php endif; ?>

위젯이 있어야 할 위치를 지정합니다.

관리 인터페이스에는 위젯으로 채울 수 있는 2개의 영역('메인 사이드바' 및 '헤더 영역')이 있습니다.

do_shortcode 사용

<?php echo do_shortcode( $content ) ?>

언급URL : https://stackoverflow.com/questions/15497201/how-to-add-widget-to-the-header-php-in-wordpress

반응형