Wordpress教程 2023年05月10日
0 收藏 0 点赞 1,373 浏览 1269 个字

可以在主题模板中使用 _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(); ?>

 

微信扫一扫

支付宝扫一扫

版权: 转载请注明出处:https://www.mizhanw.com/blog/2323.html

相关推荐
WordPress去除/禁止后台侧栏插件-主题-版本更新提示
今天使用了张戈修改的nginx-help插件修改版,官方版并无自动重启功能,因此不能更新。但是这WordPress后台一直有更新提示,这可真…
日期:2024-12-30 点赞:0 阅读:43
WordPress网站js防扒代码-禁止右键/F12/调试自动关闭窗口
网站防扒老生常谈了,今天老白博客@老白也给大家分享一下从网上看到的“WordPress网站防扒代码/禁止F12调试教程-以7b2主题为例” …
日期:2024-12-30 点赞:0 阅读:59
WordPress优化加速之导航菜单栏缓存Menu Cache
今天老白博客@老白给大家分享又一个WordPress优化加速教程:“导航菜单栏缓存WordPress插件Menu Cache”。我们都知道数…
日期:2024-12-30 点赞:0 阅读:44
2024基于网站性能测试的WordPress优化指南
老白博客WordPress优化高级教程:在如今5G遍地走,千兆多如狗的高速网络时代,如果你访问网站,还出现转圈圈的情况,那么你十有八九是要关…
日期:2024-12-30 点赞:0 阅读:49
WP网站用户行为监测回放插件nicen-replay
在数字营销的世界里,了解用户行为是提升用户体验和转化率的关键。老白推荐一款炫酷的WordPress插件:nicen-replay 。它能够让…
日期:2024-12-30 点赞:0 阅读:48
2024新WordPress缓存插件atec Cache APCu
WordPress插件atec Cache APCu 是一款2024年才投入使用的的高效缓存插件,与其他内存缓存选项(如 Redis 和 M…
日期:2024-12-30 点赞:0 阅读:65
发表评论
暂无评论

还没有评论呢,快来抢沙发~