• 24-04-2022, 14:52:04
    #1
    Array içeriğine uygun bir şekilde Wordpress kategorilerini nasıl listeleyebileceğimi bilmiyorum. Anahtar olarak kategori ID'si, değer olarak ise kategori ismi gelirse süper olur. Bunu nasıl yapabilirim acaba?

    Örnek:
    array(
        '12' => 'Bakım',
        '13' => 'Beslenme',
        '14' => 'Eğitim',
        '15' => 'Sağlık',
        '16' => 'Moda',
        'A7' => 'Spor',
        '18' => 'Araba'
    )
  • 24-04-2022, 15:04:35
    #2
    Misafir
    Buyrun hocam.

    $output_categories = array();
    $categories=get_categories();
    foreach($categories as $category) {
      $output_categories[$category->cat_ID] = $category->name;
    }
    • SkyGhostAir
    SkyGhostAir bunu beğendi.
    1 kişi bunu beğendi.
  • 24-04-2022, 15:17:14
    #3
    Misafir adlı üyeden alıntı: mesajı görüntüle
    Buyrun hocam.

    $output_categories = array();
    $categories=get_categories();
    foreach($categories as $category) {
      $output_categories[$category->cat_ID] = $category->name;
    }
    Süpersin hocam, çok teşekkür ederim. İstediğimi yaptım ama şu başa eklenen 0'ın nedeni nedir acaba? Kullanımda hata yaptım galiba. Eklediğim ayarın tam kodlarını da vereyim hatam varsa uyarırsanız sevinirim.




    $wp_customize->add_control( new Laura_Dropdown_Select2_Custom_Control( $wp_customize, 'laura_featured_content_cat',
        array(
            'label' => __( 'Category', 'laura' ),
            'description' => esc_html__( 'Choosing one or more categories, display the latest published content of the relevant category.', 'laura' ),
            'section' => 'laura_home_featured_content',
            'input_attrs' => array(
                'multiselect' => true,
            ),
            'choices' => array(
                '12' => 'Bakım',
                '13' => 'Beslenme',
                '14' => 'Eğitim'
            )
        )
    ));
    $output_categories = array();
    $categories = get_categories();
    foreach($categories as $category) {
        $output_categories[$category->cat_ID] = $category->name;
    }
    $wp_customize->add_control( new Laura_Dropdown_Select2_Custom_Control( $wp_customize, 'laura_featured_content_cat',
        array(
            'label' => __( 'Category', 'laura' ),
            'description' => esc_html__( 'Choosing one or more categories, display the latest published content of the relevant category.', 'laura' ),
            'section' => 'laura_home_featured_content',
            'input_attrs' => array(
                'multiselect' => true,
            ),
            'choices' => array(
                $output_categories
            )
        )
    ));