0

Ive been asked if this is possible hoping someone can help. I currently have multiple custom post types organised by category.

My current set up is category-name > archive-name > custom post-type (assigned by category).

Is it possible to use a page.php template instead of an archive.php template to display custom posts?

How would the custom post be assigned to the the correct page template in the hierachy if not by category (not available for pages of course?)

Like this:

page-name > custom post-type (assigned by page-name?).

EDIT:

Looks like a solution can anyone confirm?

$args = array( 'post_type' => 'product', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
  the_title();
  echo '<div class="entry-content">';
  the_content();
  echo '</div>';
endwhile;

Thanks.

1 Answer 1

0

Building on my question my solution is that I have written this bare bones template and was hoping for some critiquing on if there are better ways or if this approach is suitable.

To clarify the test case is create a page, create a sub-page with this code in the custom-page.php and display the entry content of the page, plus loop through and display each of the custom posts based on post name (type). Fire away.

<header class="event-page-header">
<!--breadcrumbs-->
    <?php custom_breadcrumbs(); ?>
    <h1><?= get_post_field('post_title', $post->ID) ?></h1>
    <div><?= get_post_field('post_content', $post->ID) ?></div>

</header><!-- .entry-header -->

<!--the post-->
<div class="post-container">
    <div class="posts-body">

            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

                <!-- get custom post by type (name)-->
                <?php $args = array( 'post_type' => 'custom-post-name', 'posts_per_page' => -1 );

                $loop = new WP_Query( $args );

                while ( $loop->have_posts() ) : $loop->the_post(); ?>

                <!-- advanced custom fields entry content -->
                <div class="acf-custom-content">                    
                    <div><?php the_field('event_time'); ?></div 
                    <div><?php the_field('event_location'); ?></div>    
                </div>

                <!-- post entry content -->
                <div class="custom-entry-content">
                    <?php the_title(); ?>
                    <?php the_content(); ?>
                </div><!-- .entry-content -->

                <?php endwhile; ?>

            </article><!-- #post-## --> 

    </div>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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