Yuav ua li cas ntxiv WordPress widgets?Cov ntsiab lus kev koom ua ke Widgets cheeb tsam

Kev cai zaub mov nta thiab sidebar widgets, yogWordPressFeatured nta hauv lub ntsiab.

  • Ua ib lub ntsiab lus, yog tias nws tsis suav nrog ob txoj haujlwm no, zoo li qaib tav ...

Chen Weilianghauv yav dhau lostsim lub vev xaibHauv qhov kev qhia no, kuv qhia yuav ua li cas muab lub ntsiab lus WordPressNtxiv cov ntawv qhia zaub mov.

Kab lus no piav qhia txog yuav ua li cas ntxiv kev cai widget ua haujlwm thaum tsim lub ntsiab lus.

Ib yam li ntxiv cov ntawv qhia kev cai rau cov ntsiab lus, kev cai ntxiv widgets tsuas yog siv 3 kauj ruam xwb.

Thawj kauj ruam, sau npe gadget

Txhawm rau siv cov widget, koj yuav tsum xub sau npe, qhib cov ntaub ntawv functions.php hauv qab lub ntsiab lus WordPress,

Hauv cov ntaub ntawv functions.php, ntxiv cov cai hauv qab no:

<?php

//侧边栏小工具
if ( function_exists('register_sidebar') ) {
    register_sidebar( array(
        'name' => __( 'Top Sidebar' ),
        'id' => 'top-sidebar',
        'description' => __( 'The top sidebar' ),
        'before_widget' => '<li>',
        'after_widget' => '</li>',
        'before_title' => '<h2>',
        'after_title' => '</h2>',
    ) );
}

?>

 

Hloov kho cov cim npe li thiab h2 hauv functions.php kom sib haum rau cov cim npe hauv sidebar.php:

Lub li thiab module h2 lub npe ntawm 'before_widget' thiab 'after_widget', hloov cov cai raws li qhov tseeb.

(tej zaum tsis muaj kev hloov kho)

        'before_widget' => '<li>',
        'after_widget' => '</li>',

        'before_title' => '<h2>',
        'after_title' => '</h2>',

Cov cai saum toj no sau npe thaj chaw widget hu ua "top-sidebar":

  • Lub npe tso tawm yog "Top Sidebar".
  • Ntxiv ib daim ntawv h2 rau lub npe.
  • Cov ntsiab lus yog tagged nrog li.

Teev nyob rau hauvWordPress backendDashboard, mus rau Appearance → Widgets.

Yog tias koj tuaj yeem pom qhov chaw sab saum toj sab xis widget ntawm sab xis ntawm daim duab hauv qab no, nws txhais tau tias kev sau npe ua tiav ▼

Ntxiv rau sab saum toj Sidebar widget cheeb tsam ntawm sab xis ntawm WordPress 1st daim ntawv

Kauj ruam thib ob, hu rau gadget

Tom qab lub gadget tau sau npe, nws tuaj yeem hu rau hauv cov ntaub ntawv template, thiab cov cai hauv qab no tuaj yeem hu rau hauv cov ntaub ntawv sidebar.php.

1) Hauv cov ntaub ntawv sidebar.php, hauv qab qhov loj tshaj li lossis div tag, ntxig ▼

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(top-sidebar) ) : ?>

2) Hauv cov ntaub ntawv sidebar.php, qhov loj tshaj plawslos yogSaum toj no, ntxiv ▼

<?php endif; ?>

Kauj ruam XNUMX: Teeb tsa widget

1) Lub gadget tau sau npe, thiab qhov chaw tso saib kuj tau txhais hauv cov ntaub ntawv ntsiab lus.

  • Koj tuaj yeem teeb tsa thaj chaw widget hauv WordPress keeb kwm yav dhau ▼

Teeb tsa thaj chaw widget hauv WordPress keeb kwm yav dhau daim ntawv 2

2) Tom qab txuag, rov ua dua nplooj ntawv pem hauv ntej.

  • Lub sidebar ntawm peb lub vev xaib yuav zoo li daim duab hauv qab no ▼

WordPress lub vev xaib pem hauv ntej-kawg widget cheeb tsam No. 3

Koj tuaj yeem pom daim duab saum toj no, qhia tias peb lub gadget tau ua thiab ua haujlwm li qub.

Yuav ua li cas ntxiv ntau WordPress widgets nyob rau hauv ntau qhov chaw?

Rov ua cov kauj ruam XNUMX thiab XNUMX kom ua rau koj lub ntsiab lus WordPress txhawb widgets nyob rau ntau qhov chaw.

Piv txwv tias koj yuav tsum ntxiv ib lub widget rau header, sidebar, thiab hauv qab ntawm lub ntsiab.

1) Ua ntej, koj yuav tsum luam cov cai hauv qab no rau hauv cov ntaub ntawv functions.php ▼

if (function_exists('register_sidebar')) {

register_sidebar(array(
'name' => 'Header',
'id' => 'header',
'description' => 'This is the widgetized header.',
'before_widget' => '<div id="%1$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
register_sidebar(array(
'name' => 'Sidebar',
'id' => 'sidebar',
'description' => 'This is the widgetized sidebar.',
'before_widget' => '<div id="%1$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
register_sidebar(array(
'name' => 'Footer',
'id' => 'footer',
'description' => 'This is the widgetized footer.',
'before_widget' => '<div id="%1$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>'
));

}

2) Tom ntej no, ntxiv cov cai hauv qab no rau header.php, sidebar.php thiab footer.php cov ntaub ntawv feem.

header.php ▼

<div id="widgetized-header">

<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('header')) : else : ?>

<div>
<p><strong>Widgetized Header</strong></p>
<p>This panel is active and ready for you to add some widgets via the WP Admin</p>
</div>

<?php endif; ?>

</div>

sidebar.php ▼

<div id="widgetized-sidebar">

<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('sidebar')) : else : ?>

<div>
<p><strong>Widgetized Sidebar</strong></p>
<p>This panel is active and ready for you to add some widgets via the WP Admin</p>
</div>

<?php endif; ?>

</div>

footer.php ▼

<div id="widgetized-footer">

<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('footer')) : else : ?>

<div>
<p><strong>Widgetized Footer</strong></p>
<p>This panel is active and ready for you to add some widgets via the WP Admin</p>
</div>

<?php endif; ?>

</div>

Yog li ua tiav!

  • Tau kawg, koj tuaj yeem hloov kho ntau yam ntsiab lus hauv cov cai raws li koj xav tau ^_^
  • 2 cov kauj ruam saum toj no, tso cai rau tus so ntawm lub ntsiab lus los koom ua ke kev ua haujlwm ntawm widget.

Tom ntej no, txuas ntxiv qhia cov lus qhia siv widgets hauv WordPress.

WordPress Ntsiab Kev Sib Txuas Widget Widget Cov Lus Qhia

Txhim khu kev cai widgets zoo:

1) Tom qab ntxiv widgets rau lub ntsiab lus, koj tuaj yeem tsim cov ntaub ntawv cais thiab npe nwswidgets.php.

  • Yuav kom txuag tau tag nrho cov kev cai widget code ntxiv nyob rau hauv kauj ruam 1 rau daim nplaub tshev no.

2) Ntxiv cov cai rau cov ntaub ntawv functions.php:

if ($wp_version >= 2.8) require_once(TEMPLATEPATH.’/widgets.php’);

3) Txuag tag nrho cov kev cai widget widget code ntxiv rau hauv kauj ruam 1 rau cov ntaub ntawv widgets.php.

Txoj kev no ua kom txhua tus widgets thauj khoom zoo thiab ua haujlwm ntawm txhua qhov WordPress versions uas txhawb nqa widgets.

Txoj kev no, koj tuaj yeem tswj hwm koj cov ntaub ntawv WordPress ntsiab lus zoo dua.

评论 评论

Koj email chaw nyob yuav tsis raug luam tawm. Yuav tsum tau siv cov liaj teb * Ntaus Cim

Scroll rau saum