am624
am624

Reputation: 13

Wordpress - How can break dynamic content up into multiple divs

I have a template page with separate modules, each with their own content that I would like to be able to edit in the WP text editor. So all of this content should be on one page but broken up into its separate parts. I have been using

<?php the_content(); ?> 

to display the content but that displays all the content entered into the text editor box.

So basically, I'm asking how to break up the text entered into WP dynamically. Is there a way to tag a certain content block such as a paragraph or an image so that I can set where in the template it is rendered?

Upvotes: 1

Views: 531

Answers (1)

Xhynk
Xhynk

Reputation: 13880

You, my friend, are looking for Custom Fields. You can implement them yourself with the meta box functions like add_meta_box, but then you're also looking at sanitizing and saving the data through your own functions.

You may be more comfortable using the Advanced Custom Fields plugin. It has over a million downloads and handles all the relational, data-type, and storage for you.

You can, for instance, very easily insert an "Image Upload Field" only on "Posts" or on "Posts and Pages", and then use the get_field() or the_field() function in your template:

<?php the_field( 'my_custom_image_field' ); ?>

You should be able to omit the $post_id parameter because it defaults to the current post id, similar to get_the_content() and the_content() functions.

Upvotes: 1

Related Questions