如何在unctions.php文件中调用特定值?

时间:2011-11-18 作者:AHCo

大家好,我是这里的新手,但希望有人能回答我的问题

在我的职能范围内。php文件,我有以下代码:

//Contractor Page meta box details
$contractorpage_meta_box=array();
$contractorpage_meta_box[]=array(
    \'id\'=>\'contractor-page-meta-box\',
    \'title\'=>\'Contractor Page Details\',
    \'page\'=>\'contractor-page\',
    \'context\'=>\'normal\',
    \'priority\'=>\'high\',
    \'fields\'=>array(
            array(
                \'id\'=>"header_link_heading1",
                \'label\'=>"First Header Link Heading",
                \'name\'=>"header_link_heading1",
                \'type\'=>"text"
            ),
            array(
                \'id\'=>"header_link_text1",
                \'label\'=>"First Header Link Text",
                \'name\'=>"header_link_text1",
                \'type\'=>"text"
            ),
            array(
                \'id\'=>"header_link_url1",
                \'label\'=>"First Header Link Url",
                \'name\'=>"header_link_url1",
                \'type\'=>"text"
            ),
            array(
                \'id\'=>"header_link_heading2",
                \'label\'=>"Second Header Link Heading",
                \'name\'=>"header_link_heading2",
                \'type\'=>"text"
            ),
            array(
                \'id\'=>"header_link_text2",
                \'label\'=>"Second Header Link Text",
                \'name\'=>"header_link_text2",
                \'type\'=>"text"
            ),array(
                \'id\'=>"header_link_url2",
                \'label\'=>"Second Header Link Url",
                \'name\'=>"header_link_url2",
                \'type\'=>"text"
            ),array(
                \'id\'=>"page_heading",
                \'label\'=>"Page Heading",
                \'name\'=>"page_heading",
                \'type\'=>"text"
            ),array(
                \'id\'=>"page_sub_heading",
                \'label\'=>"Page Sub Heading",
                \'name\'=>"page_sub_heading",
                \'type\'=>"text"
            ),array(
                \'id\'=>"first_intro_text",
                \'label\'=>"First Intro Text",
                \'name\'=>"first_intro_text",
                \'type\'=>"text"
            ),array(
                \'id\'=>"second_intro_text",
                \'label\'=>"Second Intro Text",
                \'name\'=>"second_intro_text",
                \'type\'=>"text"
            ),array(
                \'id\'=>"video_link",
                \'label\'=>"Video link",
                \'name\'=>"video_link",
                \'type\'=>"text"
            ),array(
                \'id\'=>"main_content_heading",
                \'label\'=>"Main Content Heading",
                \'name\'=>"main_content_heading",
                \'type\'=>"text" 
            ),array(
                \'id\'=>"main_content_text",
                \'label\'=>"Main Content",
                \'name\'=>"main_content_text",
                \'type\'=>"wysiwyg"
            ),array(
                \'id\'=>"bottom_heading",
                \'label\'=>"Bottom Heading",
                \'name\'=>"bottom_heading",
                \'type\'=>"text"
            ),array(
                \'id\'=>"bottom_content",
                \'label\'=>"Bottom Content",
                \'name\'=>"bottom_content",
                \'type\'=>"text"
            ),array(
                \'id\'=>"bottom_link_text",
                \'label\'=>"Bottom Link Text",
                \'name\'=>"bottom_link_text",
                \'type\'=>"text"
            ),array(
                \'id\'=>"bottom_link_url",
                \'label\'=>"Bottom Link Url",
                \'name\'=>"bottom_link_url",
                \'type\'=>"text"
            ),array(
                \'id\'=>"right_first_line",
                \'label\'=>"First Line Right Column",
                \'name\'=>"right_first_line",
                \'type\'=>"text"
            ),array(
                \'id\'=>"right_last_line",
                \'label\'=>"Last Line Right Column",
                \'name\'=>"right_last_line",
                \'type\'=>"text"
            )
        )
);
我还有以下代码:

// Embed YouTube videos with "youtube" shortcode

function youtube($atts) {
    extract(shortcode_atts(array(
        "value" => \'\',
        "width" => \'475\',
        "height" => \'350\',
        "name"=> \'movie\',
        "allowFullScreen" => \'true\',
        "allowScriptAccess"=>\'always\',
    ), $atts));
    return \'<object style="height: \'.$height.\'px; width: \'.$width.\'px"><param name="\'.$name.\'" value="\'.$value.\'"><param name="allowFullScreen" value="\'.$allowFullScreen.\'"></param><param name="allowScriptAccess" value="\'.$allowScriptAccess.\'"></param><embed src="\'.$value.\'" type="application/x-shockwave-flash" allowfullscreen="\'.$allowFullScreen.\'" allowScriptAccess="\'.$allowScriptAccess.\'" width="\'.$width.\'" height="\'.$height.\'"></embed></object>\';
}
add_shortcode("youtube", "youtube");
我正在尝试将第一个代码中的“video\\u link”放入第二个代码中的“value”(其中表示“WHAT-to-PUT-HERE”)。

任何帮助都将不胜感激。

1 个回复
最合适的回答,由SO网友:Ijaas 整理而成
function youtube($atts) {

    global $post;
    $value = get_post_meta($post->ID, \'video_link\', true);

    extract(shortcode_atts(array(    //Make sure not to include the \'value\' as part of this array. 
        "width" => \'475\',
        "height" => \'350\',
        "name"=> \'movie\',
        "allowFullScreen" => \'true\',
        "allowScriptAccess"=>\'always\',
    ), $atts));
    return \'<object style="height: \'.$height.\'px; width: \'.$width.\'px"><param name="\'.$name.\'" value="\'.$value.\'"><param name="allowFullScreen" value="\'.$allowFullScreen.\'"></param><param name="allowScriptAccess" value="\'.$allowScriptAccess.\'"></param><embed src="\'.$value.\'" type="application/x-shockwave-flash" allowfullscreen="\'.$allowFullScreen.\'" allowScriptAccess="\'.$allowScriptAccess.\'" width="\'.$width.\'" height="\'.$height.\'"></embed></object>\';

}
结束

相关推荐

Custom admin post.php page

我正在做一个CPT,但我需要对发布/编辑页面(post-new.php和post.php)的布局有更多的控制。我认为通过admin\\u init进行黑客攻击是最好的选择,但我根本无法让脚本正常工作。帮助function init_shelf_page() { if (!current_user_can(\'edit_shelves\') && $_SERVER[\'PHP_SELF\'] == \'/wp-admin/post.php\') { i