codestar-framework获取后台设置控制指定分类文章和显示数量

1,457次阅读
没有评论

可以在主题模板中使用 _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(); ?>" class="inNews_title"><?php the_title(); ?></a>
    <a href="<?php the_permalink(); ?>" 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(); ?>" class="inNews_title"><?php the_title(); ?></a>
    <a href="<?php the_permalink(); ?>" class="inNews_ms"><?php the_excerpt(); ?></a>
    <span><?php the_time('Y-m-d H:i:s'); ?></span>
</li>
<?php endwhile; wp_reset_query(); ?>

 

正文完
 0
评论(没有评论)

觅站网

Posts

Sed cras ornare arcu dui vivamus arcu felis. Cursus euismod quis viverra nibh cras pulvinar mattis nunc.

Melissa Meiers