Scope: Using Variable Defined in a Function

六眼飞鱼酱① 提交于 2019-12-08 02:57:27

If you want to use <?php echo $tzDesc; ?> anyway, you would need to define $tzDesc as a global variable. However, I don't recommend doing so as global variables are considered poor programming practice.

A better solution would be to have the paginate_slide() add $tzDesc (and other values) to the $post object. That way you have access to these variables anytime you call the_post(). If you go this route, be sure to namespace you variables:

$post->ns_tzDesc = $tzDesc;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!