首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress在自定义模板中使用h5p短代码

Wordpress在自定义模板中使用h5p短代码
EN

Stack Overflow用户
提问于 2021-05-10 17:15:37
回答 1查看 45关注 0票数 1

我有一个自定义的显示模板,我们基本上是空白的。我希望能够传递一个简短的代码id给页面,让它显示,即h5p id="4“我可以很容易地在wordpress页面上做到这一点,但我希望单个页面显示不同的内容,这取决于用户之前选择的内容。而我必须为每个我不想要的交互创建一个自定义页面。

格式最终将是:

代码语言:javascript
复制
<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>

我试着用“

代码语言:javascript
复制
echo do_shortcode("[h5p id='1']");

但页面只是作为空白加载。没有错误消息。

我的实际代码看起来是这样的(不要笑-我不知道wordpress)

代码语言:javascript
复制
<?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>';
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-13 20:15:19

do_shortcode函数将用H5P的iframe的HTML语言替换短代码,但您必须添加一个

do_action( 'wp_footer' );

添加到您的模板中,例如在末尾。它通常在WordPress显示页脚时调用。

H5P将该操作解释为WordPress已完成构建post/页面的信号,H5P可以开始其工作:用生命实际填充H5P iframe。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67467781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档