WordPress将the_views中的视图作为变量发布

Tim*_*urr 2 php variables wordpress function

我正在使用WordPress插件WP-PostViews来显示帖子的视图数量。我正在使用此代码,它很好用:

<?php if(function_exists('the_views')) { the_views(); }?>
Run Code Online (Sandbox Code Playgroud)

我想做的是将一定数量的帖子视图用作变量,但是我无法使其正常工作。到目前为止,我已经尝试过:

<?php if(function_exists('the_views')) { $variable = the_views(); } ?>
Run Code Online (Sandbox Code Playgroud)

<?php if(function_exists('the_views')) { $variable = the_views(); } else { $var = 0; } ?>
Run Code Online (Sandbox Code Playgroud)

到目前为止没有成功。有人有建议吗?

vva*_*ten 5

默认情况下,the_views()回显而不是返回。您可以通过将第一个参数设置为来获得回报false。例:

<?php if(function_exists('the_views')) { $variable = the_views(false); } ?>
Run Code Online (Sandbox Code Playgroud)