激活自定义插件后无法使用 Elementor 进行编辑,找不到内容区域

问题描述 投票:0回答:3

我制作了一个自定义插件,它使用自定义帖子类型的数据创建一个表。我正在使用“The Gem”主题,此问题仅特定于此页面(未使用不同的模板)。当我激活此插件时,我无法“使用 Elementor 编辑”并在尝试时收到以下消息: 抱歉,在您的页面中找不到内容区域。您必须在当前模板中调用“the_content”函数,Elementor 才能在此页面上工作。

激活插件后,它不会破坏页面,我只是无法使用 Elementor 编辑页面。我可以停用它并返回 Elementor。我尝试添加 the_content();进入我的插件,但这不起作用。我认为这是插件代码中的某些内容,因为如果我只是回显“Hello World!”没有问题,我可以返回 Elementor 编辑器。编辑以包含以下完整插件代码:

function queryGrantPosts() {
    // the args
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $args = array(
        'post_type' => 'grants',
        'posts_per_page' => '10',
        'paged' => $paged,
        'orderby' => 'title',
        'order' => 'ASC',
    );
    $args['search_filter_id'] = 1350;

    $myPosts = new WP_Query($args) ;
    return $myPosts ;
}

function createTableEndHTML(){
    $myHTML = '';
    $myHTML .= '    </table>';
    $myHTML .= '</div>';
    $myHTML .= '<div class="pagination">';
    $myHTML .= '    <?php the_custom_pagination( $the_query); ?>';
    $myHTML .= '</div>';
    return $myHTML;
                
}
function createTableStartHTML(){
    $myHTML = '';

    $myHTML .= '<div class="table-wrap">';
    $myHTML .= '    <table class="grants-list">';
    $myHTML .= '            <thead class="grants-listing">';
    $myHTML .= '                    <th width="33%">Organization,<br>Program Name</th>';
    $myHTML .= '                    <th width="10%">City,<br>Location</th>';
    $myHTML .= '                    <th width="8%">Amount</th>';
    $myHTML .= '                    <th width="5%">Life Cycle (months)</th>';
    $myHTML .= '                    <th width="25%">Counties Served</th>';
    $myHTML .= '            </thead>';
    return $myHTML;
}

function createTableContentHTML($pPosts){
    $myHTML = '';

    // the loop 
    while ( $pPosts->have_posts() ) : $pPosts->the_post(); 
        $number = get_field('amount_num'); 
        $amount = number_format($number);
        $programName = get_field('program_name');
        $organizationCity = get_field('organization_city');
        $geographicLocation = get_field('geographic_location');
        $grantLifeCycle = get_field('grant_life_cycle');
        $myTerms = get_the_terms(get_the_ID(), 'counties_served');
        if ( $myTerms && ! is_wp_error($myTerms) ) {
            $myTermList = join(', ', wp_list_pluck($myTerms, 'name'));
        }
                    
        $myHTML .= '<tr class="grants-listing">';
        $myHTML .= '    <td class="program-name">';
        $myHTML .= '        <span style="font-family: Gotham Bold, sans-serif;">' . get_the_title() . '</span></br>' ;
        $myHTML .= $programName . '</td>';
        $myHTML .= '    <td>' . $organizationCity . '<br><em>' . $geographicLocation . '</em></td>';
        $myHTML .= '    <td>' . $amount . '</td>';
        $myHTML .= '    <td>' . $grantLifeCycle . '</td>';
        $myHTML .= '    <td>';
        $myHTML .= $myTermList;

        $myHTML .= '    </td>';
        $myHTML .= '</tr>';         
    endwhile; 
    
    return $myHTML;

}

function createTablePagination($pPosts){
    $myHTML = '';
    $myHTML .= '<div class="gem-pagination">';
    $myHTML .= the_custom_pagination( $pPosts ); 
    $myHTML .= '</div>';
    return $myHTML;
}
the_content(); 
add_shortcode('bpr_grant_table', 'createGranteeTable');
function createGranteeTable(){
    $myPosts = queryGrantPosts();
    echo createTableStartHTML();
    echo createTableContentHTML($myPosts);
    echo createTableEndHTML();
    if (function_exists( 'the_custom_pagination' ) ) {
        createTablePagination($myPosts);
    } else {
        echo 'function not found';
    }
}

有什么想法吗?我是否错误地调用了该函数或在错误的位置?

php wordpress plugins elementor
3个回答
1
投票

解决问题的方法有多种。

您或主题的开发人员是否为您的主题创建了不包含

the_content
功能的自定义 WordPress 页面模板?您需要在代码中包含 the_content 才能使用 Elementor 进行编辑或切换到不同的主题,这通常可以解决问题。首先,尝试切换到“Hello”之类的主题,看看您的问题是否得到解决。如果您是 Web 开发人员并且正在开发主题,请将 the_content 函数添加到页面模板的代码中。这是您需要添加的行:
<?php the_content(); ?>
如果您不熟悉此代码的放置位置或如何将其添加到页面,请联系您的网站开发人员,以便它可以正确实施,因为我们无法提供全面支持那。请注意,添加此代码不会启用存档页面和最新帖子页面的编辑(这些页面必须通过 Elementor 的主题构建器进行编辑),而且非常简单。

欲了解更多信息,请阅读文章:

https://elementor.com/help/the-content-area-was-not-found-error/

https://kinsta.com/knowledgebase/you-must-call-the-content-function-elementor/

谢谢你


1
投票

更新!找到这段代码为我解决了问题。如果我将此代码放在查询之前

$wp_query = null;
$wp_query = new WP_Query($args);

循环后的代码

$wp_query = null;
wp_reset_query();

然后我就不再收到 Elementor 错误了。


0
投票

注意:未定义索引:custom_css位于/home/jhoster/public_html/wp-content/plugins/elementpress/elementpress.php第322行

© www.soinside.com 2019 - 2024. All rights reserved.