Question

i have a custom post on my website, i just want that the all post from custom post types should be published on a separate page which will be "Blog", is this possible?

the code worked, i edited the code this is my code:

<?php
/*
Template Name: Blog template
*/
get_header(); 

$blog_query = new WP_Query;
$blog_query->query( 'post_type=uni' ); // <-- Your args on this line
?>

<div id="content" class="col-full">
<div id="main" class="col-left">
<?php if( $blog_query->have_posts() ) : ?>

    <?php while( $blog_query->have_posts() ) : $blog_query->the_post(); ?>

    <div class="featured post">
    <h2 class="title fl"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    </h2>
    </br>
    <p class="fr">

                   <span class="small"><span class="post-category"><?php the_category(' ') ?></span></span>

               </p>
               <p class="post-meta">

                        <span class="small"><?php _e('Featured Venue &#124;', 'woothemes'); ?></span>

                        <span class="comments"><?php comments_popup_link(__('0 Reviews', 'woothemes'), __('1 Review', 'woothemes'), __('% Reviews', 'woothemes')); ?></span>

                    </p>
                    <div class="entry">

                    <?php the_excerpt(); ?>

                </div>

    </div>

    <?php endwhile; ?>

<?php endif; ?>

<?php wp_reset_query(); ?>

</div>
</div>

<?php 
get_footer();

but when i click on the title of the blog page, it takes me to a page where content of the posts come without div tag, and on the menu its on the home page check this image alt text in this image everything looks fine, this is what i wanted

in this when i click on the post i.e. title it comes this way

check this image alt text the menu is pointing on home and there is no div tag in the post

Was it helpful?

Solution

Create a page, call it blog.

Create a page template and fetch posts from the custom type.

Attach the template to the page.

Save.

Example Page Template

You can use any parameters in the query line that you would with query posts.

<?php
/*
Template Name: Blog template
*/
get_header(); 

$blog_query = new WP_Query;
$blog_query->query( 'post_type=mycustomtype' ); // <-- Your args on this line
?>

<div id="content">

<?php if( $blog_query->have_posts() ) : ?>

    <?php while( $blog_query->have_posts() ) : $blog_query->the_post(); ?>

    <div class="post">
        <h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
        <?php the_content(); ?>
    </div>

    <?php endwhile; ?>

<?php endif; ?>

<?php wp_reset_query(); ?>

</div>

<?php 
get_footer();
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top