Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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' ); ?>>
            <header>
                <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>
            </header>
        </section>
    <?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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
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 '12 at 10:35
    
well the you need to set the work page template if its your front page –  Bainternet Jul 7 '12 at 12:53
    
I've edited my question to clarify. Still not sure what you mean... –  Krimo Jul 7 '12 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 '12 at 14:12
    
Thanks it works ! –  Krimo Jul 7 '12 at 14:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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