The reason is your code outputs html instead of returning it. For an LCP template to work you need to assign all output (as a string) to $this->lcp_output
, as is shown in the default template file (we also use the $lcp_display_output
variable to make things easier). The plugin will then handle outputting it exactly where you placed the shortcode.
You have two options:
- Refactor your code so that it uses functions that return stuff instead of outputting it (
get_the_permalink
instead of the_permalink
) and, as is shown in the default template, concatenate everything in a single variable.
- Use output buffering.
Output buffering example with your code:
<?php ob_start(); ?>;
<?php if( have_posts() ): ?>
<?php while( have_posts() ): the_post(); ?>
<div class="col-lg-2 col-xs-6 col-sm-6 col-md-6 product-category text-center">
<a href="<?php the_permalink(); ?>" class="product-link-category">
<img src="<?php the_field('zdjecie_do_mlw'); ?>" class="img-fluid img-category-product text-center" alt="<?php the_field('nazwa_produktu'); ?>" title="<?php the_field('nazwa_produktu'); ?>" />
<h3 class="product-name-category"><?php the_field('nazwa_produktu'); ?></h3>
</a>
<div class="button-category-product text-center">
<a href="<?php the_field('nokaut'); ?>" rel="nofollow" target="_blank" onclick="gtag('event', 'Oferta', { event_category: '<?php the_field('nazwa_produktu'); ?>', event_action: '<?php echo ($_SERVER['REQUEST_URI']);?>', event_label: '<?php the_field('nazwa_produktu'); ?>'});" class="btn category-button-price">Sprawd? cen?</a>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php
$this->lcp_output = ob_get_contents();
ob_end_clean();
?>;
Let me know if it worked.
-
This reply was modified 5 years, 11 months ago by zymeth25.