src/Controller/WordpressController.php line 12
- <?php
- namespace App\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- class WordpressController extends AbstractController
- {
- public function postsHomeAction(Request $request)
- {
- define('WP_USE_THEMES', false);
- require_once($this->getParameter('kernel.project_dir').'/'.$this->getParameter('avanza.web.folder').'/blog/wp-load.php');
- global $post; $sitepress;
- $locale = $request->getLocale();
- // echo $locale;
- // dump($locale);
- $sitepress->switch_lang($locale);
- // dump($sitepress->get_current_language());
- $limit = 3;
- $args = array( 'posts_per_page' => $limit, 'suppress_filters' => false );
- $posts = get_posts( $args );
- $postsE = [];
- $i = 0;
- foreach( $posts as $post )
- {
- setup_postdata($post);
- $postsE[$i]['link'] = get_the_permalink();
- $postsE[$i]['title'] = get_the_title();
- $postsE[$i]['content'] = get_the_content();
- $postsE[$i]['thumb'] = get_the_post_thumbnail_url($post->ID, "full");
- $postsE[$i]['date']['day'] = get_the_date('d');
- $postsE[$i]['date']['month'] = get_the_date('M');
- $postsE[$i]['author'] = get_the_author();
- $i++;
- }
- return $this->render('includes/posts_home.html.twig',["posts"=>$postsE]);
- }
- }