I-WordPress: Dala ama-Sidebars ngokuzenzakalela Esigabeni ngasinye

Umsebenzi wokubhalisa ama-Sidebars wesigaba ngasinye se-WordPress

Bengilokhu ngenza lula leli sayithi ukwenza ngcono izikhathi zejubane nokuzama ukwenza imali ngaleli sayithi kangcono ngaphandle kokucasula abafundi bami. Kunezindlela eziningi engikwenze ngazo imali isayithi… nakhu zisuka kokuningi kuye ekuzuziseni okungenani:

  • Ukuxhaswa okuqondile kusuka ezinkampanini zomlingani. Sisebenza ngamasu ahlanganisiwe afaka yonke into kusuka kuma-webinars kuya kumasheya ezokuxhum ukukhuthaza imicimbi yabo, imikhiqizo, kanye / noma izinsizakalo.
  • kokujoyina kusuka kuhlu lwamapulatifomu wokuhambisana. Ngihlwaya futhi ngikhombe izinkampani, ngiqinisekise ukuthi zaziwa kahle, futhi ngabelana ngama-athikili athile engiwabhalayo noma izikhangiso abazinikezayo.
  • Ukumaketha izinsizakusebenza kusuka kuzakwethu okhipha imicimbi ehlobene nokumaketha, izifundo ezimayelana namaphepha, namaphepha amhlophe.
  • Ukukhangiswa kwesibhengezo kusuka kwa-Google lapho izikhangiso ezifanele zisakazeka khona ngokuzenzakalela ngesifanekiso sami nokuqukethwe.

I-WordPress Sidebars

Ngokumaketha okuhambisanayo okuhlinzeka ngemali engenayo enesizotha, nginqume ukuthi ngifuna ukukhombisa abakhangisi abathile ngokuya ngesigaba sesayithi, ngakho-ke bengifuna ukwakha ngamandla amabha ohlangothini ngaphandle kokubhala kanzima ikhodi ngayinye eseceleni. Ngale ndlela, uma ngifaka isigaba - ibha eseceleni ivela ngokuzenzekelayo endaweni yami ye-Widget futhi ngingangeza isikhangiso.

Ukwenza lokhu, bengidinga ikhodi ethile ku imisebenzi.php ifayela lengqikithi yengane yami. Ngokujabulisayo, ngithole ukuthi othile ubesevele ebhale cishe yonke into ebengiyidinga: Dala imigoqo eseceleni ebanzi yesigaba ngasinye ku-WordPress. Bengifuna nje ezinye izilawuli ezingezekile ukuthi iziphi izigaba engingafisa ukuveza ngazo izinsimbi eziseceleni.

function add_category_sidebars() {
    $args = array(
        'type'                     => 'post',
        'orderby'                  => 'name',
        'order'                    => 'ASC',
        'hide_empty'               => 1,
        'hierarchical'             => 1,
        'exclude'                  => '',
        'include'                  => '',
        'number'                   => '',
        'taxonomy'                 => 'category'
        ); 
    
    $categories = get_categories($args);

    foreach ($categories as $category) {
        if (0 == $category->parent)
            register_sidebar( array(
                'name' => $category->cat_name,
                'id' => $category->category_nicename . '-sidebar',
                'description' => 'This is the ' . $category->cat_name . ' widgetized area',
                'before_widget' => '<aside id="%1$s" class="widget %2$s">',
                'after_widget' => '</aside>',
                'before_title' => '<h3 class="widget-title">',
                'after_title' => '</h3>',
            ));
        }
}
add_action( 'widgets_init', 'add_category_sidebars' );

Ngama-agumenti amaningi wokuthola izigaba, ngingafaka futhi ngikhiphe noma iziphi izigaba engifisa ukuzikhomba. Ngaphakathi kwesitatimende sangaphambilini, ngiyakwazi ukuguqula ngifanise ukwakheka kokufomethwa kwebha eseceleni kweWebhusayithi yami yonke.

Ngokwengeziwe, ku- imisebenzi.php, Ngifuna ukufaka umsebenzi ukubona ukuthi ngabe ibha eseceleni ikhona yini futhi ine-widget engezwe kuyo:

function is_sidebar_active($cat_name) {
    global $wp_registered_sidebars;
    $cat_id = get_cat_ID($cat_name);
    $widgetlist = wp_get_sidebars_widgets();
    if ($widgetlist[$cat_id])
        return true;
    return false;
}

Ngemuva kwalokho, ngaphakathi kwengqikithi yami Sidebar template, ngifaka ikhodi ukubonisa ngamandla indawo uma ibha eseceleni ibhalisiwe futhi inewijethi kuyo.

$queried_object = get_queried_object();
if ($queried_object) {
    $post_id = $queried_object->ID;
}
if(is_category() || in_category($cat_name, $post_id)) {
    $sidebar_id = sanitize_title($cat_name);
    if( is_sidebar_active($sidebar_id)) {
        dynamic_sidebar($sidebar_id);
    }
}

Ama-Sidebars e-WordPress wesigaba ngasinye

Umphumela yilokho kanye ebengikufuna:

Imigqa eseceleni ye-WordPress Widget Yesigaba ngasinye

Manje, noma ngabe ngiyangeza, ngihlela, noma ngisusa izigaba… izindawo zami eziseceleni zizohlala zisesikhathini njalo!

UCABANGANI?

Le sayithi isebenzisa i-Akismet ukunciphisa ugaxekile. Funda ukuthi idatha yakho yokuphawula isetshenziswa kanjani.