Display custom post type in front Page Wordpress

 First go to front-page.php find event section and write below code 

 <?php
        $homepageEvents = new WP_Query(array(
            'post_type' => 'event',
            'posts_per_page' => 2,
        ));

        while($homepageEvents->have_posts()) {
         $homepageEvents->the_post(); ?>
      <div class="event-summary">
        <a class="event-summary__date t-center" href="<?php the_permalink();  ?>">
          <span class="event-summary__month">Apr</span>
          <span class="event-summary__day">02</span>
        </a>
        <div class="event-summary__content">
          <h5 class="event-summary__title headline headline--tiny"><a
              href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
          <p><?php echo wp_trim_words(get_the_content(), 18);  ?> <a href="<?php the_permalink(); ?>"
              class="nu gray">Learn more</a></p>
        </div>
      </div>
      <?php    }  wp_reset_postdata();
       ?>

and save 

now go to dashboard and in setting update permalink again so that event url works.

Comments

Popular posts from this blog

Basics Of PHP

Creating App.js for Node Application

WordPress Full Guide For Developer