I have a page on my website called Work (that uses a work.php page template) set up as my front page, where I would like to display a list of the last ten posts with the custom type called portfolio. Here is my code so far:

    <?php $the_query = new WP_Query( array( 'post_type' => 'portfolio', 'posts_per_page' => 10 ) ); ?>
    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
        <section id="post-<?php the_ID(); ?>" <?php post_class( 'portfolio-post' ); ?>>
                <h2><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                <time datetime="<?php the_time('Y-m-d') ?>" pubdate><?php the_time('F jS, Y') ?></time>
    <?php endwhile;?>

The problem is that nothing shows up on that page, despite my having created a couple of posts of this type in wordpress' backend. And when one is clicked, I would like to be taken to /work/the_post_i_clicked/. I must admit to being a bit confused here. Any help would be greatly appreciated.

1 Answer 1


Find the code where you register your portfolio post type and add/change this arguments:

'has_archive' => 'work', //under work you will see a list of portfolio items
'rewrite' => array(
    'slug' =>'work_item',
    'with_front' => false,

then manually go to Settings > Permalinks and refresh your permalink structure

after that your items will be listed under /work as an archive

and work_item/name_of_post as singles.

  • Ok, so I tried what you said: - /work/ is set up as my front page (just so you know) and when I visit this page, the last 10 custom posts still don't show up. - when I click on "view post" in the backend, it works, I'm taked to the single-portfolio.php template with the name of the custom post and everything
    – Krimo
    Jul 7, 2012 at 10:35
  • well the you need to set the work page template if its your front page
    – Bainternet
    Jul 7, 2012 at 12:53
  • I've edited my question to clarify. Still not sure what you mean...
    – Krimo
    Jul 7, 2012 at 13:50
  • You don't need a page for that ,So remove the page named work and rename your work.php theme file to archive-portfolio.php that is it.
    – Bainternet
    Jul 7, 2012 at 14:12

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.