Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display a list of WordPress custom posts?

Tags:

I am using WordPress 3, and I created a custom post type called article, which gives me the URL format of mywebsite/articles/article-title. How do I see all the article entries in the URL mywebsite/articles?

like image 329
Giljed Jowes Avatar asked Aug 03 '10 16:08

Giljed Jowes


People also ask

How do I display categories of my custom post type?

use get_terms() function to fetch custom taxonomy by its slug, in your case slug is dining-category. read function refrence from wordpress codex website and try this.

How do I display custom post types in WordPress plugin?

After activating the plugin, visit any post or page's edit screen. In main content area, click on '+' icon to add a new block. Search for 'Display Post Types' block or Select from “Layout Elements > Display Post Types”. Select a post type to be displayed.


1 Answers

Assuming you set up everything correctly and you want to see the post type on a public template page, try this code into mycustomtemplate.php or the equivalent.

<?php $loop = new WP_Query( array( 'post_type' => 'article', 'posts_per_page' => 10 ) ); ?>  <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>      <?php the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' ); ?>      <div class="entry-content">         <?php the_content(); ?>     </div> <?php endwhile; ?> 

You can customize the loop just like you would blog posts and pages. If you want to get all on one page you'll want to remove the limit of 10 on post_per_page I wouldn't suggest it though. I would say set it to 50 or 100 and still use pages.

Source: Custom post types in WordPress

like image 133
Brooke. Avatar answered Oct 30 '22 04:10

Brooke.