Выбор категории в кастомизаторе в админке для вывода постов на странице
Привет. в customize.php пишу код:
$categories = get_categories(); $cats = array(); $i = 0; foreach($categories as $category){ if($i==0){ $default = $category->slug; $i++; } $cats[$category->term_id] = $category->name; } $wp_customize->add_setting('benefits_slug', array( 'transport' => $transport, 'default' => $default )); $wp_customize->add_control( 'benefits_slug', array( 'settings' => 'benefits_slug', 'label' => 'Select Category:', 'section' => 'layout_setup', 'type' => 'select', 'choices' => $cats, ));
В индексе пишу:
<div style="background-color: #ffffff" class="container-fluid" id="container-masonary"> <div class="row"> <?php // $cat_name = // $idObj = get_category_by_slug('offers'); // $idObj = get_option('$default'); $idObj = get_theme_mod('benefits_slug'); $id = $idObj->term_id; $recent = new WP_Query("cat=$id"); while($recent->have_posts()) : $recent->the_post(); ?> <!-- <a href="--><?php //the_permalink() ?><!--" rel="bookmark">--> <div class="offer_index col-xs-6 col-sm-4 col-md-3 col-lg-3 item "> <a href="<?php the_permalink() ?>" rel="bookmark"> <div class="img_cnt"> <img src="<?php the_field('offer_image'); ?>" alt="" class="offer_image"> </div> <h3><?php the_title(); ?></h3> <?php the_excerpt(); ?> <p id="res"><?php echo "$idObj" ?></p> <h4><?php the_field('offer_price'); ?> Руб.</h4> </a> </div> <?php endwhile; ?> </div> </div>
Ничего не получается) Кама помоги пожалуйста.
Цитирую Ваш код:
А В самом документа пишите
Это как то непонятно.
Сделайте:
Что хранится в переменной $idObj ?
в переменной idobj должен хранится результат выбора в кастомизаторе рубрики посты которой нужно выводить.
Я понимаю, что должен
Но что сейчас там есть ?
используйте print_r() и покажите нам.
Айди выбранной рубрики там