0

So here's my question:

I need to build a custom post type to add employees to a website. The problem is, it need to be shown:

1 - Image on the Right 2 - Image on the Left ... and so on.

For this I made a page template where I need this custom post type content to be shown. To style the custom post type differently I made two different post type templates and I created two posts with those templates.

Now my problem is: How can I show this custom post types with his templates inside my custom page template?

I tried with this code:

<?php
  $args = array( 'post_type' => 'equipa', 'posts_per_page' => 10 );
  $loop = new WP_Query( $args );
  while ( $loop->have_posts() ) : $loop->the_post();
    the_post();
  endwhile;
 ?>

But it's throwing me these errors:

Notice: Undefined offset: 1 in C:\xampp\htdocs\WP\wp-includes\class-wp-query.php on line 3071

Notice: Undefined offset: 2 in C:\xampp\htdocs\WP\wp-includes\class-wp-query.php on line 3071

Anyone have any idea on what i'm doing wrong here?

0

So I found the solution: You just insert both templates (made like every normal template for custom post types) and then come to the page-template and do this:

        <?php
        $args = array( 'post_type' => 'equipa', 'order' => 'ASC' );
        $loop = new WP_Query( $args );
        $c = 0;
        while ( $loop->have_posts() ) : $loop->the_post();
            if ($c % 2 == 0) {
                include 'template-post-left.php';
            } else {
                include 'template-post-right.php';
            }
            $c++    ;
        endwhile;
        ?>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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