Show post with include_once

Asked

Viewed 18 times

0

I want to list all my posts from all my custom post type, so far I get list in index.php

But the problem is that it only lists one post of each custom post type.

My index.php loop

<?php $args = array('post_type'=>array('filmes', 'series', 'blog'),'paged' => $paged,'orderby'=>'date','posts_per_page' => 8); query_posts($args); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php   if (has_post_thumbnail()) {
    $imgsrc = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'home');
    $imgsrc = $imgsrc[0];
} elseif ($postimages = get_children("post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=0")) {
    foreach($postimages as $postimage) {
        $imgsrc = wp_get_attachment_image_src($postimage->ID, 'home');
        $imgsrc = $imgsrc[0];
    }
    } elseif (preg_match('/
        <img [^>]*src=["|\']([^"|\']+)/i', get_the_content(), $match) != FALSE) {
        $imgsrc = $match[1];
    } else {
        $imgsrc = get_template_directory_uri() . '/images/no-imagen.png';
    } ?>
<?php 
if ( get_post_type( get_the_ID() ) == 'filmes' ) {
    require_once('post/filmes.php');
} elseif ( get_post_type( get_the_ID() ) == 'series' ) {
    require_once('post/series.php');
} elseif ( get_post_type( get_the_ID() ) == 'blog' ) {
    require_once('post/blog.php');
}
?>
    <?php endwhile; else : ?>
    <?php endif; ?>

someone would know what the problem is or what I’m doing wrong?

1 answer

0


I solved the problem by replacing require_once with include

<?php 
if ( get_post_type( get_the_ID() ) == 'filmes' ) {
    include('post/filmes.php');
} elseif ( get_post_type( get_the_ID() ) == 'series' ) {
    include('post/series.php');
} elseif ( get_post_type( get_the_ID() ) == 'blog' ) {
    include('post/blog.php');
}
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.