可以在主题模板中使用 _izhanke() 函数获取后台设置的 xinwen_num 字段的值,然后将其传递到 query_posts() 函数中的 showposts 参数。
/*
* ------------------------------------------------------------------------------
* 其他调用
* ------------------------------------------------------------------------------
*/
CSF::createSection($prefix, array(
'id' => 'too_ad',
'icon' => 'fa fa-leanpub',
'title' => '其他调用',
'fields' => array(
array(
'type' => 'notice',
'style' => 'warning',
'content' => '分割线 (首页新闻公告设置)',
),
array(
'id' => 'xinwen_id',
'type' => 'select',
'title' => '新闻分类',
'placeholder' => '选择分类栏目',
'options' => 'categories',
),
array(
'id' => 'xinwen_num',
'type' => 'text',
'title' => '显示数量',
'default' => '8',
),
)
));
在模板里调用:
<?php
// 获取设置的值
$xinwen_id = _izhanke('xinwen_id');
$xinwen_num = _izhanke('xinwen_num');
?>
<?php // 调用文章
query_posts('cat=' . $xinwen_id . '&showposts=' . $xinwen_num);
while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="inNews_title"><?php the_title(); ?></a>
<a href="<?php the_permalink(); ?>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="inNews_ms"><?php the_excerpt(); ?></a>
<span><?php the_time('Y-m-d H:i:s'); ?></span>
</li>
<?php endwhile; wp_reset_query(); ?>
<li>
<a href="<?php the_permalink(); ?>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="inNews_title"><?php the_title(); ?></a>
<a href="<?php the_permalink(); ?>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="inNews_ms"><?php the_excerpt(); ?></a>
<span><?php the_time('Y-m-d H:i:s'); ?></span>
</li>
<?php endwhile; wp_reset_query(); ?>
还没有评论呢,快来抢沙发~