加入收藏 | 设为首页 | 会员中心 | 我要投稿 源码门户网 (https://www.92codes.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Php 如何在WordPress中从两个单独文件中的函数访问和编辑全局变量

发布时间:2022-12-03 11:03:08 所属栏目:PHP教程 来源:互联网
导读: Php 如何在WordPress中从两个单独文件中的函数访问和编辑全局变量
phpwordpressvariables
Php 如何在WordPress中从两个单独文件中的函数访问和编辑全局变量,php,wordpress,variables,globa

Php 如何在WordPress中从两个单独文件中的函数访问和编辑全局变量

phpwordpressvariables

Php 如何在WordPress中从两个单独文件中的函数访问和编辑全局变量,php,wordpress,variables,global,Php,Wordpress,Variables,Global,下面是我的快捷码函数的用法:这里我使用一个全局变量$displated\u posts\u idPHP超级全局变量,我想在另一个函数中访问和编辑它;我应该在另一个文件中重新申报吗function posts_mobile($atts){global $displayed_posts_ids;$html = "";if (rw_is_mobile()){$args = array('posts_per_page' =>

下面是我的快捷码函数的用法:

这里我使用一个全局变量

$displated\u posts\u id

,我想在另一个函数中访问和编辑它;我应该在另一个文件中重新申报吗

function posts_mobile($atts)
{
    global $displayed_posts_ids;
    $html = "";
    if (rw_is_mobile())
    {
        $args = array(
            'posts_per_page' => 5,
            'orderby' => 'date',
            'order' => 'DESC',
            'exclude' => array(get_the_id()),
        );
        $posts_array = get_posts($args);
        // var_dump($posts_array);
        $ids = get_the_id() . ",";
        if (count($posts_array) > 0)
        {
            $html .= "
"; $html .= "
"; foreach ($posts_array as $post) { $html .= show_post_selected($post->ID); $ids .= $post->ID . ","; } $html .= "
"; } $ids = rtrim($ids, ","); $displayed_posts_ids .= $ids; $html .=""; return $html; } }

任何帮助都将不胜感激。

谢谢。

如果您想在

ajax\u get\u other\u posts()

方法中访问

$displated\u posts\u id

,则必须再次调用

global

变量,如下所示:

function ajax_get_other_posts(){  
    global $displayed_posts_ids;
    $ids_posts = explode(',', $displayed_posts_ids);
    //..
    //..
}

希望这有帮助

如果要在

ajax\u get\u other\u posts()

方法中访问

$displated\u posts\u id

,则必须再次调用

global

变量,如下所示:

function ajax_get_other_posts(){  
    global $displayed_posts_ids;
    $ids_posts = explode(',', $displayed_posts_ids);
    //..
    //..
}

希望这有帮助

仍然无法访问它,因为当我显示它时,我得到了空函数ajax\u get\u other\u posts(){global$displated\u posts\u id;var\u dump($displated\u posts\u id);仍然无法访问它,因为当我显示它时,我得到了空函数ajax\u get\u other\u posts(){global$displated\u posts\u id;var\u dump($displated\u posts\u id);

(编辑:源码门户网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!