0

So I created a custom post type and I've also created a custom page called page-profile.php that follows the WordPress templating.

Here is the code inside page-profile.php:

<?php

$args = array(
    'post_type' => 'profile', // enter custom post type
    'orderby' => 'title',
    'order' => 'ASC',
    'posts_per_page' => '4',
);
$loop = new WP_Query($args);

get_header(); // displays header
get_sidebar();
get_footer(); //displays footer

So the header, footer and sidebar all are being called in.

How can I target the red box and create templating where I would like to show the title and thumbnail?

enter image description here

1 Answer 1

0

You need to add the Loop to your template to display post content.

Regular loop (the current page).

<?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

    <article>
        <h2><?php the_title(); ?></h2>
    </article>

    <?php endwhile; ?>

        <?php // Navigation ?>

    <?php else : ?>

        <?php // No Posts Found ?>

<?php endif; ?>

Custom query loop. Notice the wp_rest_postdata()

<?php if ($loop->have_posts()) : ?>

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

    <article>
        <h2><?php the_title(); ?></h2>
    </article>

    <?php endwhile; ?>

  <!-- reset global post variable. After this point, we are back to the Main Query object -->
  <?php wp_reset_postdata(); ?>

<?php else : ?>

    <?php // No Posts Found ?>

<?php endif; ?>

You can also use get_template_part() in the loop, if you like to split your code into smaller pieces and into separate files.

Your Answer

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