를 사용하여 프론트 엔드에서 백엔드의 동적 선택 범주를 반향하는 방법내가 functions.php에있는 워드 프레스
//Example of select field
$this->settings['select'] = array(
'section' => 'general',
'title' => __('Example Select'),
'desc' => __('This is a description for the drop-down.'),
'type' => 'select',
'std' => '',
'choices' => array(
'choice1' => 'Choice 1',
'choice2' => 'Choice 2',
'choice3' => 'Choice 3'
)
);
//Here i have managed to echo the categories dynamically in the back-end
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0
);
$categories = get_categories($args);
$categories_name = array();
foreach($categories as $category){
$categories_name[] = $category->name;
}
$this->settings['categoriesmain1'] = array(
'section' => 'general',
'title' => __('Select Left Block Category'),
'desc' => __('Here you can select the main category for main left block.'),
'type' => 'select',
'std' => '',
'choices' => $categories_name // this returns the category names in a select field
);
$settings = get_option('mytheme_options');
$my_choices_cat1 = $settings['categoriesmain1'];
$this->settings['categoriesmain2'] = array(
'section' => 'general',
'title' => __('Select Center Block Category'),
'desc' => __('Here you can select the main category for main center block.'),
'type' => 'select',
'std' => '',
'choices' => $categories_name
);
$settings = get_option('mytheme_options');
$my_choices_cat2 = $settings['categoriesmain2'];
$this->settings['categoriesmain3'] = array(
'section' => 'general',
'title' => __('Select Right Block Category'),
'desc' => __('Here you can select the main category for main right block.'),
'type' => 'select',
'std' => '',
'choices' => $categories_name
);
$settings = get_option('mytheme_options');
$my_choices_cat3 = $settings['categoriesmain3'];
index.php를
<?php $settings = get_option('mytheme_options');
query_posts('category_name='.$settings["categoriesmain1"].'&posts_per_page=1');
while (have_posts()) : the_post(); ?>
<div class="boxes-third boxes-first">
<div class="boxes-padding">
<div class="bti">
<div class="featured-images"><?php the_post_thumbnail(array(300,300)); ?></div>
<div class="featured-titles"><?php echo get_the_title($post->ID); ?></div>
</div>
<div class="featured-text"><?php the_content('',FALSE,''); ?></div>
</div>
<span class="box-arrow"></span>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php $settings = get_option('mytheme_options');
query_posts('category_name='.$settings["categoriesmain2"].'&posts_per_page=1');
while (have_posts()) : the_post(); ?>
<div class="boxes-third">
<div class="boxes-padding">
<div class="bti">
<div class="featured-images"><?php the_post_thumbnail(array(300,300)); ?></div>
<div class="featured-titles"><?php echo get_the_title($post->ID); ?></div>
</div>
<div class="featured-text"><?php the_content('',FALSE,''); ?></div>
</div>
<span class="box-arrow"></span>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php $settings = get_option('mytheme_options');
query_posts('category_name='.$settings["categoriesmain3"].'&posts_per_page=1');
while (have_posts()) : the_post(); ?>
<div class="boxes-third boxes-last">
<div class="boxes-padding">
<div class="bti">
<div class="featured-images"><?php the_post_thumbnail(array(300,300)); ?></div>
<div class="featured-titles"><?php echo get_the_title($post->ID); ?></div>
</div>
<div class="featured-text"><?php the_content('',FALSE,''); ?></div>
</div>
<span class="box-arrow"></span>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
문제는 점에서 index.php를 $settings[]
이 제대로 에코되지 않습니다. Category3
가 선택되고 난 var_dump
또는 print_r
가 배열 {} (빈 배열) 같은 것을 메아리 추가 예
query_posts('category_name='.$settings["categoriesmain3"].'&posts_per_page=1');,
대신 카테고리 명을 반향 ,
query_posts('category_name=Category3&posts_per_page=1');
되어야 카테고리를 사용자가 백엔드에서 내 functions.txt는 http://pastebin.ca/2476028 입니다. 제발 저를 도울 때 WordPress에 최선을 다하고 있습니다. 내가 위해서 var_dump를해야하는 위치
query_posts를 사용하지 마십시오. 성능이 매우 좋지 않습니다 ([info] (http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts- vs-get-posts)) – janw
'var_dump ($ settings)'시도 틀린 옵션을 얻으려고 노력합니다. 당신은 어떤 종류의 설정 프레임 워크를 사용합니다. 어느 것이 든 말해야합니다. – janw
@janw 예를 들어, query_posts ('category_name ='. $ settings [ "categoriesmain2"]. & posts_per_page = 1 ');'뒤에'var_dump ($ settings)'를 추가하고 내 모든 백엔드 설정을 그 이유를 이해하지 못한다면, 다른 옵션이 제대로 작동하기 때문에 범주를 지적해야합니다. 텍스트/체크 박스와 같습니다. select만이 문제입니다. – Adrian