【问题标题】:WordPress Error: Warning Illegal OffsetWordPress 错误:警告非法偏移
【发布时间】:2015-03-07 20:31:21
【问题描述】:

我在 wordpress 上的目录网站上工作,当我尝试搜索选项时出现此错误:

警告:第 27 行 /home/dalilouk/public_html/wp-content/themes/directory/header.php 中的非法字符串偏移“字段”

警告:第 33 行 /home/dalilouk/public_html/wp-content/themes/directory/header.php 中的非法字符串偏移“字段”

而且搜索的结果总是“没有找到”。

这是第 27 行 header.php 的代码:

<script type="text/javascript">            #line 27
jQuery(document).ready(function($) {

    {ifset $themeOptions->search->searchCategoriesHierarchical}
    var categories = [ {!$categoriesHierarchical} ];
    {else}
    var categories = [                #line 33
    {foreach $categories as $cat}
        { value: {$cat->term_id}, label: {$cat->name} }{if !($iterator->last)},{/if}
    {/foreach}
    ];
    {/ifset}

    {ifset $themeOptions->search->searchLocationsHierarchical}
    var locations = [ {!$locationsHierarchical} ];
    {else}
    var locations = [
    {foreach $locations as $loc}
        { value: {$loc->term_id}, label: {$loc->name} }{if !($iterator->last)},{/if}
    {/foreach}
    ];
    {/ifset}

    var catInput = $( "#dir-searchinput-category" ),
        catInputID = $( "#dir-searchinput-category-id" ),
        locInput = $( "#dir-searchinput-location" ),
        locInputID = $( "#dir-searchinput-location-id" );

    catInput.autocomplete({
        minLength: 0,
        source: categories,
        focus: function( event, ui ) {
            var val = ui.item.label.replace(/&amp;/g, "&");
                val = val.replace(/&nbsp;/g, " ").replace(/&#039;/g, "'");
            catInput.val( val );
            return false;
        },
        select: function( event, ui ) {
            var val = ui.item.label.replace(/&amp;/g, "&");
                val = val.replace(/&nbsp;/g, " ").replace(/&#039;/g, "'");
            catInput.val( val );
            catInputID.val( ui.item.value );
            return false;
        }
    }).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
        return $( "<li>" )
            .data( "item.autocomplete", item )
            .append( "<a>" + item.label + "</a>" )
            .appendTo( ul );
    };
    var catList = catInput.autocomplete( "widget" );
    catList.niceScroll({ autohidemode: false });

    catInput.click(function(){
        catInput.val('');
        catInputID.val('0');
        catInput.autocomplete( "search", "" );
    });

    locInput.autocomplete({
        minLength: 0,
        source: locations,
        focus: function( event, ui ) {
            var val = ui.item.label.replace(/&amp;/g, "&");
                val = val.replace(/&nbsp;/g, " ").replace(/&#039;/g, "'");
            locInput.val( val );
            return false;
        },
        select: function( event, ui ) {
            var val = ui.item.label.replace(/&amp;/g, "&");
                val = val.replace(/&nbsp;/g, " ").replace(/&#039;/g, "'");
            locInput.val( val );
            locInputID.val( ui.item.value );
            return false;
        }
    }).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
        return $( "<li>" )
            .data( "item.autocomplete", item )
            .append( "<a>" + item.label + "</a>" )
            .appendTo( ul );
    };
    var locList = locInput.autocomplete( "widget" );
    locList.niceScroll({ autohidemode: false });

    locInput.click(function(){
        locInput.val('');
        locInputID.val('0');
        locInput.autocomplete( "search", "" );
    });


    {ifset $_GET['dir-search']}
    // fill inputs with search parameters
    $('#dir-searchinput-text').val({$searchTerm});
    catInputID.val({$_GET["categories"]});
    for(var i=0;i<categories.length;i++){
        if(categories[i].value == {$_GET["categories"]}) {
            var val = categories[i].label.replace(/&amp;/g, "&");
                val = val.replace(/&nbsp;/g, " ").replace(/&#039;/g, "'");
            catInput.val(val);
        }
    }
    locInputID.val({$_GET["locations"]});
    for(var i=0;i<locations.length;i++){
        if(locations[i].value == {$_GET["locations"]}) {
            var val = locations[i].label.replace(/&amp;/g, "&");
                val = val.replace(/&nbsp;/g, " ").replace(/&#039;/g, "'");
            locInput.val(val);
        }
    }
    {/ifset}

});
</script>

请帮我解决这个问题。

【问题讨论】:

    标签: javascript php wordpress warnings


    【解决方案1】:

    它不是 PHP 源代码。您刚刚在浏览器中打开了该 php,因此您发布的是该 PHP 脚本输出。您必须在某个编辑器中打开真正的 .php 文件,并向我们展示源代码:)

    根据您的问题 - 这不是错误,它是关于调用变量的警告,该变量未在某些时候设置。所以你的脚本仍然有效,但可能你的表单有错误的字段名称要发送,所以你的 php 脚本无法找到你想要搜索的数据,因为找不到那个特定的变量。

    【讨论】:

    • 感谢您的回复,很抱歉我是新手,您能告诉我如何找到这个 .php 文件吗?
    • 您将应用程序(大量 .php 文件)部署到您的服务器,可能是通过 ftp/sftp :) 所以,您也可以从您的 ftp/sftp 下载它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多