0
votes

I'm using wordpress for a site which has a blog attached and would like to display the single posts using the blog template as the parent page.

Currently root.com shows the front page of the site.

root.com/blog/ shows the blog posts

but then when a single post is being viewed it's ignoring the blog section and the url looks like this root.com/single

Is there a way to make single.php use the blog page as it's parent?

1
have you tried changing your permalinks? I think setting them to /%pagename%/%postname%/ should do the trickCaio Felipe Pereira
I did and weirdly that outputs root.com/single/single/Aaron
damn that sounds nasty. ill do some testing and see what i can findCaio Felipe Pereira
Actually %pagename% isn't a structure tag: codex.wordpress.org/Using_Permalinks#Structure_TagsAaron
This is a commercial site, so forcing /blog/ in the permalinks isn't going to work. Thanks anywayAaron

1 Answers

1
votes

So I figured this out for those having the same issue.

Add this to your functions.php

/*
 * REWRITE THE SLUG FOR SINGLE POSTS .../BLOG/SINGLE POST
 *************************************************************/
add_action('init', 'post_slug_init');
function post_slug_init() {
  register_post_type( 'post', array(
        'public'  => true,
        '_builtin' => false, 
        '_edit_link' => 'post.php?post=%d', 
        'capability_type' => 'post',
        'map_meta_cap' => true,
        'hierarchical' => false,
        'rewrite' => array( 'slug' => '/blog' ),
        'query_var' => false,
        'pages'     => false,
        'supports' => array( 
            'title', 
            'editor',
            'author', 
            'thumbnail', 
            'excerpt', 
            'revisions'
        ),
));
}

Then you'll need to re-save your permalinks from wordpress admin and single posts will now appear with the correct permalink structure.