Php Wordpress";do“u shortcode”;在自定义页面模板中
我正在尝试使用这个插件的一个短代码创建一个自定义页面模板 快捷码是“[shiftcontroller]”,它带有一个location属性,因此您可以像这样显示特定位置的班次:“[shiftcontroller location=“2”]”,其中2是位置id。我添加了一个名为“locationid”的自定义用户字段因此,我可以将该值与短代码一起使用,以仅显示当前用户特定位置的班次 这是迄今为止我的页面模板代码:Php Wordpress";do“u shortcode”;在自定义页面模板中,php,wordpress,shortcode,Php,Wordpress,Shortcode,我正在尝试使用这个插件的一个短代码创建一个自定义页面模板 快捷码是“[shiftcontroller]”,它带有一个location属性,因此您可以像这样显示特定位置的班次:“[shiftcontroller location=“2”]”,其中2是位置id。我添加了一个名为“locationid”的自定义用户字段因此,我可以将该值与短代码一起使用,以仅显示当前用户特定位置的班次 这是迄今为止我的页面模板代码: <?php /* Template name: Custom Shift Con
<?php
/*
Template name: Custom Shift Controller Page
*/
get_header(); ?>
<?php do_action( 'flatsome_before_page' ); ?>
<div id="content" role="main" class="content-area">
<?php while ( have_posts() ) : the_post(); ?>
<?php
$client_user = wp_get_current_user();
$user_id = $client_user->ID;
$key = 'locationid';
$single = true;
$client_location_id = get_user_meta( $user_id, $key, $single );
echo '<h2 class="" style="text-align: center;">Manage, view and book shifts</h2>';
echo '<h1>The Client Location ID: ' . $client_location_id . '</h1>';
echo do_shortcode('[shiftcontroller location="' . $client_location_id . '"]');
// echo do_shortcode('[shiftcontroller]');
// echo apply_filters( 'the_content', '[shiftcontroller]');
?>
<?php endwhile; // end of the loop. ?>
</div>
<?php do_action( 'flatsome_after_page' ); ?>
<?php get_footer(); ?>
我正在回显h1,以便确认位置id,并且它工作正常。但是,应该显示的轮班日历根本不显示。即使没有我的自定义locationid代码,也只需echo do_短代码(“[shiftcontroller]”)代码>仍不显示日历
你知道为什么短码不起作用吗?轮班日历使用AJAX,但我不知道这是否会导致问题。谢谢在注释的代码中,您就快到了。您只需应用正确的过滤器。而不是使用echo do_shortcode()代码>,请尝试:
echo apply_filters('the_content', '[shiftcontroller location="' . $client_location_id . '"]');
谢谢你的回复。只是试了一下,但没用。即使没有locationid,echo应用过滤器('the_content','shiftcontroller')代码>仍然不起作用。由于某种原因,短代码根本没有被计算/显示。如果通过ajax加载内容,您可以检查页面上是否收到任何javascript错误吗?如果do\u短代码
和apply\u过滤器
不起作用,它们将以纯文本形式返回短代码。i、 e.“[shiftcontroller location=“XXX”]”在页面内容中。这表明存在一个外部问题(即,与如何调用短代码无关)。我建议检查您的短代码使用的javascript文件是否正在加载到页面上,然后从那里开始。祝你好运我想你可能对插件的js文件有所了解。让我从那个洞下去。谢谢你的帮助。非常感谢我检查过了,我的自定义模板上没有调用js文件。我知道这偏离了最初的问题,但有没有一种方法可以从不同的插件调用一个插件的文件?再次感谢