Closed pmpr closed 6 years ago
You either need to grab the information yourself from the database, or you could set up a twig extension and have that extension call the wordpress function, provided you are loading wordpress as well as symfony in your project.
https://symfony.com/doc/master/templating/twig_extension.html
Thanks for your response, but what do you mean by
provided you are loading wordpress as well as symfony in your project ??
I setup the KayueWordpressBundle, and now want to get post thumbnail. I am familiar with Twig extensions. But how should I call Wordpress functions from within Twig extension? AFAIK, the Wordpress core is not part of KayueWordpressBundle anymore:
Improved version of the original WordpressBundle. The biggest different is this new KayueWordpressBundle won't load the entire WordPress core, thus all the WordPress template funtions won't be available in your Symfony app. This is also the goal of the bundle; do everything in Symfony's way.
To load the wordpress core, you need to include wp-load.php. How and where you do this depends on your project. There are some performance implications to loading both symfony and wordpress so it's best not to do it on every page.
Once you've included that file you should have access to wordpress functions and globals.
Finally I found the solution. Required Twig functions are provided by the bundle itself, out of the box:
{% set img = wp_find_featured_image(post) %}
{% if img is defined and img is not null %}
{% set url = wp_get_attachment_url(img, 'medium') %}
<img src="{{ url }}">
{% endif %}
How should one get post thumbnail in twig?
does not give me the image url.