我们在使用wordpress进行开发时,需要从数据库拿到我们所需的数据,worspress本身自带方法去实现此操作,如下:
<?php
            $args = array(
                'post_type' => 'post',//请求类型
                'category_name' => 'banner_title_big',//分类目录的名称
      ... //还可以根据其他字段
            );
            $listings = new WP_Query( $args );
            // 开始循环
            if ( $listings->have_posts() ) {
                //如果找到了结果,便输出以下内容
                while ( $listings->have_posts() ) {
                    //再次判断是否有结果
                    $listings->the_post();//不用问为什么,每次都要写这个;    
       //获取文章title
                    $bannerTitle = get_the_title();
                    //获取文章content
                    $bannerCon = get_the_content();
       ...//我们在这里可以操作从数据库拿到的数据了
    }
?>

相关文章:

  • 2021-11-18
  • 2021-11-27
  • 2021-12-07
  • 2021-06-21
  • 2021-08-12
猜你喜欢
  • 2021-06-20
  • 2022-01-20
  • 2021-09-24
  • 2022-12-23
  • 2021-11-16
  • 2021-11-28
  • 2021-12-28
相关资源
相似解决方案