我有一个自定义的显示模板,我们基本上是空白的。我希望能够传递一个简短的代码id给页面,让它显示,即h5p id="4“我可以很容易地在wordpress页面上做到这一点,但我希望单个页面显示不同的内容,这取决于用户之前选择的内容。而我必须为每个我不想要的交互创建一个自定义页面。
格式最终将是:
<html>
<body>
//GET THE H5P id based on previous engagement- this part I have, its just the display
Custom h5p block [h5p id="4"]
</body>
</html>我试着用“
echo do_shortcode("[h5p id='1']");但页面只是作为空白加载。没有错误消息。
我的实际代码看起来是这样的(不要笑-我不知道wordpress)
<?php
/*
Template Name: page_display
*/
global $wpdb;
//https://stackoverflow.com/questions/67467781/wordpress-use-h5p-short-code-within-custom-template
$template = str_replace( '%2F', '/', rawurlencode( get_template() ) );
$theme_root_uri = get_theme_root_uri( $template );
$template_dir_uri = "$theme_root_uri/$template";
$user_details_sql = 'SELECT
wp_users.user_nicename
FROM wp_users
WHERE id = ' . get_current_user_id();
$user_details_results = $wpdb->get_results($user_details_sql, OBJECT );
echo '<HTML>
<head>
<title>Archon Dashboard</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="' . $template_dir_uri . '/custom/style.css' . '">
</head>
<body class="w3-theme">';
foreach($user_details_results as $user_details_result){
echo 'Welcome back ' . $user_details_result->user_nicename . '<br />
<div class="w3-container">
<div align="center">';
echo do_shortcode("[h5p id='1']");
echo '
</div>';
}
echo '
</div>
</body>
</html>';发布于 2021-05-13 20:15:19
do_shortcode函数将用H5P的iframe的HTML语言替换短代码,但您必须添加一个
do_action( 'wp_footer' );
添加到您的模板中,例如在末尾。它通常在WordPress显示页脚时调用。
H5P将该操作解释为WordPress已完成构建post/页面的信号,H5P可以开始其工作:用生命实际填充H5P iframe。
https://stackoverflow.com/questions/67467781
复制相似问题