【问题标题】:Modifying single.php on child theme "Mikado Newsflash"修改子主题“Mikado Newsflash”上的 single.php
【发布时间】:2021-10-09 23:30:38
【问题描述】:

我有一个带有“Mikado Newsflash”主题和自定义子主题的网站。我可以在子主题上添加功能,但是如果我修改 single.php,我不会得到任何结果。即使我删除了主题上的代码,它仍然有效。它在其他地方被调用吗?我已经修改了 framework/modules/blog/templates/singles 等核心模板,但没有结果。关于如何覆盖 single.php 的任何线索?

这是 single.php 主题文件:

    <?php
get_header();
newsflash_mikado_get_title();
get_template_part( 'slider' );

if ( have_posts() ) : while ( have_posts() ) : the_post();
    //Get blog single type and load proper helper
    newsflash_mikado_include_blog_helper_functions( 'singles', 'standard' );
    
    //Action added for applying module specific filters that couldn't be applied on init
    do_action( 'newsflash_mikado_blog_single_loaded' );
    
    //Get classes for holder and holder inner
    $mkdf_holder_params = newsflash_mikado_get_holder_params_blog();
    ?>
    
    <div class="<?php echo esc_attr( $mkdf_holder_params['holder'] ); ?>">
        <?php do_action( 'newsflash_mikado_after_container_open' ); ?>
        
        <div class="<?php echo esc_attr( $mkdf_holder_params['inner'] ); ?>">
            <?php newsflash_mikado_get_blog_single( 'standard' ); ?>
        </div>
        
        <?php do_action( 'newsflash_mikado_before_container_close' ); ?>
    </div>
<?php endwhile; endif;
get_footer(); ?>

【问题讨论】:

    标签: php wordpress wordpress-theming themes child-theming


    【解决方案1】:

    大多数情况下,对模板文件的编辑没有改变任何内容是因为您更改了错误的文件。

    将此代码添加到主题的 functions.php 文件中:

    functions.php

    function cagb_which_template_is_loaded() {
        if ( is_super_admin() ) {
            $categories = get_the_category();
            //$category_id = $categories[0]->cat_ID;
            echo '<div style="margin-top:25px;" id="my-debug">';
            global $template;
            print_r( $template );
            echo ' | ' . get_the_ID();
            echo ' | ' . $categories;
            echo "</div>";
        }
    }
     
    add_action( 'wp_footer' , 'cagb_which_template_is_loaded');
    

    登录后,此插件将在页面底部添加额外信息(用于调试),当您加载主页(或任何其他页面)时,它将显示如下内容: /www/public_html/wp-content/themes/mikado-newsflash/homepage.php

    这样您就可以知道加载了模板的哪个文件,然后您就可以对其进行编辑了。

    【讨论】:

    • 哇,这会非常方便。太感谢了。它实际上在一个插件文件中:/wp-content/plugins/mikado-news/modules/blog/news-single.php | 161758 |数组
    • 很高兴它对你有用!使用此功能,您可以跟踪页面或帖子输出中涉及的每个模板文件
    猜你喜欢
    • 2016-09-06
    • 2013-04-06
    • 1970-01-01
    • 2020-06-14
    • 2012-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-21
    相关资源
    最近更新 更多