I-WordPress: Yenza iibhola ezisecaleni ngokuzenzekelayo kwiCandelo ngalinye

Umsebenzi wokuBhaliswa kweeBhola ezisecaleni kwiCandelo ngalinye le-WordPress

Kudala ndenza lula le ndawo ukuphucula amaxesha esantya kunye nokuzama ukwenza imali endaweni engcono ngaphandle kokucaphukisa abafundi bam. Kukho iindlela ezininzi endiye ndenza imali ngazo isiza… nantsi zisuka kwezona zininzi ziye kutsho kwinzuzo encinci:

  • Inkxaso ngqo ezivela kwiinkampani zamaqabane. Sisebenza kwizicwangciso zokudibanisa ezibandakanya yonke into ukusuka kwiwebhu ukuya kwizabelo zemidiya yoluntu ukukhuthaza iminyhadala yabo, iimveliso, kunye / okanye iinkonzo.
  • Ukuthengiswa kwamanyathelo ukusuka kuluhlu lwamaqonga amanyeneyo. Ndijongile kwaye ndichonge iinkampani, ndiqinisekise ukuba bayaziwa, kwaye babelana ngamanqaku athile endiwabhalayo okanye iintengiso abazibonelelayo.
  • Ukuthengisa izixhobo ukusuka kwiqabane elikhupha Iziganeko ezinxulumene nokuthengisa, izifundo zamaphepha, kunye namaphepha amhlophe.
  • Isibhengezo-ntengiso ukusuka kuGoogle apho iintengiso ezifanelekileyo zichithwa ngokuzenzekelayo kwitemplate yam kunye nomxholo.

Iibhola ezisecaleni zeWordPress

Ngokuthengisa ngokudibeneyo kubonelela ngengeniso efanelekileyo, ndaye ndagqiba kwelokuba ndifuna ukubhengeza abathengisi abathile ngokusekwe kudidi lwesiza, ngenxa yoko bendifuna ukwenza ngamandla iicarbars ngaphandle kokufaka ikhowudi kwicala ngalinye lesiza. Ngale ndlela, ukuba ndongeza udidi - ibha esecaleni ivela ngokuzenzekelayo kwindawo yam yewijethi kwaye ndingongeza intengiso.

Ukwenza oku, bendifuna ikhowudi ethile kwi Imisebenzi.php ifayile yomxholo womntwana wam. Ngombulelo, ndafumanisa ukuba umntu sele ebhale phantse yonke into endiyifunayo: Yenza iibhola ezisecaleni eziBanzi zeCandelo ngalinye kwi-WordPress. Ndifuna nje ulawulo olongezelelweyo ngaphezulu kweziphi iindidi endinokunqwenela ukubonisa kuzo iibar ezisecaleni.

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' );

Ngoluhlu lweempikiswano zokufumana kwakhona iindidi, ndingabandakanya kwaye ndingabandakanyi naziphi na iintlobo endinqwenela ukujolisa kuzo. Ngaphakathi kwengxelo engaphambili, ndinokutshintsha kwaye nditshatise ubeko kwindawo yam esezantsi yeWordPress yokufomatha ibar esecaleni.

Ukongeza kwi Imisebenzi.phpNdifuna ukongeza umsebenzi ukuze ndibone ukuba ibar esecaleni ikhona kwaye inewijethi eyongeziweyo 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;
}

Ke ngaphakathi komxholo wam esecaleni template ifayile, ndongeza ikhowudi ukubonisa ngamandla indawo ukuba ibar yecala ibhalisiwe kwaye 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);
    }
}

Iibhola ezisecaleni ze-WordPress zeCandelo ngalinye

Iziphumo yile nto kanye bendiyifuna:

Iibhola ezisecaleni zeWidget ezisecaleni kwinqanaba ngalinye

Ngoku, nokuba ndiyadibanisa, ukuhlela, okanye ukucima iindidi… iindawo zam ezisecaleni ziya kuhlala zisexesheni!

Ingaba ucinga ntoni?

Le sayithi isebenzisa i-Akismet ukunciphisa ugaxekile. Funda indlela idatha yakho yokubhaliweyo isetyenziswe ngayo.