Der WordPress-Shortcode befindet sich immer ganz oben im Inhalt

Lesezeit: 2 Minuten

Dieser Shortcode befindet sich immer oben im Inhalt, unabhängig davon, wo er auf der Seite platziert wird. Wie kann ich ihn dort anzeigen lassen, wo er platziert ist?

Ich habe versucht, die zu ersetzen echo Aussagen mit return wie in früheren Beiträgen beschrieben, aber es bricht das Skript.

Der Shortcode zieht 1 Produkt aus jedem Produktattributbegriff und zeigt dann das Produktbild und den Namen des Attributbegriffs an.

function navigationProdFromEachLimit() {
$factwpslug = "/charts/?fwp_chart_type=";
$number="5"; //LIMIT THE NUMBER OF RETURNED CHART TYPES

$args = array(

'number'     => $number,
'orderby'    => 'count',
'order'      => 'DESC',
'hide_empty' => false,
'include'    => $ids,
);
$product_categories = get_terms( 'pa_chart-type', $args );
 $count = count($product_categories);
if ( $count > 0 ){
foreach ( $product_categories as $product_category ) {
    $args = array(
        'posts_per_page' => 1,
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'pa_chart-type',
                'field' => 'slug',
                'terms' => $product_category->slug
            )
        ),
        'post_type' => 'product',
        'orderby' => 'title,'
    );
    $products = new WP_Query( $args );
    while ( $products->have_posts() ) {
        $products->the_post();

        ?>
            <div class ="chart-type-nav <?php echo $product_category->slug ?>">

                <a class="nav-thumb" href="https://stackoverflow.com/questions/60588554/<?php%20echo%20$factwpslug%20%20.%20$product_category->slug%20?>">
                   <div class ="img-contain"> <?php the_post_thumbnail(); ?></div>
                </a>
                  <?php
             echo '<span class="nav-title"><a href="'.$factwpslug%20%20.%20$product_category->slug%20.%20'">' . $product_category->name . '</a></span>';
 ?>
            </div>
        <?php

    }
}
}
}
add_shortcode('navprodealimit', 'navigationProdFromEachLimit');

Sie können die Shortcode-Ausgabe ohne Ausgabepufferung nicht echoen. Du musst RETURN Shortcode-Ausgabe.

function navigationProdFromEachLimit() {
$factwpslug = "/charts/?fwp_chart_type=";
$number="5"; //LIMIT THE NUMBER OF RETURNED CHART TYPES

$args = array(

'number'     => $number,
'orderby'    => 'count',
'order'      => 'DESC',
'hide_empty' => false,
'include'    => $ids,
);
$product_categories = get_terms( 'pa_chart-type', $args );
$count = count($product_categories);

ob_start(); // Use Output Buffering for your shortcode

if ( $count > 0 ){
foreach ( $product_categories as $product_category ) {
    $args = array(
        'posts_per_page' => 1,
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'pa_chart-type',
                'field' => 'slug',
                'terms' => $product_category->slug
            )
        ),
        'post_type' => 'product',
        'orderby' => 'title,'
    );
    $products = new WP_Query( $args );
    while ( $products->have_posts() ) {
        $products->the_post();
        ?>
            <div class ="chart-type-nav <?php echo $product_category->slug ?>">

                <a class="nav-thumb" href="https://stackoverflow.com/questions/60588554/<?php%20echo%20$factwpslug%20%20.%20$product_category->slug%20?>">
                   <div class ="img-contain"> <?php the_post_thumbnail(); ?></div>
                </a>
                  <?php
             echo '<span class="nav-title"><a href="'.$factwpslug%20%20.%20$product_category->slug%20.%20'">' . $product_category->name . '</a></span>';
 ?>
            </div>
        <?php

            }
        }
    }
    return ob_get_clean(); // You have to return shortcode output.
}
add_shortcode('navprodealimit', 'navigationProdFromEachLimit');

1010310cookie-checkDer WordPress-Shortcode befindet sich immer ganz oben im Inhalt

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy