php - How to arrange the_content() in Wordpress post page? -


i'm trying format single post page template has custom types. i'm using the_content() displays post contents altogether, how can call individual content fields can arrange them in 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;  ?> 

you need create custom fields used in posts if wanted separate out parts of content, each paragraph individually or something. the_content() print out entire content.

if want plugin it, popular https://wordpress.org/plugins/advanced-custom-fields/

or, when creating new post, can go top , click screen options check custom fields box.

custom fields appear under post content box. can create new 1 , give value (they act key/value pairs).

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

$post_id -> id of post want meta values for. use $post->id post's id within $post variable scope. use get_the_id() retrieve id of current item in wordpress loop.

$key -> string containing name of meta value want.

$single can either true or false. if set true function return single result, string. if false, or not set, function returns array of custom fields.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -