src/Eccube/Controller/TopController.php line 28

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Controller;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. require_once 'wp/wp-load.php';
  16. require_once 'wp/wp-includes/class-wp-query.php';
  17. class TopController extends AbstractController
  18. {
  19.     /**
  20.      * @Route("/", name="homepage", methods={"GET"})
  21.      * @Template("index.twig")
  22.      */
  23.     public function index()
  24.     {
  25.       // ----------------- //
  26.       // ブログ取得
  27.       // ----------------- //
  28.       $args = array(
  29.         'post_type' => 'blog',
  30.         'posts_per_page' => -1,
  31.       );
  32.       
  33.       $res = new \WP_Query($args);
  34.       
  35.       $Blogs = [];
  36.       if ($res->have_posts()):
  37.         while ($res->have_posts()) : $res->the_post();
  38.       
  39.           $dat = [];
  40.           $dat['ID'] = get_the_ID();
  41.           $dat['post_date'] = get_the_time('Y.m.d');
  42.           $dat['post_title'] = get_the_title();
  43.           $dat['link'] = '/blog/view/'.$dat['ID'];
  44.           //$dat['img_src'] = get_thumb_src(get_post_thumbnail_id(), 'large');
  45.           $dat['img_src'] = get_field('cf_blog_banner');
  46.           
  47.           //$banner = get_field('cf_blog_banner');
  48.           
  49.           $Blogs[] = $dat;
  50.       
  51.         endwhile;
  52.         wp_reset_postdata();
  53.       endif;
  54.       
  55.       
  56.         return ['Blogs'=>$Blogs];
  57.     }
  58. }