How can I display the_content from the regular loop and several custom post types on the same page template in WordPress?
-
-
Answer:
The simplest way is to put the content from a custom post type into a variable while in a regular loop (as dictated by a template). For example, suppose we are in a Page template, so it looks like this: get_header(); the_post(); <h1><?php the_title(); ?></h1> <?php the_content(); ?> Now I want to output the content from my kittens custom post type: <?php $kittens = get_posts(array('post_type'=>'kittens','posts_per_page'=>-1)); foreach($my_cpt as $kitten) { echo apply_filters('the_content', $kitten->post_content); } ?> What is happening here is that I am loading all my kittens into a $kittens variable, then looping through each kitten obtained thereby, and for each kitten I am outputting the post_content of the kitten after running it through the "the_content" filter, which does all the fancy stuff that WP applies in the the_content() template tag.
Daniel Quinn at Quora Visit the source
Related Q & A:
- How do I display all categories on a page with a corresponding image?Best solution by Magento
- How can I use several windows by Ribbon?Best solution by Stack Overflow
- How can I get custom fields in wordpress?Best solution by Stack Overflow
- How can I display data in a listview?Best solution by Stack Overflow
- How can I change my yahoo page from wide screen to regular?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.