0

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.

  • Are you looking for a page that's editable from the front end, or from the admin screens? You can accomplish what you're looking for in the back end, using meta boxes and wp_editor(). I don't have time to write a complete answer right now, but I'll try to come up with something later today, if no one else has. – Pat J Aug 7 '13 at 12:45
  • A page that is editable from the back end, are meta boxes similar to what I've been doing with PerchCMS? – Josh Aug 7 '13 at 13:02
  • I haven't used PerchCMS, so I can't say for sure. Meta boxes allow you to add extra (meta) information to a post/page/custom post type. Then, in the front end, you would pull the meta information out using get_post_meta() for display. Essentially, the post's content would be your first section, and then the meta boxes would contain your additional fields. – Pat J Aug 7 '13 at 13:07
  • I really think this is being over complicated, as an example of what I want - examples.getbootstrap.com/jumbotron/index.html imagine each section under the heading is what I tried to modify using the_content(). How would you use wordpress to achieve this? Assuming of course that they're NOT links to other pages, just blocks of text. – Josh Aug 7 '13 at 13:10
  • In your Bootstrap example, I'm doing something very much like that, but I'm using meta boxes to add the different content areas. Bear in mind that you're trying to make WordPress -- which ships with a single content area, but the ability to add more using meta boxes -- into a clone of PerchCMS, with multiple editable content areas. It can be done, but it's going to take some work. – Pat J Aug 7 '13 at 13:49
0

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>
  • The trouble is that the content is all on the same page, just in different divs. It's all on the index page of the website. – Josh Aug 7 '13 at 12:16
  • in fact. from what I've understood you need the content to be editable from the back end. if so you can create 2 pages, in the back end, with the services information, another one with about information.. and with the code above that you're going to paste into your index.php you can display the content of those pages. And they are also editable from the admin area. – gxt Aug 7 '13 at 12:20
  • two pages from admin area into one page on front page – gxt Aug 7 '13 at 12:23
  • Surely that's not the only way to have multiple sections of editable content? I've got about 9 pages on this website, each with between 2 and 4 sections to be edited. I'm going to end up with hundreds of extra pages? – Josh Aug 7 '13 at 12:32
  • check my EDITS in post above! – gxt Aug 7 '13 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.