Before you ask please READ THIS

Duplicate "Posts" menu in admin for blog entries

edited February 2017 in FatMoon Posts: 52
I recently added a script to the functions.php file as I wanted my blog post structure to be: "http://www.websiteurl.com/blog/postname" (I have used websitrurl.com as an example as my site is locked until its completed). This was the code I added:

add_action( 'init', 'my_new_default_post_type', 1 );
function my_new_default_post_type() {
 
    register_post_type( 'post', array(
        'labels' => array(
            'name_admin_bar' => _x( 'Post', 'add new on admin bar' ),
        ),
        '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,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
    ) );
}
After doing so, all the blog posts under websiteurl.com/blog/postname would return a 404 error. So to fix this, I re-saved the permalink structure in the wordpress reading settings to Post Name. This fixed the issue so I am now able to load posts with this new slug, but now I have 2 x posts links in the wordpress menu and posts with and without this new slug are loading! So I have duplicate content...

Any ideas how to remove the posts link with the old structure? Or is there an easier way to set the existing posts slug to be within /blog/ so I can remove the script I added and revert back to how it was.

Screenshots here for what I mean:

This is how the slug structure is preferred: https://cl.ly/0A3r1P2c1m0X/Screen Shot 2017-02-20 at 05.14.57.png

This slug ALSO works due to now having duplicate content, so content needs removing/new script needed so other one can be removed instead: https://cl.ly/0p1l1t3T2q29/Screen Shot 2017-02-20 at 05.16.14.png

Duplicate posts in menu: https://cl.ly/0p1t3u0j302Y/Screen Shot 2017-02-20 at 05.13.27.png

Setting applied in Reading section: https://cl.ly/2h3p1S3h422z/Screen Shot 2017-02-20 at 05.13.06.png

I hope this is clear? The site is locked until it goes live, so please let me know if there is anything else you need to see and I shall send it over.

Thanks
Post edited by Air on

Comments

  • AirAir
    Posts: 10,970
    Hello:-)

    I don't think I can help you with this one as you are doing "register_post_type" so this is exactly what should happen.

    You need to ask on general WordPress forum how to safely achieve permalinks that you need. For sure this is not best way to do it.

    With kind regards.
  • ok thanks, I just want the blog pages to appear within a sub page instead of a root page if that makes sense? Any ideas?
  • AirAir
    Posts: 10,970
    chillwiddastill said: page instead of a root page if that makes sense?
    Yes:-)
    chillwiddastill said: Any ideas?
    Like I said:
    Air said: You need to ask on general WordPress forum how to safely achieve permalinks that you need
    I don't know how to do it.

    With kind regards.
  • Ah ok fair enough, I shall head to the forums then and let you know what the fix is, if there is one ;)

    Thanks
  • AirAir
    Posts: 10,970
    Should be possible. You can try this answer http://stackoverflow.com/questions/15617820/wordpress-custom-permalink-for-just-posts#15619416
    It sound simple :-)
  • Yes I just tried /blog/%postname%/ and that seemed to work and removing the code I added to functions.php removed the duplicate post in the menu, but now portfolio pages were showing up as /blog/portfolio/portfolio-single oops!

    so with this line in the forum:

    'rewrite' => array('slug' => 'portfolio', 'with_front' => false),

    Do you know where exactly would I add this? Is it to the .htaccess file?

    Sorry to ask :smile:


    Thanks
  • AirAir
    edited February 2017 Posts: 10,970
    Try going to wp-content\plugins\a13_framework_cpt\a13_framework_cpt.php

    Find there 'rewrite' => array( 'slug' => $album_slug ), line ~52
    and also 'rewrite' => array( 'slug' => $work_slug ), line ~156

    And add in both cases missing part , 'with_front' => false.
    Refresh permalinks settings, and tell me how it went :-)

    With kind regards.
    Post edited by Air on
  • Perfect! Works exactly how I expect, and with such minimal code and no need for extra permalink control plugins!

    Thank you so much!
  • AirAir
    edited February 2017 Posts: 10,970
    You asked me on PM about problem with /blog/ in your works category links.
    You probably missed this change
    Air said: And add in both cases missing part , 'with_front' => false.
    Refresh permalinks settings, and tell me how it went :-)
    As explained here http://stackoverflow.com/questions/15617820/wordpress-custom-permalink-for-just-posts#15619416

    With kind regards.
    Post edited by Air on
  • Thanks Air,

    yes I have both these lines in the plugins php file just as you said:

    'rewrite' => array( 'slug' => $work_slug, 'with_front' => false ), 'rewrite' => array( 'slug' => $album_slug, 'with_front' => false ),

    Thats why I was confused as this was already in place.
  • AirAir
    Posts: 10,970
    OK I have mistaken taxonomy of works, which is work_genre, with "work" post type.
    Thanks to you I have learned something new:-)

    Do what follows:
    Go to : wp-content\plugins\a13_framework_cpt\a13_framework_cpt.php line ~182
    Find there:
    
    				"rewrite"           => array(
    					'hierarchical' => true
    				),
    change it to:
    
    				"rewrite"           => array(
    					'hierarchical' => true,
    					'slug'  => 'work-type', // this what you asked me about in PM
    					'with_front' => false , // this will remove /blog/ part
    				),
    Same thing you can do for albums in line ~90 but you have to use different unique slug if you want to change it also.

    Remember to refresh permalinks after this change! It means set them to Default, save, set them back to what you want, save:-)

    I think I will add option to change these slugs to theme in future, as I didn't know it was possible before.

    With kind regards.
  • Air said: Thanks to you I have learned something new:-)
    That's what i'm here for Air ;) I like a good challenge and i'm sure you do too!

    Air said: Do what follows:
    Ok sure I shall give this a go and let you know in an hour or so!

    Thanks again
  • Hey Air,

    this worked perfectly thanks!

    One issue I am having now though (although its not a huge one) is that I would like to be able to link to the work type/portfolio categories individually from within a single page. So in a blog post, or a single page somehwere on the site, I would like to add a link that shows all the porfolio/work categories within Web Design for example.

    To do this, I am using a relative path for the work category, that shows up when you hover within the portfolio/works list.

    For example, when I hover over the Website Design tab in the categories list on works/portfolio page, the link in the bottom of the browser displays as: "http://www.myurl.com/work-type/web-design/", so when I then set the link within a page on the site to go to ../../work-type/web-design, for some reason on click, this does a 301 redirect and goes to http://www.myurl.com/portfolio/web-design (I assume due to this recent update), which results in a 404 as there is no child page within portfolio.

    Any ideas how I can either cancel the 301 redirect so it loads the path correctly, or how I can set the link in another page so it loads the correct URL for the category?

    Hope I have explained this ok, I refer to Portfolio/Works here so you are familiar which page this is, but for the record the theme's works page's slug is currently set to Portfolio.

    Log in details are in the PM I sent you a while back but let me know if you need this again.


    Thanks
  • Ah, It was caching a 301 I set in .ht-access file that I set a while ago to, as a test to see if that fixed a separate issue! So now the cache is cleared, it loads as it should and works with ../../work-type/web-design and loads all the content for that category.

    Next thing now is to work out if there is a way to have the categories show up in the page still, as now its set this way, it only loads the images within the web design category and not the list of all the categories.

    One way I thought it could work would be to add a query string within the hyperlink instead, so it could load the page and then perform the category selection function. A bit like this:

    http://www.myurl.com/portfolio/?work-type=web-design/ but obviously this doesn't work!

    The screenshot below shows how i'd like it to load vs how it currently does

    How it should be: https://cl.ly/0g1L1Z2G1l1g/Screen Shot 2017-03-08 at 18.46.38.png

    How it currently is using a relative path: https://cl.ly/3b0W1g243d3e/Screen Shot 2017-03-08 at 18.56.09.png

    Any ideas?


    Thanks
  • AirAir
    Posts: 10,970
    Hi long posts writer ;-)

    So you don't see list of categories in category view, cause it displays only child categories(if there are any). It is made that way so one could create multiple albums/works list.

    If you go to fatmoon\parts\category-filter.php line ~41 and change
    if ( $category_template === true ) {
    to
    if (0 && $category_template === true ) {
    next do the same on line ~65.

    You will see all categories now, however it won't mark current category.

    Check if this is what you are looking for.

    With kind regards.
  • haha thanks Air, I struggle to get my point across in short sentences, so I write as much as I can to get a faster solution instead of waiting for further questions ;P

    Its not the end of the world if the current category isn't marked I guess, I hoped there would be a much simpler solution to go to the page with the child category marked, by using a query string in the hyperlink. Never mind, I shall try this anyway and let you know.
  • Ok so it DID work...however now for some reason I cant actually select any of the other categories to load as a result. Think therefore its better to just have it load the way it does currently, without the filter option, as the "ALL" category is highlighted when the page loads, which would confuse people, plus selecting anything else other than whats in the page URL doesn't actually filter it, as its fixed on whatever was selected.

    Never mind, it was worth trying at least. Thanks anyway
  • AirAir
    Posts: 10,970
    You are right, this solution was not complete for your scenario as it would require more changes to work as you wish. I think complete solution might be out of support boundary, so lets keep it as it is:-)

    With kind regards.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!