Multiple editable content on page


EDIT: I’ve found out that by using Advanced Custom Fields I can edit multiple fields on a page. Why WP doesn’t have this feature by default I’ll never know.

This is the kind of ability I was looking for that PerchCMS has by default.

Thanks for your answers.


I’m new to writing websites using WordPress as a CMS, and in the past I’ve used a CMS called PerchCMS which allows me to add extra multiple sections by using the php tag of:

<?php perch_content('InformationTitle');?>
<?php perch_content('Information');?>
<?php perch_content('AboutTitle');?>
<?php perch_content('AboutContent');?>

With WordPress I really don’t understand how to add multiple sections in this way, I trawled the Internet for answers, but there appear to be no answers anywhere else.

Part of my code is as follows:

<?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>


        <img src="<?php bloginfo('template_directory'); ?>/assets/img/logo.png" class="fg3 logo" alt="Logo" />


          <div id='services'>
            <p>
              <?php the_content('services'); ?>
            </p>
          </div>

           <div id='about'>
            <p>
              <?php the_content('about'); ?>
            </p>
          </div>

With this method, all the content I write gets repeated.

What am I doing wrong? I understand that the loop is there to loop through the posts on the page, and I’ve seen mention of plugins such to achieve this, but surely WordPress should offer this by default? There are many many sites that have different sections that need to be edited independently.

Any help is greatly appreciated.

Answer

you can’t pass nothing inside the_content(); except a “read more”.
To achieve what you need it could be done this way;

<?php get_header(); ?> // getting the header 

<?php if (have_posts()) : while (have_posts()) : the_post(); ?> // the loop stuff

<?php 
        // PAGE 1
        $page_id = 8454; // id of the page you need to pull out the content of
        $page_data = get_page( $page_id ); // getting the data from the page
        $content = apply_filters('the_content', $page_data->post_content); // filtering

        echo $content; // outputting the content 

        // PAGE 2
        $page_id = 8456;
        $page_data = get_page( $page_id );
        $content = apply_filters('the_content', $page_data->post_content);

        echo $content;

        // PAGE 3
        $page_id = 8458;
        $page_data = get_page( $page_id );
        $content = apply_filters('the_content', $page_data->post_content);

        echo $content;

?>


<?php endwhile; endif; ?> <?php // ending while and if ?>

<?php // get_sidebar(); ?> <?php // get the side bar if you want ?>
<?php get_footer(); ?> <?php // the footer ?>

• Now create a page (Pages > Add New) with the info you want to output and save it.

• Find out the ID of the page (look at the URL of the page you just saved) it’s the number you see after post.php?=
http://www.yoursite.com/wp-admin/post.php?post=8458&action=edit

• Now copy that number and place it $page_id = HERE

——- EDITS ——-

for me that’s the best way… you have lots of pages but at least they are organized.
BUT!!! if you wish, You can have everything in 1 single page, in admin area, and output only the content of that page. In wordpress you can use HTML tags in pages, so on that single page you can have multiple <div>s <p>s <h1>s <img>s with the content you want.

index.php

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<?php 
        $page_id = 8454;
        $page_data = get_page( $page_id );
        $content = apply_filters('the_content', $page_data->post_content); 

        echo $content;
?>


<?php endwhile; endif; ?> <?php // ending while and if ?>

<?php // get_sidebar(); ?> <?php // get the side bar if you want ?>
<?php get_footer(); ?> <?php // the footer ?>

in admin are create a page and put all your content inside it:

<h1>Services</h1>
<div id="services">CONTENT OF SERVICES</div>

<h1>About</h1>
<div id="about">CONTENT OF About</div>

<h1>Images</h1>
<div id="images">
<img src="" alt="" />
<p>Some description</p>
</div>

Attribution
Source : Link , Question Author : Josh , Answer Author : gxt

Leave a Comment