src/Controller/WordpressController.php line 15

  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. class WordpressController extends AbstractController
  7. {
  8.     public function postsHomeAction(Request $request
  9.     {
  10.         define('WP_USE_THEMES'false);
  11.         require_once($this->getParameter('kernel.project_dir').'/'.$this->getParameter('avanza.web.folder').'/blog/wp-load.php');
  12.         global $post$sitepress;
  13.         $locale $request->getLocale();
  14. //         echo $locale;
  15. //         dump($locale);
  16.         $sitepress->switch_lang($locale);
  17. // dump($sitepress->get_current_language());        
  18.         $limit 3;
  19.         $args = array( 'posts_per_page' => $limit'suppress_filters' => false );
  20.         $posts get_posts$args );
  21.         
  22.         $postsE = [];
  23.         
  24.         $i 0;
  25.         foreach( $posts as $post )
  26.         {
  27.             setup_postdata($post);
  28.             $postsE[$i]['link'] = get_the_permalink();
  29.             $postsE[$i]['title'] = get_the_title();
  30.             $postsE[$i]['content'] = get_the_content();
  31.             $postsE[$i]['thumb'] = get_the_post_thumbnail_url($post->ID"full");
  32.             $postsE[$i]['date']['day'] = get_the_date('d');
  33.             $postsE[$i]['date']['month'] = get_the_date('M');
  34.             $postsE[$i]['author'] = get_the_author();
  35.             $i++;
  36.         }
  37.         
  38.         return $this->render('includes/posts_home.html.twig',["posts"=>$postsE]);
  39.     }
  40. }