Wordpress教程 2023年05月10日
0 收藏 0 点赞 1,163 浏览 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

相关推荐
如何向WooCommerce导入产品(快速而简单的方法)
无论你是刚开始用WooCommerce开店,还是想加快向现有商店添加产品的进程,学习如何向WooCommerce导入产品都很重要。批量导入产…
日期:2023-11-29 点赞:0 阅读:8
WordPress建站教程:解决谷歌字体导致的网站卡顿问题
继续分享wordpress建站教程。悦然wordpress建站之前使用blocksy主题帮客户做了一个物流公司公司建设,网站的各方面都还不错…
日期:2023-11-22 点赞:0 阅读:21
WordPress外贸网站速度优化:如何选择性能优化插件?
使用wordpress建站时,我们一定要考虑到wordpress网站加速问题,因为网站打开速度太慢会影响到用户体验和谷歌SEO优化效果。一般…
日期:2023-11-22 点赞:0 阅读:18
什么是WordPress跨境电商AB站?
做过wordpress跨境电商网站的人应该都知道,支付收款是一个大问题,特别是Paypal封号比较严重,之前帐户清零的新闻还历历在目,其它的…
日期:2023-11-22 点赞:0 阅读:20
Custom Field Suite 修改woocommerce销量
Custom Field Suite 修改woocommerce销量
日期:2023-10-29 点赞:0 阅读:24 套餐
宝塔面板里mysql经常自动停止怎么办?
宝塔面板里mysql经常自动停止怎么办? 随着服务器里面的项目越来越多,会发现宝塔面板里mysql经常自动停止。通常这个是因为服务器内存不足…
日期:2023-08-06 点赞:0 阅读:131
发表评论
暂无评论

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