I'm trying to create website with index page which will have 2+ different boxs with different content generated from post or pages in WP administration. This page will be looks like this wireframe. I'm using the TwentyFourteen template and I edit index.php in templates folder.

What I tried: Multiple pages on one with different HTML and Multiple pages on a single page. But this isn't working properly for me. These instructions do not insert into 4 different divs.

What I want: I want into 2, or more, different divs on the index page of my website include 2, or more, posts/pages from WP administration into this different divs. I can this problem solved by using <?php include("content-of-div.php) ?>, but this can't be edited in WP admin.

enter image description here

  • you mean you want to have 4 boxes each with a category archieve? – maioman Feb 27 '15 at 8:59
  • What does not working properly means. Explain in an edit – Pieter Goosen Feb 27 '15 at 9:01
  • @maioman I don't know you mean with "archieve" ? I want 4 box (or more) into which I can link to it content (post or page) by ID. – Mardzis Feb 27 '15 at 9:03
  • @PieterGoosen These instructions do not insert into 4 different divs. – Mardzis Feb 27 '15 at 9:04
  • 1
    I suggest to look into page templates to achieve what you need – maioman Feb 27 '15 at 9:05

More complex way

I use it this way (I'm usually doing one page design, however the method of loading pages is still same).

Fo Theme options, I'm using Option tree plugin where my clients could just checkbox which pages should appear there (it's passed by it's ID) and than I load it into the script.

// loading pages which should appear by option tree setting, but you can add your IDs of pages manually there
$ids = ot_get_option( 'show_pages', false);
//if nothing is set
if ($ids == false )
{$ids = array('9999');}

//post_type page, ordered
$page_query = new WP_Query( array( 'post_type' => 'page', 'orderby' => array('menu_order' => 'ASC'),  'post__in' => array_values($ids)) );

if ( $page_query-> have_posts() ) : while ($page_query-> have_posts() ) : $page_query-> the_post(); 

$template_file = get_post_meta( get_the_ID(), '_wp_page_template', TRUE );
        //page template (name of your template)
        if ($template_file=='page-contactform.php') {
           //here you should include it 
           include 'page-contactform.php'; 
        elseif ($template_file=='page-vyrobky.php') { 
           include 'page-vyrobky.php'; 
        else {
            include 'page.php'; 
         endwhile; else : ?>
    <p>Nothing found</p>

<?php endif; 


    $include = get_pages('include=11'); //here go your ID number
    $content = apply_filters('the_content',$include[0]->post_content);
    echo $content;
  • Never ever use query_posts unless your intention is to break your page's functionalities :-) – Pieter Goosen Feb 27 '15 at 9:27
  • @kybernaut.cz Thanks for your answer, but this is too complicated for me. Is there a simple solution as php include() but only according to include by ID from WP? – Mardzis Feb 27 '15 at 9:37
  • @PieterGoosen I've thought that for main query its ok, nope? But I've changed it to page_query (hopefully I haven't skipped something somewhere) – Karolína Vyskočilová Feb 27 '15 at 9:37
  • I think you mean WP_Query :-) That is the correct way to create a custom query – Pieter Goosen Feb 27 '15 at 9:43
  • @Mardzin I've edited my post, the really simple way should work for you, just put the correct page number there. – Karolína Vyskočilová Feb 27 '15 at 9:48

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.