PHP WordPress the_content()

Jef*_*ona 1 php wordpress

我在哪里可以找到the_content()post_content数据库中获取值的文件?

我想做这个概念但是使用数据库中的另一个内容,到目前为止,我已经向数据库添加了一个新列.post_content2如何使用类似的东西来获取它的值

 <?php the_content2(); ?>
Run Code Online (Sandbox Code Playgroud)

我试着查看post-template.php并找到了函数,但没有从数据库post_content中获取值.

ran*_*ame 7

从上面的评论,以及更完整的答案:

  1. 不要修改核心WP表.使用post_meta函数或添加新表.

  2. the_content()只是一个直接访问posts表,content列的便捷函数.您可以通过从数据库中获取值并将其传递来随时执行相同的操作apply_filters('the_content', $my_custom_content);.如果你想编写自己的the_content2()函数,可以/应该这样做(使用post_meta上面提到的方法):

    function the_content2() {
        // Global in the current post so we can get the ID
        global $post;   
        // Load your custom content
        $my_content = get_post_meta($post->ID, 'my_custom_content'); 
        // Echo it out (like the_content()) applying 'the_content' filters
        echo apply_filters('the_content', $my_content);
    }
    
    Run Code Online (Sandbox Code Playgroud)

如果你想弄清楚如何保存这些内容,那么你可以阅读这篇文章:

如何在WordPress中创建自定义元框

编辑
值得注意的是,您可以在几个不同的插件中使用此功能.根据我的经验,Custom Field Suite是最可靠和易于使用的(但这只是我的意见).