Code Monkey home page Code Monkey logo

Comments (4)

jgarib avatar jgarib commented on August 30, 2024

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

from kayuewordpressbundle.

 avatar commented on August 30, 2024

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.

from kayuewordpressbundle.

jgarib avatar jgarib commented on August 30, 2024

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.

https://wordpress.stackexchange.com/questions/47049/what-is-the-correct-way-to-use-wordpress-functions-outside-wordpress-files

Once you've included that file you should have access to wordpress functions and globals.

from kayuewordpressbundle.

 avatar commented on August 30, 2024

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 %}

from kayuewordpressbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.