简体   繁体   中英

How to set front page in wordpress a custom post type post

I have created a custom post type by CPT UI plugin in WordPress, now I need to show a custom post type page on front page of WordPress by setting >> reading in admin panel. but this type of posts isn't there? how can I display them?!

You're not going to be able to do that because CPT is not a page, it is a post. What you can do is create a page template for the homepage which makes a query and gets the post data. This is how you would do that

  1. First create a page template with this code and place it in the root of your theme

    <?php /* Template Name: Your template name */?>

  2. Then go into the pages tab in the dashboard and open the homepage. Set the page template option (dropdown menu) to the template you just created.

  3. Edit the template file and include this code (replace "123" with the post ID):

    <?php $the_post = get_post(123); ?>

  4. That will give you a Wordpress post object you can work with.

**** UPDATE

When you have your post in a variable you can do things like this:

<?php echo get_the_title($the_post); ?>
<?php echo $the_post->post_content; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM