输出短码时出现问题

时间:2015-03-08 作者:Hussy571

这是我在学习shortcode时关于shortcode的第二个问题。

这是我的代码:

add_shortcode(\'work-shortcode\', \'work_shortcode\');

function work_shortcode() 
{

$return_string .= \'<div class="work">\';
$return_string .= \'<div class="container">\';
$return_string .= \'<div class="portfolio-wrapper">\';
$return_string .= \'<ul class="filter text-center wow fadeInUp" data-wow-delay="300ms">\';
$return_string .= \'<li>\';
$return_string .= \'<a class="selected" href="#" data-filter="*">All\';
$return_string .= \'</a>\';
$return_string .= \'</li>\';

$terms = get_terms("filter"); // get all categories, but you can use any taxonomy
$count = count($terms); //How many are they?
if ( $count > 0 ){  //If there are more than 0 terms
    foreach ( $terms as $term ) {  //for each term:
        $return_string .= \'<li>\';
        $return_string .= \'<a href="#" data-filter="\'.$term->slug.\'">\';
        $return_string .=  $term->name;
        $return_string .= \'</a>\';
        $return_string .= \'</li>\';
        //create a list item with the current term slug for sorting, and name for label
    }
}
 $return_string .= \'</ul>\';

 $our_work = new WP_Query(array(
    \'post_type\' => \'our_work\',
    \'posts_per_page\' =>50,


 )); //Check the WP_Query docs to see how you can limit which posts to display



if ( $our_work->have_posts() ) :

$return_string .= \'<ul class="portfolio-items">\';

while ( $our_work->have_posts() ) : $our_work->the_post();

    $termsArray = get_the_terms( $post->ID, "filter" );  //Get the terms for this particular item

    $termsString = ""; //initialize the string that will contain the terms

    foreach ( $termsArray as $term ) { // for each term 
        $termsString .= $term->slug.\' \'; //create a string that has all the slugs 
    }




    $return_string .= \'<li class="\'.$termsString. \'item">\';
    $return_string .= \'<div class="infos">\';
    $return_string .= \'<div class="img-responsive">\';
    $return_string .= get_the_post_thumbnail();
    $return_string .= \'</div>\';
    $return_string .= \'<div class="overlay">\';
    $return_string .= \'<div class="text">\';
    $return_string .= \'<h2>\'.get_the_title().\'</h2>\';
    $return_string .= \'</div>\';
    $return_string .= \'</div>\';
    $return_string .= \'</div>\';
    $return_string .= \'</li>\';

    endwhile;

    wp_reset_postdata();

    $return_string .= \'</ul>\';
    $return_string .= \'</div>\';
    $return_string .= \'</div>\';

    endif;

return $return_string;
}
实际上我有两个问题:

1) 我的过滤器不工作(它在页面中工作,但在短代码中不工作)。这是第页的代码

<ul class="filter text-center wow fadeInUp" data-wow-delay="300ms">
   <li>
      <a class="selected" href="#" data-filter="*">All</a>
   </li>                         

<?php 
$terms = get_terms("filter"); // get all categories, but you can use any taxonomy
$count = count($terms); //How many are they?
if ( $count > 0 ){  //If there are more than 0 terms
foreach ( $terms as $term ) {  //for each term:
echo "<li><a href=\'#\' data-filter=\'.".$term->slug."\'>" . $term->name . "
</a></li>\\n";
//create a list item with the current term slug for sorting, and name for label
}
} 
?>

</ul>
2)短代码没有输出帖子缩略图,但当我放置get\\u permalink()时,它会输出链接。。请帮忙。谢谢。。

1 个回复
最合适的回答,由SO网友:Lisa Daugherty Thompson 整理而成
$return_string .= get_the_post_thumbnail();

should be:

$return_string .= get_the_post_thumbnail( get_the_ID() );
结束

相关推荐

Functions.php中的入队样式

这对我没用functions.php: if( is_page_template( \'template-flat.php\' ) ) { function flatsome_scripts() { wp_enqueue_style( \'flatsome-style\', get_template_directory_uri() .\'/flatash/css/foundation.css\', array(), \'2.1\', \'all\'); }