0

I'm a bit despaired because I cannot figure out how to do what I need (and I worked with WP since a lot of time ..)

Basically, I need to show my artistic work. Each work is a post, or a page or a custom types (I still don't know which fits the best) I have 3 categories of work and I won't have more.

I have a blog on my website and the custom permalink is:

/blog/%year%/%monthnum%/%day%/%postname%/

So I guess it already removes the post type hypothesis (I don't want an url like :

julienbayle.net/blog ....

I want this:

julienbayle.net/works shows ALL my works as a portfolio page with only thumbnails as a grid/table and pagination.

julienbayle.net/works/creation shows only works in category creation as the grid of thumbnails too

julienbayle.net/works/lab shows only works in category lab as the grid of thumbnails too

julienbayle.net/works/collab shows only works in category collab as the grid of thumbnails too

When you click on thumbnails, you see the work considered, for instance:

julienbayle.net/works/collab/work1

julienbayle.net/works/collab/work2

etc.

I tried with a custom type named "works" but I had some problems with pagination. So I tried by using basic category hierarchy and pages :

works

-- creation

-- lab

-- collab

But I cannot have the good permalink + the link to each work is wrong (contains the structure of a blog post)

Anyone here to help me? BIG thanks in advance :)

2 Answers 2

1

This is fairly straightforward with a custom post type and custom taxonomy.

First, register a custom taxonomy worktype, with rewrite parameter set to works:

'rewrite' => array( 'slug' => 'works' )

Next, register a custom post type with rewrite set to works/%worktype%:

'rewrite' => array( 'slug' => 'works/%worktype%' )

You'll also need to set with_front to false if your posts have a static prefix, like blog.

Next, add a filter to post_type_link to swap the %worktype% tag with your selected worktype for individual works posts whenever WordPress outputs a link to an individual work:

function wpa_works_post_link( $post_link, $id = 0 ){
    $post = get_post($id);  
    if ( is_object( $post ) && $post->post_type == 'works' ){
        $terms = wp_get_object_terms( $post->ID, 'worktype' );
        if( $terms ){
            return str_replace ( '%worktype%' , $terms[0]->slug , $post_link );
        }
    }
    return $post_link;
}
add_filter( 'post_type_link', 'wpa_works_post_link', 1, 3 );
12
  • I was missing the last part about the rewrite. It works very fine, thanks a lot Milo :)
    – gluon
    Commented May 31, 2013 at 19:56
  • something doesn't work. strangely, I didn't verify to click on .. view work. I cannot see any 'work'.. it gives a 404
    – gluon
    Commented May 31, 2013 at 20:19
  • set has_archive to true in your post type registration.
    – Milo
    Commented May 31, 2013 at 20:38
  • already did :-/
    – gluon
    Commented Jun 1, 2013 at 8:18
  • I created archive-works.php , archive-creation etc for each worktype in order to display global portfolio. It doesn't work :( (despaired)
    – gluon
    Commented Jun 1, 2013 at 8:28
0

Change your permalink and set to this

    %postname%/

Its change your url Like a site url/category name/postname

1
  • and I lose the julienbayle.net/blog/... for all my blog posts :(
    – gluon
    Commented May 31, 2013 at 13:15

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.