为什么我的unctions.php会导致白屏和媒体库问题?

时间:2014-04-02 作者:Daniel Dropik

Overview:

我创作了一个子主题,并意识到它的功能。php导致媒体库出现问题,并导致编辑帖子后出现“白屏”。我通过从函数中删除所有内容修复了此问题。php,但我不知道是什么导致了这种情况。

信息:Production Server: 多站点,Wordpress 3.8.1Local development server(又名“localhost”):Wordpress 3.8.1和AMPPS v2。2(php v5.3)在Windows 7 Pro SP1中。


The Media-Library problem:标题-->“选择图像”->“从媒体库中选择图像”AND 转到帖子-->“所有帖子”->“编辑帖子”->“设置特色图片”时,媒体库没有显示任何内容,就好像我的媒体库是空的一样。尽管转到仪表板-->媒体-->库并验证是否存在媒体内容,但仍会出现这种情况

    白屏问题:

    • 在转到“帖子-->所有帖子-->编辑帖子-->更新”时,单击按钮更新/创建帖子时会出现一个白屏CNTRL+s 从所见即所得中保存帖子不会导致出现白色屏幕

    功能。php的功能就是这样。php看起来像之前一样,我通过删除所有内容修复了这个问题。(结果证明,无论如何,我不再需要其中的函数)。同时打开http://pastebin.com/KS66yfqK

    <!-- In a child theme, all of the functions of the parent theme are present, unless   overridden here -->
    <?php
    
    function cals_fetch_feed2($feed_uri,$num_items, $echo = 1, $length =-1, $exclude=\'\'){
    //NOTE: to disable cache, go to feed.php and replace timestamp in 
    // $feed->set_cache_duration(apply_filters(\'wp_feed_cache_transient_lifetime\', 43200, $url)); 
    $i = rand(1,5);
    // Get RSS Feed(s)
    include_once(ABSPATH . WPINC . \'/feed.php\');
    
    // Get a SimplePie feed object from the specified feed source.
    $rss = fetch_feed($feed_uri);
    
    if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly 
    
        //enable order by date
        $rss->enable_order_by_date(true);
    
        // Figure out how many total items there are, but limit it to $num_items. 
        $maxitems = $rss->get_item_quantity($num_items); 
    
        // Build an array of all the items, starting with element 0 (first element).
        $rss_items = $rss->get_items(0, $maxitems); 
    endif;
    
    if($echo == 1){
    
        if (count($rss_items) == 0) {
            //echo \'<li>No items.</li>\';
            echo \'no items\';
        } else {
            foreach ( $rss_items as $item ) { 
    
                //check for excluded posts
                if($exclude!=\'\' && $exclude == $item->get_id()){
                    continue;
                }
    
    
                $featuredImageSrc = $item->get_item_tags(\'\', \'featuredimage\'); 
    
    
                $featuredImage = $featuredImageSrc[0][\'data\'];
    
    
    
                ?>
    
                <?php  
                /*if($featuredImage) {*/
    
                    echo \'<div class="newsItem fromFunctionsPHP \';
                    if(!$featuredImage) {echo \'noImage \';}
    
    
    
    
                    foreach ($item->get_categories() as $category)
                        {
                            echo $category->get_label()." ";
    
    
                            /*$imageCat = $category->get_label();
    
                        if($imageCat == "Agriculture" || $imageCat == "Food" || $imageCat == "Environment" || $imageCat == "Energy" || $imageCat == "Health" || $imageCat == "People" || $imageCat == "Communities" || $imageCat == "Events") {
    
                            break;
    
                        } else {
    
    
                            echo "Announcements ";
                            break;
                        }*/
    
                        }
    
                    echo \'"><div class="previousa"><div class="additionalContent">\';
    
                    $notdisplayed = true;
    
                if($featuredImage1) {
                    echo \'<img src="\'.$featuredImage1.\'" alt="" />\';
                } else if($featuredImage) {
                    echo \'<img src="\'.$featuredImage.\'" alt="" />\';
                } else {
                    echo \'<div class="noImageSpacer"></div>\';
                    /*foreach ($item->get_categories() as $category)
                    {
                        $imageCat = $category->get_label();
    
                        if($imageCat == "Agriculture") {
    
                            echo \'<img src="\';
                            echo bloginfo(\'template_url\');
                            echo \'/images/agriculture-pic-\';
                            echo rand(1,3);
                            echo \'.jpg" alt=" " />\';
                            break;
                        } else if($imageCat == "Food") {
    
                            echo \'<img src="\';
                            echo bloginfo(\'template_url\');
                            echo \'/images/food-pic-\';
                            echo rand(1,3);
                            echo \'.jpg" alt=" " />\';
                            break;
                        } else if($imageCat == "Environment") {
    
                            echo \'<img src="\';
                            echo bloginfo(\'template_url\');
                            echo \'/images/environment-pic-\';
                            echo rand(1,3);
                            echo \'.jpg" alt=" " />\';
                            break;
                        } else if($imageCat == "Energy") {
    
                            echo \'<img src="\';
                            echo bloginfo(\'template_url\');
                            echo \'/images/energy-pic-\';
                            echo rand(1,3);
                            echo \'.jpg" alt=" " />\';
                            break;
                        } else if($imageCat == "Health") {
    
                            echo \'<img src="\';
                            echo bloginfo(\'template_url\');
                            echo \'/images/health-pic-\';
                            echo rand(1,3);
                            echo \'.jpg" alt=" " />\';
                            break;
                        } else if ($imageCat == "People" || $imageCat == "Communities") {
    
                            echo \'<img src="\';
                            echo bloginfo(\'template_url\');
                            echo \'/images/people-pic-\';
                            echo rand(1,3);
                            echo \'.jpg" alt=" " />\';
                            break;
                        } else if ($imageCat == "Events") {
    
                            echo \'<img src="\';
                            echo bloginfo(\'template_url\');
                            echo \'/images/twitter-bg-\';
                            echo rand(1,3);
                            echo \'.jpg" alt=" " />\';
                            break;
                        } else {
    
    
                            echo \'<img src="\';
                            echo bloginfo(\'template_url\');
                            echo \'/images/generalcals-bg-\';
                            echo $i;
                            echo \'.jpg" alt=" " />\';
                            if($i < 5) {
                                $i = $i + 1;
                            } else {
                                $i = 1;
                            }
                            break;
                        }
    
    
    
                    }*/
    
    
                }
                echo \'</div>\';
    
                    echo \'<div class="text"><div class="glyph"><div class="symbol"></div></div><div class="titleheading"><h3>\';
                    $title = $item->get_title();
                    if($length != -1){
                        if(strlen($title)>$length){ 
                            echo substr($title,0,$length).\'...\'; } 
                        else { 
                            echo $title; 
                        }
                    } else { 
                        echo $title; 
                    }
                echo \'</h3></div><div class="excerpt">\';
                $content = $item->get_description(); 
                echo $content;
                echo \'</div><div class="dateheading">\';
                echo $item->get_date(\'F j, Y\');
                echo \'</div><div class="hiddendate">\';
                echo "-".$item->get_date(\'Ymd\');
                echo \'</div><div class="hiddengroup">\';
                $cattemp = $item->get_category();
                echo $cattemp->get_label();
                echo \'</div><span class="number">10</span></div>\';
    
    
    
    
    
            echo \'<a href="\';
            echo $item->get_permalink();
            echo \'" class="highlight" title="\';
            echo \'Posted \'.$item->get_date(\'j F Y | g:i a\');
            echo \'">Read more about \';
            echo $item->get_title();
            echo \'<div class="loadingSpinner"><div class="progress"></div></div></a></div></div>\';
    
    
            /*}  else {
    
                //What to display if no image is supplied by the article
    
                echo \'<div class="newsItem noImage \';
                    foreach ($item->get_categories() as $category)
                        {
                            echo $category->get_label()." ";
                        }
    
                    echo \'"><div class="previousa"><div class="titleheading"><h3>\';
                    $title = $item->get_title();
                    if($length != -1){
                        if(strlen($title)>$length){ 
                            echo substr($title,0,$length).\'...\'; } 
                        else { 
                            echo $title; 
                        }
                    } else { 
                        echo $title; 
                    }
                echo \'</h3></div><div class="text"><div class="glyph"><div class="symbol"></div></div><div class="excerpt">\';
                $content = $item->get_description(); 
                echo $content;
                echo \'</div><div class="dateheading">\';
                echo $item->get_date(\'F j, Y\');
                echo \'</div><div class="hiddendate">\';
                echo "-".$item->get_date(\'Ymd\');
                echo \'</div><div class="hiddengroup">\';
                $cattemp = $item->get_category();
                echo $cattemp->get_label();
                echo \'</div><span class="number">10</span></div><div class="additionalContent">\';
    
    
    
    
    
    
    
    
    
            echo \'</div><a href="\';
            echo $item->get_permalink();
            echo \'" class="highlight" title="\';
            echo \'Posted \'.$item->get_date(\'j F Y | g:i a\');
            echo \'">Read more about \';
            echo $item->get_title();
            echo \'<div class="loadingSpinner"><div class="progress"></div></div></a></div></div>\';
    
    
            }*/
             ?>
    
    
    
    
            <?php }
        }
    
    } else {
    
        return $rss_items;
    
    }
    }
    
    /*function soilsextension_enqueue_scripts(){
     $handle = \'soilsextension_scripts\';
     $src = get_theme_root_uri() . \'/soilsextension/js/min/master.min.js\';
    
    wp_register_script($handle, $src, false, false, true);
    
    wp_enqueue_script(\'soilsextension_scripts\');
    }
    
    add_action(\'wp_enqueue_scripts\', \'soilsextension_enqueue_scripts\'); */
    
    活动插件:这些是我测试期间的活动插件。

    Production: 高级自定义字段版本4.3.5(http://www.advancedcustomfields.com/), 自定义帖子类型UI版本0.8.2(http://webdevstudios.com/plugin/custom-post-type-ui/), 事件管理器版本5.5.2(http://wp-events-plugin.com/), WP Super Cache 1.4版(http://wordpress.org/plugins/wp-super-cache/)

    Localhost Active plugins: 高级自定义字段版本4.3.4(http://www.advancedcustomfields.com/), 自定义帖子类型UI版本0.8.2(http://webdevstudios.com/plugin/custom-post-type-ui/)

    <小时>Attempted Solutions:我尝试了两个案例并记录了结果,试图了解原因。

    Case 1.

    正在删除函数顶部的html注释。php

    Localhost: 不存在“白屏问题”。“媒体库问题”,不存在。

    Production: “白屏问题”和“媒体库问题”都存在。

    Case 2.

    在函数顶部保留html注释。php,但正在删除函数cals\\u feed\\u fetch2

    Localhost: 不存在“白屏问题”。存在“媒体文件问题”。

    Production: 存在“白屏问题”。存在媒体文件问题

    结论:虽然我似乎已经通过删除函数中的所有内容解决了问题。php,我不知道我的原始函数是什么部分。php导致了这些问题。

2 个回复
SO网友:TheDeadMedic

第一行只是PHP范围之外的HTML注释。它会输出每一个响应,并产生你正在经历的各种头痛。

解决方案删除它,或将其作为PHP注释:

<?php    
/* In a child theme, all of the functions of the parent theme are present, unless   overridden here */
您还应该确保PHP标记的两侧都没有空格,如下所述here.

SO网友:mohammad

对于wordpress中的显示介质问题,您必须:

删除php标记之间的注释,如下所示

<?php some functions ?>
指南注释行-->此部分导致媒体不显示

<?php more functions ?>
我希望这对每个有问题的人都有用

结束

相关推荐

使用主题文件夹代替plugins_url

我想这很简单,但我无法解决。我正在尝试通过我的主题向WordPress仪表板添加菜单页。我有以下。。。add_menu_page( \'Test\', \'Test\', \'manage_options\', \'myplugin/myplugin-admin.php\', \'\', plugins_url( \'myplugin/image/icon.png\' ), 6 &