我试图使用以下方法将函数的输出连接到帖子内容:
function bottom_content($content) {
global $post;
$content .= course_resources($post->ID);
return $content;
}
add_filter(\'the_content\', \'bottom_content\');
function course_resources($id) {
$course = get_post_meta($id);
$course[\'wpcw_associated_module\'][0];
global $wpdb;
// query for parent_id
$course_id = $wpdb->get_row(\'SELECT \'.$wpdb->prefix.\'wpcw_courses.course_id FROM \'.$wpdb->prefix.\'wpcw_modules INNER JOIN \'.$wpdb->prefix.\'wpcw_courses ON \'.$wpdb->prefix.\'wpcw_modules.parent_course_id=\'.$wpdb->prefix.\'wpcw_courses.course_id WHERE \'.$wpdb->prefix.\'wpcw_modules.module_id =\'.$course["wpcw_associated_module"][0].\'\', ARRAY_A);
// $course_id = $wpdb->get_row(\'SELECT * FROM \'.$wpdb->prefix.\'wpcw_modules INNER JOIN \'.$wpdb->prefix.\'wpcw_courses ON \'.$wpdb->prefix.\'wpcw_modules.parent_course_id=\'.$wpdb->prefix.\'wpcw_courses.course_id WHERE \'.$wpdb->prefix.\'wpcw_modules.module_id =\'.$course["wpcw_associated_module"][0].\'\', ARRAY_A);
$upload_dir = wp_upload_dir();
$resource_path = $upload_dir["basedir"].\'/resources/Sharepoint-Videos-Resources-\'. $course_id["course_id"].\'.zip\';
if (file_exists($resource_path)) {
$resource_link = $upload_dir["baseurl"]. \'/resources/Sharepoint-Videos-Resources-\'. $course_id["course_id"].\'.zip\';
echo \'<div style="text-align:center;font-size:14px;background:#dedede;color:#777;border:1px solid #bbb;padding:20px 10px 20px;"><a href="\'. $resource_link .\'"><button style="font-size:16px;background:#4f8a3f;box-shadow:none;border:1px solid #3F803C;color:#f0f0f0;padding:10px 20px;"><i class="fa fa-download fa-1x"></i> Resource Files</button></a> </div>\';
}
}
期望的结果是
<div>
包含放置在帖子内容底部的按钮,但无论我为
add_filter
, 输出始终位于内容的顶部。
我错过了什么?