我有一个问题,我开发了一个短代码,它工作得很好,只是当我把它放在博客帖子中,页脚和相关产品停止工作。
我给你看我的代码,希望你能帮助我。
<?php
add_shortcode(\'myshort\', \'myshortBrandName\');
add_shortcode(\'myshortother\', \'myshortotherBrandArtist\');
function myshortotherBrandArtist($atts){
ob_start();
extract( shortcode_atts( array (
\'posts\' => \'\',
\'artist\' => \'\',
), $atts ) );
$options = array(
\'posts_per_page\' => $posts,
\'post_type\' => array (
\'post\' => \'post\',
),
\'meta_value\' => $artist
);
$products = new WP_Query( $options );
if( $products->have_posts() ) {
?>
<div class="contenedorelp">
<h3>The last post of <span><?php echo $artist; ?></span></h3>
<?php
while( $products->have_posts() ) {
$products->the_post();
?>
<div class="relacional">
<div class="featured-image">
<a rel="noindex, follow" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail( \'thumbnail\' ); ?></a>
</div>
<h4><?php the_title() ?></h4>
</div>
<?php
}
?></div>
<?php
return ob_get_clean();
}
else {
echo \'No exist\';
}
}
function myshortBrandName($atts){
ob_start();
extract( shortcode_atts( array (
\'posts\' => \'\',
\'brand\' => \'\',
), $atts ) );
$options = array(
\'posts_per_page\' => $posts,
\'post_type\' => \'product\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'product_brand\',
\'field\' => \'slug\',
\'terms\' => $brand
)
)
);
$products = new WP_Query( $options );
if( $products->have_posts() ) {
?>
<div class="contenedorel">
<h3>The products of <?php echo $brand; ?> en la <span><img src="/wp-content/themes/neighborhood-child/images/eboutiq-flecha-sidebar.png"/> eBoutique D Talentos</span></h3>
<?php
while( $products->have_posts() ) {
$products->the_post();
$price = get_post_meta( get_the_ID(), \'_regular_price\', true);
?>
<a rel="noindex, follow" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><div class="relacional">
<div class="featured-image">
<?php the_post_thumbnail( \'thumbnail\' ); ?>
</div>
<h4><span><?php the_title() ?> </span><span class="price">$ <?php echo $price; ?> MXN</span></h4>
</div></a>
<?php
}
?></div>
<?php
return ob_get_clean();
}
else {
echo \'No exist\';
}
}
?>
谢谢大家