我正在使用 WordPress 插件 WP-PostViews 来显示帖子的浏览量。我正在使用这段代码,效果很好:
<?php if(function_exists('the_views')) { the_views(); }?>
我想做的就是使用这个帖子浏览量作为变量,但我无法让它工作。到目前为止我已经尝试过:
<?php if(function_exists('the_views')) { $variable = the_views(); } ?>
和
<?php if(function_exists('the_views')) { $variable = the_views(); } else { $var = 0; } ?>
到目前为止还没有成功。有人有建议吗?
最佳答案
默认情况下,the_views()
会回显而不是返回。您可以通过将第一个参数设置为 false
来获得返回。示例:
<?php if(function_exists('the_views')) { $variable = the_views(false); } ?>
关于php - WordPress 将 the_views 中的 View 作为变量发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23581853/