Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
注意:未定义变量:在C:\wamp\www\moderna\wp content\themes\moderna\inc\shortcodes.php的第48行发布_Php_Wordpress_Shortcode - Fatal编程技术网

注意:未定义变量:在C:\wamp\www\moderna\wp content\themes\moderna\inc\shortcodes.php的第48行发布

注意:未定义变量:在C:\wamp\www\moderna\wp content\themes\moderna\inc\shortcodes.php的第48行发布,php,wordpress,shortcode,Php,Wordpress,Shortcode,在尝试使用post global之前,您没有将其包括在内。导致问题的行包括: function portfolio_shortcode($atts, $content = null){ extract( shortcode_atts( array( 'type' => 'post', ), $atts ) ); $q = new WP_Query( array('posts_per_page' => 5, 'post_typ

在尝试使用post global之前,您没有将其包括在内。导致问题的行包括:

function portfolio_shortcode($atts, $content = null){
    extract( shortcode_atts( array(
        'type' => 'post',
    ), $atts ) );

     $q = new WP_Query(
        array('posts_per_page' => 5, 'post_type' => 'portfolio')
        );              

    $list = '<div class="row">
                <section id="projects">
                    <ul id="thumbs" class="portfolio">';
    while($q->have_posts()) : $q->the_post();
        $idd = get_the_ID();

        $portfolio_large = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'portfolio-large' );
        $portfolio_thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'portfolio-image' );

        $list .= '

                    <!-- Item Project and Filter Name -->
                <li class="col-lg-3 design" data-id="id-0" data-type="web">
                <div class="item-thumbs">
                <!-- Fancybox - Gallery Enabled - Title - Full Image -->
                <a class="hover-wrap fancybox" data-fancybox-group="gallery" title="'.get_the_title().'" href="'.$portfolio_large[0].'">
                <span class="overlay-img"></span>
                <span class="overlay-img-thumb font-icon-plus"></span>
                </a>
                <img src="'.$portfolio_thumb[0].'" alt="'.get_the_title().'" />

                </div>
                </li>

        ';  

    endwhile;
    $list.= '</ul></section></div>';
    wp_reset_query();
    return $list;
}
add_shortcode('portfolio', 'portfolio_shortcode'); 
对于这一特定错误,有两种解决方案

一,

增加全球$员额;到你的功能的顶端。例如

$portfolio_large = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'portfolio-large' );
$portfolio_thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'portfolio-image' );
二,

您已经在使用$idd=get\u the\u ID;获取ID;。用它代替$post->ID


还有第三种选择,我在最后提到,因为如果你将来遇到类似的问题,它对你没有帮助。get_post_thumbnail_id将用于循环中的当前帖子。因此,您不需要传入任何ID。

$post->ID->idd->ID?最后一行真的是第48行吗?到目前为止,您尝试了什么?标题中包含问题的问题,并且问题主体中没有其他解释信息,这些问题往往会被关闭。您的帖子中只有41行代码,但问题出现在第48行…您需要向我们展示第48行的代码…您如何知道OP甚至在任何地方定义了$post?!代码是特定于WordPress的$帖子已经在全球范围内定义了,用户不需要自己做。嗨,Nathan Dawson,非常感谢。
function portfolio_shortcode( $atts, $content = null ) {
    global $post;
    ...
$portfolio_large = wp_get_attachment_image_src( get_post_thumbnail_id( $idd ), 'portfolio-large' );
$portfolio_thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $idd ), 'portfolio-image' );