doujia1988 2016-07-15 19:58
浏览 34
已采纳

如何在Wordpress帖子页面中安排the_content()?

I'm trying to format my single post page template that has custom types. I'm using the_content() which displays the post contents altogether, but how can I call individual content fields so that I can arrange them in the template?

functions.php

function stories_init() {
$args = array(
  'label' => 'Stories',
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => array('slug' => 'stories'),
    'query_var' => true,
    'menu_icon' => 'dashicons-video-alt',
    'supports' => array(
        'title',
        'editor',
        'custom-fields',

        'thumbnail',)



    );
register_post_type( 'stories', $args );
}

single-post.html

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>

<?php endwhile;  ?>
  • 写回答

2条回答 默认 最新

  • dongruo0909 2016-07-15 21:11
    关注

    You would need to create custom fields to be used in posts if you wanted to separate out parts of your content, like each paragraph individually or something. the_content() will always print out the entire content.

    If you want a plugin to do it, this is the most popular https://wordpress.org/plugins/advanced-custom-fields/

    Or, when creating a new post, you can go to the top and click Screen Options then check the Custom Fields box.

    Custom fields will appear under your post content box. You can create a new one and give it a value (They act as key/value pairs).

    to call it in your template, use <?php echo get_post_meta($post_id, $key, $single); ?>

    $post_id -> is the ID of the post you want the meta values for. Use $post->ID to get a post's ID within the $post variable scope. Use get_the_ID() to retrieve the ID of the current item in the WordPress Loop.

    $key -> is a string containing the name of the meta value you want.

    $single can either be true or false. If set to true then the function will return a single result, as a string. If false, or not set, then the function returns an array of the custom fields.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器