• Resolved lukas_pabianski

    (@lukasz-wos)


    Hi gret plugin.
    Im lookin for solution how to display pods shortcode on templte.php fille.
    <?php echo do_shortcode(‘[pods name=”samochod” where=”category.name=’osobowe'” template=”Samochody”]’); /> does’t work.

    I’ts giving me an error “Parse error: syntax error, unexpected ‘osobowe’ (T_STRING), expecting ‘)’ in /home/lukas/domains/kreotech.pl/public_html/goleasing/wp-content/themes/go-leasing/samochody.php on line 54″

    my themplate:
    <?php
    /**
    * Template Name: Cars
    *
    * This is the template that displays all pages by default.
    * Please note that this is the WordPress construct of pages
    * and that other ‘pages’ on your WordPress site will use a
    * different template.
    *
    * @package understrap
    */

    /**
    * Allow Pods Templates to use shortcodes
    *
    * NOTE: Will only work if the constant PODS_SHORTCODE_ALLOW_SUB_SHORTCODES is defined and set to
    true, which by default it IS NOT.
    */
    add_filter( ‘pods_shortcode’, function( $tags ) {
    $tags[ ‘shortcodes’ ] = true;

    return $tags;

    });
    ?>
    <?php
    // Exit if accessed directly.
    defined( ‘ABSPATH’ ) || exit;

    get_header();
    ?>

    <!– Card –>

    <section>
    <div class=””>
    <div class=”bg-top”></div>
    </div>

    </section>

    <section class=”py-5 position-relative”>
    <div class=”container-fluid”>
    <div class=”row justify-content-center”>
    <div class=”col-12 text-center “>
    <div class=”tekst-height d-inline-block text-left mt-3″>
    <p class=”tekst-2 text-creative”>samochody</p>
    <p class=”tekst-1 text-creative”>Go Leasing</p>
    </div>
    </div>
    </div>
    </div>
    <div class=”trojkat-t” data-aos=”zoom-in-left” data-aos-duration=”2000″>
    ...
    </div>

    </section>

    <span style=”color: #0000ff;”>Osobowe</span>
    <div class=”row”>

    <?php echo do_shortcode(‘[pods name=”samochod” where=”category.name=’osobowe'” template=”Samochody”]’); />
    ?>
    </div>

     

    <span style=”color: #ff0000;”>Dostawcze</span>
    <div class=”row”>
    <?php echo do_shortcode(‘[pods name=”samochod” where=”category.name=’dostawcze'” template=”Samochody”]’); />
    ?>
    </div>

    <?php get_footer(); ?>

    Can you help me solve this problem?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Jim True

    (@jimtrue)

    The Allow Pods Shortcode to run in Pods Templates is not for the template.php, it’s for our Pods Templates which are part of Pods.

    This whole block does not go in your template.php; it goes in your functions.php:

    
    /**
    * Allow Pods Templates to use shortcodes
    *
    * NOTE: Will only work if the constant PODS_SHORTCODE_ALLOW_SUB_SHORTCODES is defined and set to
    true, which by default it IS NOT.
    */
    add_filter( ‘pods_shortcode’, function( $tags ) {
    $tags[ ‘shortcodes’ ] = true;
    
    return $tags;
    
    });
    

    You’ve either got an escaping issue or you’re using a pretty single quote in that shortcode, based on the error:
    Parse error: syntax error, unexpected ‘osobowe’ (T_STRING), expecting ‘

    You can determine if that is the case by testing your shortcode in a WordPress page.

    Thread Starter lukas_pabianski

    (@lukasz-wos)

    Hi thank you for your response.
    I have added code from above to my function.php
    Shortcode works well on wordpress page, in “visual editor” but it does’t work in template.
    [pods name=”samochod” where=”category.name=’osobowe'” template=”Samochody” shortcodes=1 ]
    When i try to paste the same shortcode in to php template shows error.

    <?php echo do_shortcode( ‘[pods name=”samochod” where=”category.name=’osobowe'” template=”Samochody” shortcodes=1 ]’ ); ?></div>

    I have tried in diffrent way, the php error is gone, but still is not displaying posts.

    <?php echo do_shortcode( ‘[pods name=”samochod” where=”category.name="osobowe"” template=”Samochody” shortcodes=1]’ ); ?>

    if i do delete single quote posts are not showing at all?

    Plugin Author Jory Hogeveen

    (@keraweb)

    @lukasz-wos
    What error do you see? We can’t help you if we do not get all information.

    As for quotes, you cannot mix quotes within PHP so this won’t work:
    <?php echo do_shortcode( ‘[pods name=”samochod” where=”category.name="osobowe"” template=”Samochody” shortcodes=1]’ ); ?>
    Please get yourself familiar with using PHP strings:
    https://www.php.net/manual/en/language.types.string.php

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘display shortcode in post temlate’ is closed to new replies.