如何使用子主题替换函数?

时间:2015-06-07 作者:cmsdeployed

我有以下功能,我想替换图像nopic。jpg公司

我已通过删除一些冗余选项进行了更新。

    if ( ! function_exists( \'TaskerDev_get_first_post_image_fnc\' ) ) :
            function TaskerDev_get_first_post_image_fnc($pid, $w = 100, $h = 100) {

                //---------------------
                // build the exclude list
                $exclude = array();

                $args = array(
                \'order\'          => \'ASC\',
                \'post_type\'      => \'attachment\',
                \'post_parent\'    => $pid,
                \'meta_key\'       => \'another_reserved1\',
                \'meta_value\'     => \'1\',
                \'numberposts\'    => -1,
                \'post_status\'    => null,
                );
                $attachments = get_posts($args);
                if ($attachments) {
                        foreach ($attachments as $attachment) {
                        $url = $attachment->ID;
                        array_push($exclude, $url);
                    }
                }

                //-----------------

                $args = array(
                \'order\'          => \'ASC\',
                \'orderby\'        => \'post_date\',
                \'post_type\'      => \'attachment\',
                \'post_parent\'    => $pid,
                \'exclude\'           => $exclude,
                \'post_mime_type\' => \'image\',
                \'post_status\'    => null,
                \'numberposts\'    => 1,
                );
                $attachments = get_posts($args);
                if ($attachments) {
                    foreach ($attachments as $attachment) {
                        //$url = wp_get_attachment_url($attachment->ID);
                        return TaskerDev_wp_get_attachment_image($attachment->ID, \'thumb_image_thing\');
                    }
                }
                #else   return get_bloginfo(\'template_url\').\'/images/nopic.jpg\';
                else    return get_stylesheet_directory_uri().\'/images/Picture16.jpg\';
            }
            /*************************************************************
            //*
            *   TaskerDev (c) sitemile.com - function
            /
            *************************************************************/
        endif;
完成后,一切正常工作大约一个小时,然后出现以下错误:

函数TaskerDev\\u get\\u first\\u post\\u image\\u fnc()不能调用两次,它已经在父级中被调用(只是分段描述它所说的内容)

通过在子主题中调用图像,更新图像最有效的方法是什么。是否有短钩或动作?谢谢

1 个回复
SO网友:Wali Hassan

您应该像这样将函数包装在父主题中,而不是子主题函数中。php

if (!function_exists(\'TaskerDev_get_first_post_image_fnc\') ){
function TaskerDev_get_first_post_image_fnc($pid, $w = 100, $h = 100)
    {
//Parent theme code here
 }
}

结束

相关推荐

使用快速编辑更新POST时,POST_ROW_ACTIONS过滤器不工作

我使用post\\u row\\u操作创建了两个链接,页面加载时显示良好。但使用快速编辑更新帖子后,链接将消失。是WordPress的bug还是我错过了什么。我的代码如下所示。add_filter(\'post_row_actions\', \'add_new_link\', 10, 2); public function add_new_link($actions, $page_object) { $actions[\'new_action\'] = \'<