如何删除子主题中的set_POST_THMBABILE_SIZE()?

时间:2011-02-01 作者:Osu

我真的被困在这一点上了-下面是这篇文章:

How to override parent functions in child themes

我不知道如何重写二十个十的set\\u post\\u thumbnail\\u size()函数。我在下面列出了我正在执行的其他重写的代码,但当我将其添加到函数twentyten\\u child\\u theme\\u setup()时,什么都没有发生:

set_post_thumbnail_size( array(100,100) , array("class" => "alignleft post_thumbnail"), true );
我在循环中插入缩略图,如下所示:

<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) {
the_post_thumbnail(array(100,100), array("class" => "alignleft post_thumbnail"));
} else { ?>
<img src="<?php echo bloginfo(\'stylesheet_directory\'); ?>/images/thumb-default.jpg" alt="thumb-default" width="100" height="100" />
<?php } ?>
下面是我的函数-有人能帮我重写这个讨厌的函数吗?

谢谢

osu

function twentyten_child_theme_setup() {

    // OVERRIDE SIDEBAR GENERATION!
    function osu_twentyten_widgets_init() {
        // Siedbar 1, located on LHS sidebar
        register_sidebar( array(
            \'name\' => __( \'Primary Widget Area\', \'twentyten-child\' ),
            \'id\' => \'primary-widget-area\',
            \'description\' => __( \'The primary widget area where the navigation goes\', \'twentyten-child\' ),
            \'before_widget\' => \'<li id="%1$s" class="widget-container %2$s">\',
            \'after_widget\' => \'</li>\',
            \'before_title\' => \'<h3 class="widget-title">\',
            \'after_title\' => \'</h3>\',
        ) );
        // Area 2, located on RHS sidebar
        register_sidebar( array(
            \'name\' => __( \'Secondary Widget Area\', \'twentyten-child\' ),
            \'id\' => \'secondary-widget-area\',
            \'description\' => __( \'The secondary widget area\', \'twentyten-child\' ),
            \'before_widget\' => \'<li id="%1$s" class="widget-container %2$s">\',
            \'after_widget\' => \'</li>\',
            \'before_title\' => \'<h3 class="widget-title">\',
            \'after_title\' => \'</h3>\',
        ) );
    }
    /* Deregister sidebar in parent */
    remove_action( \'widgets_init\', \'twentyten_widgets_init\' );
    /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
    add_action( \'widgets_init\', \'osu_twentyten_widgets_init\' );

    // OVERRIDE EXCERPT READ MORE LINK
    function osu_readon_link() {
        return \' <a href="\'. get_permalink() . \'" class="readmore">\' . __( \'Read More\', \'twentyten-child\' ) . \'</a>\';
    }
    // Function to override
    function osu_twentyten_custom_excerpt_more( $output ) {
        if ( has_excerpt() && ! is_attachment() ) {
            $output .= osu_readon_link();
        }
        return $output;
    }
    remove_filter( \'get_the_excerpt\', \'twentyten_custom_excerpt_more\' );
    add_filter( \'get_the_excerpt\', \'osu_twentyten_custom_excerpt_more\' );

}
/* IMPORTANT: Run the code for parent function overrides (involving hooks and filters) after theme setup! */
add_action( \'after_setup_theme\', \'twentyten_child_theme_setup\' );

1 个回复
最合适的回答,由SO网友:Rarst 整理而成

你所说的什么都没发生是什么意思?

从技术上讲,您不需要删除set_post_thumbnail_size(), 正如我从代码中所理解的,稍后只需进行自己的调用就会覆盖大小。

有两种方法可以处理此问题:

将设置功能调整到以后的优先级。子主题在父主题之前处理。因此,当您使用默认优先级挂接时,设置函数也会按该顺序执行。所以add_action( \'after_setup_theme\', \'twentyten_child_theme_setup\', 11 );

插上自己的插头twentyten_setup() 作用它被包裹在if ( ! function_exists( \'twentyten_setup\' ) ) 情况在2010年。因此,只需将其复制到您的主题并进行所需的更改,即可运行您的版本而不是原始版本。

结束

相关推荐

获取在Functions.php中设置的变量,并在我的Custom Post模板中回显它们

在我的函数中设置了以下函数。php文件,以允许我的自定义帖子类型“Slideshow”工作。add_action( \'the_post\', \'paginate_slide\' ); function paginate_slide( $post ) { global $pages, $multipage, $numpages; if( is_single() && get_post_type() == \'lom_s