Jump to content

.London Domains - £4
Photo
- - - - -

Custom Post Type - Display on home page


  • Please log in to reply
3 replies to this topic

#1 CraigP

CraigP
  • Supporter+
  • Mike's BFF
  • 2,320 posts

Posted 07 February 2018 - 00:26

Morning all!

 

I'm currently working on a little side project to refresh my skills a bit and I've drawn a blank at how to get my custom post type posts to display on my home page.

 

I've got a blog, which I display nine items on my home page.

I want to do exactly the same with my business ads.

 

I've had a bit of a look around, but I can't find anything for static home pages and the stuff I have tried with the functions.php is just returning errors, looking at the source, most of them come from around 8 years ago, so perhaps outdated?

 

Any suggestions would be great!

 

C


  • 0

Push24 Creative - it's just who we are and what we do!
Get in Touch - craig@Push24Creative.co.uk

Follow Me - @craigpettit12 - @Push24Creative
+1 to those who help


#2 MikeChipshop

MikeChipshop
  • Overlord
  • Mini Member
  • 4,672 posts

Posted 07 February 2018 - 08:34

You're looking for WP_Query https://codex.wordpr...erence/WP_Query

 

Example...

 

<?php
    $args = array(
        'post_type' => 'POST-TYPE-NAME-HERE',
        'posts_per_page' => 9
    );
?>
<?php $cploop = new WP_Query( $args ); if ( $cploop->have_posts() ) { ?>
     <?php while ( $cploop->have_posts() ) : $cploop->the_post(); ?>
 
        <!-- Normal Loop Nonsense In Here -->
 
     <?php endwhile; ?>
<?php endif; ?>

  • 1

#3 CraigP

CraigP
  • Supporter+
  • Mike's BFF
  • 2,320 posts

Posted 07 February 2018 - 10:07

 

You're looking for WP_Query https://codex.wordpr...erence/WP_Query

 

Example...

<?php
    $args = array(
        'post_type' => 'POST-TYPE-NAME-HERE',
        'posts_per_page' => 9
    );
?>
<?php $cploop = new WP_Query( $args ); if ( $cploop->have_posts() ) { ?>
     <?php while ( $cploop->have_posts() ) : $cploop->the_post(); ?>
 
        <!-- Normal Loop Nonsense In Here -->
 
     <?php endwhile; ?>
<?php endif; ?>

 

Cheers mate! sorted


  • 0

Push24 Creative - it's just who we are and what we do!
Get in Touch - craig@Push24Creative.co.uk

Follow Me - @craigpettit12 - @Push24Creative
+1 to those who help


#4 MikeChipshop

MikeChipshop
  • Overlord
  • Mini Member
  • 4,672 posts

Posted 07 February 2018 - 11:22

No problem sir, plenty of options for the arguments too on that page.


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users