WordPress.org

Ready to get started?Download WordPress

Forums

List Posts/Pages Based On PHP Template? (2 posts)

  1. suntower
    Member
    Posted 1 year ago #

    Is there a way to print a hierarchy of posts/pages/custom post types based on page template?

    EG. I am often asked to review another web site and I'd like a way to 'see' all the pages that are assigned to the 'Newsletter' PHP template and all the pages assigned to the 'Product Info' PHP template.

    In fact, if someone could tell me where the page template info is stored in the db I guess I could just loop through WP_Posts, right?

    TIA,

    ---JC

  2. hiphopinenglish
    Member
    Posted 1 year ago #

    It seems to me that you want to create another page template called Archives or something similar. There are plenty of guides available on Google on how to do that. In that page template, you will want to create 2 loops: one that calls Product Info CPT and one that pulls Newsletter CPT posts. Inside each loop, you want to include a call to the permalink of each post. Does that sound like a reasonable solution?

    More info on calling CPTs here.

    Essentially, you'd want something like this:

    $args = array( 'post_type' => 'your-CPT-taxonomy-here', '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;

    ^^If you want a simple "list", then remove the_content(), and replace with the_permalink().

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags