wordpress 插件:在插件中查询帖子 ID? [英] wordpress plugin: query post-ID in plugin?

查看:31
本文介绍了wordpress 插件:在插件中查询帖子 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,也许你们中的一些人有编写 wordpress 插件的经验.我有一个可能相当简单的问题,但我在网上找不到任何内容.

hey guys, maybe some of you have experience with programming wordpress plugins. I have a probably rather simpel question, but i couldn't find anything on the web.

<?php
/*
Plugin Name: test
*/

function test($content) {

    echo $post_id;
    return $content;
}

add_filter('the_content', 'test');  
?>

我有一个 simpel 插件,它应该在其内容中显示每个帖子的唯一 ID.所以在我有 10 个帖子的首页上,每个帖子都应该有它的 ID.

I have a simpel plugin that should echo out the unique ID of every post in it's content. So on my frontpage with 10 posts every post should have it's ID echoed out.

知道如何实现这一目标吗?谢谢!

Any idea how to achieve that? thank you!

推荐答案

我的猜测是使用 global 关键字访问函数

My guess is Use global keyword to access post id in function

而且我的猜测是 return 和 echo 两者在函数中不能一起工作

And also my guess is return and echo both would not work together in function

function test($content) {
        global $post;
        return $post->ID.'<br>'.$content;
    }

这篇关于wordpress 插件:在插件中查询帖子 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆