1

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

4
  • "I have a custom post on my website"; do you mean "post" or "postS" (plural?) If you want them on Blog, and I assume you mean a list of posts, where do you want the list of post_type='post'? Commented Jan 4, 2011 at 9:28
  • se what i am telling you to tell is, i have a custom post type, whenever i write a post from this it should directly publish on blog page, instead on home Commented Jan 4, 2011 at 9:46
  • you can refer my answer on this link wordpress.stackexchange.com/questions/175120/…
    – megi
    Commented Jun 20, 2017 at 9:55
  • you can refer my answer on same question on this link wordpress.stackexchange.com/questions/175120/…
    – megi
    Commented Jun 20, 2017 at 9:56

1 Answer 1

4

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();
2
  • hey your code worked, but i made some changes, instead of the_content i used the_excerpt which works, but when i click on the title, it should open the content in a page like single.php, and it should be in the same menu i.e. blog, but when i click on the title, it opens a page which contains no <div> and it opens in the home menu, check my original answer Commented Jan 5, 2011 at 5:18
  • At a guess, whichever page renders your home page doesn't include the div you're referring to?
    – t31os
    Commented Jan 5, 2011 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.