php - Twig Template Import External WordPress Posts -


i'm trying load in few wordpress posts website built using twig. i've tried inserting code page gets commented out. i'm guessing there's special way i'm supposed rewrite work in twig. can me?

<?php define('wp_use_themes', false); require('../wordpress/wp-blog-header.php'); query_posts('showposts=3'); ?>  <?php while (have_posts()): the_post(); ?> <div class="wordpress-post"> <?php if ( has_post_thumbnail() ) : ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> <?php the_post_thumbnail(); ?> <h2><?php the_title(); ?></h2> <?php the_excerpt(); ?> <p><a class="read-more" href="<?php the_permalink(); ?>" class="red">read more</a></p> </div> <?php endwhile; ?> 

thanks in advance!

you cannot mix php , twig code in given twig template. should query posts in php file , pass variable twig variable render results.

by way, equivalent twig template following:

{% the_post in posts %}     <div class="wordpress-post">         {% if the_post.thumbnail defined %}             <a href="{{ the_post.permalink }}" title="{{ the_post.title }}">                 {{ the_post.thumbnail }}             </a>         {% endif %}          <h2>{{ the_post.title }}</h2>         {{ the_post.excerpt }}          <p><a class="read-more" href="{{ the_post.permalink }}" class="red">read more</a></p>     </div> {% endfor %} 

to render template in php application, first make sure twig lib installed. then, in php file, following:

<?php require_once '/path/to/lib/twig/autoloader.php'; twig_autoloader::register();  $loader = new twig_loader_filesystem('/path/to/templates/directory'); $twig = new twig_environment($loader);  // query database posts , save result in $posts variable $posts = ...  echo $twig->render('template_name.html', array('posts' => $posts)); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -