programing

$before_widget과 $after_widget의 의미는 무엇입니까?

coolbiz 2023. 4. 1. 00:00
반응형

$before_widget과 $after_widget의 의미는 무엇입니까?

이 기능은 어떻게 기능합니까?exact($args)작동합니까?
의 의미는 무엇입니까?$before_widget,$after_widget?

사이드바에서는 위젯에 자신의 클래스를 추가할 수 있습니다.<div class="well beforeW">따라서 모든 위젯은 style.css 파일에서 이미 정의한 것과 동일한 스타일을 유지합니다.

때때로 디자이너는 각 위젯의 하단에 곡선의 그림자를 추가하므로 당신은 그것을 이미지로 만들어야 합니다. 따라서 위젯이 당신의 구원이 된 후에 당신은 이것을 위젯 후에 합니다.</div><span class="specialShadow"></span>.

이렇게 하면 원하는 위젯의 앞뒤에 새 요소를 추가할 수 있습니다.

예:

register_sidebar(array('name'=>'Footer-Sidebar',
'before_widget' => '<div class="ftr-widget">',
'after_widget' => '</div><span class="specailShadow"></span>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));

위의 예에 주목하면 $120s를 함수에 삽입할 수 있습니다.또는 보다 명확한 방법으로:

$args = array('name'=>'Footer-Sidebar',
'before_widget' => '<div class="ftr-widget">',
'after_widget' => '</div><span class="specailShadow"></span>',
'before_title' => '<h3>',
'after_title' => '</h3>',
);
register_sidebar($args);

$before_widget그리고.$after_widgetregister_module 함수의 인수입니다.

위젯은 사이드바에 추가된 경우에만 사용할 수 있으며 register_sidebar 기능을 사용하면 위젯을 래핑할 HTML을 지정할 수 있습니다.일반적으로.$before_widget같은 일을 하게 될 것이다<div id="1%$s" class="widget">또는<li id="%1$s" class="widget %2$s">(디폴트) 및$after_widget같은 일을 하게 될 것이다</div>또는</li>(디폴트).

그런 다음 위젯에서 사이드바에서 이러한 인수를 추출하여 위젯 인스턴스의 출력에 사용합니다.

이 코드는 함수에 배치됩니다.php 파일.register_widget("Twenty_Eleven_Ephemera_Widget");

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



      before_widget - HTML to place before every widget(default: '<li id="%1$s" class="widget           %2$s">')
      after_widget - HTML to place after every widget (default: "</li>\n"). 

대답은 간단하다.

스텝 1: register_sidebar() 함수를 사용하여 새 사이드바를 등록하고 새로 등록된 사이드바에 이름, ID 및 설명을 지정합니다.

스텝 2: 사이드바 내에 새로운 위젯을 작성하면이러한 위젯은 마크업 내에서 묶어야 합니다.HTML 마크업은 사용자가 선택할 수 있지만, 사이드바의 향후 모든 위젯에 대해 일관성이 있어야 합니다.

따라서 위젯 전 마크업은 $before_widget이고 위젯 후 마크업은 $after_widget입니다.

예:

register_sidebar( array(

        'name' => _('Primary Sidebar', 'primary-sidebar'),
        'id'   => 'primary-area',
        'description' => _('The primary area','dir'),
        'before_widget' => '<div class="myWidget">',
        'after_widget' => "</div>",
        'before_title' => '<h3 class="myWidgetTitle">',
        'after_title' => '</h3>',

    ));

사이드바를 작성한 후 새 텍스트 위젯을 작성했다고 가정합니다.

여기에 이미지 설명 입력

텍스트 위젯 제목: 내 텍스트 위젯 내용:위젯의 내용은 이 문장입니다.

브라우저의 HTML 코드는 다음과 같습니다.

<div class="myWidget">
<h3 class="myWidgetTitle">My Text Widget</h3>
<p>My content for the widget is this sentence"</p>
</h3>
</div>

언급URL : https://stackoverflow.com/questions/17768968/whats-the-meaning-of-before-widget-and-after-widget

반응형