$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Showing Custom Post Type with his templates on a custom page template|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Showing Custom Post Type with his templates on a custom page template

matteradmin9PV0评论

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?

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?

Share Improve this question asked Feb 8, 2019 at 11:55 Ariano ÂngeloAriano Ângelo 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 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;
        ?>
Post a comment

comment list (0)

  1. No comments so far