1
嗨我在wordpress中使用会话来获取会话中的模板部分。我是新来的PHP,不知道如何解决。在wordpress中使用会话只能获取模板一次
使用下面的代码拉一次模板部分,只使用第一个会话。 它只拉一次,但当我刷新页面时,它返回空白 我该如何解决它?
<!-- Main file -->
<div class="container">
<div class="row">
<?php
if(!isset($_SESSION['function_ran'])){
get_template_part('parts/template-part');
$_SESSION['function_ran'] = true;
}
?>
</div>
</div>
<!-- Main file -->
Below is the template part im am trying to pull only once during the session
[ parts/template-part ]
<div class="col-md-4">
<div class="fgfgfg">
</div>
</div>
进一步添加的代码在function.php
function register_my_session()
{
if(!session_id())
{
session_start();
}
}
add_action('init', 'register_my_session');
请提供更多的细节和代码? – C2486
更新了代码 – Naob