• Resolved damian0021

    (@damian0021)


    Hey,

    I have a small problem with an additional plug-in template.

    I created a template for posts as you indicated themes /theme-name/list-category-posts/product-mlw.php

    The appearance is as I coded, however, the posts do not show up in the place where we wanted, and exactly where I paste the plugin code.

    WP-Dashboard: https://prntscr.com/lxtfyz
    WP post: https://prntscr.com/lxtg3s

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter damian0021

    (@damian0021)

    The generated code on the page always appears before the first end, it can not be obtained.

    I also use the plugin ACF.

    My code:

    <?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; ?>
    Plugin Contributor zymeth25

    (@zymeth25)

    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:

    1. 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.
    2. 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.
    Thread Starter damian0021

    (@damian0021)

    Dzia?a, thanks!

    • This reply was modified 5 years, 11 months ago by damian0021.
    Thread Starter damian0021

    (@damian0021)

    Such code should be issued only once on the site?

    Plugin Contributor zymeth25

    (@zymeth25)

    Go to this chatroom

    https://tlk.io/lcp

    and we’ll figure it out.

    Thread Starter damian0021

    (@damian0021)

    Hello!
    I solved the problem in 90%, your bear code helped, I can use the post several times and other entries are displayed.

    Now I would like to add some pagination to my code, but I can not fix it, can you help me?

    Can you add pagination to the above code you have inserted?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Displaying posts’ is closed to new replies.