• Hey, I am using Headway as a theme and have been working quite a bit with it.
    I am creating pages and childpages using wordpress and fetching the pages to different blocks in my headway theme.

    The problem I have can be illustrated with a simple example:

    I have a FAQ page.
    https://www.website.com/faq
    On this page I am using the content from two pages within wordpress.
    FAQ (parent)
    Generel (child of FAQ)
    I am fetching both of the pages content to the https://www.website.com/faq entry.
    The challenge is, that even if I’m fetching the content on a single page – users will still be able to manually type https://www.website.com/faq/generel to reach my general child page and thereby breaking my design.

    Is it possible to disable permalinks of child pages?

    Hope you can give me a hack for this. Thank you.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Just to ask a silly question, why can’t the content of “Generel” be moved into the “FAQ” page and then simply delete “Generel”?

    The simplest (untested) solution that I can come up with is to modify your header.php template file adding this at the top:

    <?php
      global $post;
      if ($post->post_parent > 0) {
        wp_redirect(get_permalink($post->post_parent), 301);
        exit();
      }
    ?>

    However this simple code will behave nastily if you have a large and unwieldy hierarchy of pages. If you just have a top level and a second level, it will be fine.

    Thread Starter mr.hoelgaard

    (@mrhoelgaard)

    The idea behind making more pages, is that I am able to fetch different bits of content to different blocks on the page and style them differently.

    Does that mean there is no easy and clean way? I would very much like to avoid bad habbits, since I am afraid that it can snowball.

    Ah ok, now I understand what your goal is. The best way to do this is to create a custom post type that is not publicly accessible and use that instead. Put this in your theme’s functions.php file:

    register_post_type('text_blobs', array(
            'labels' => __('Text Blobs'),
            'description' => __('Content Used Throughout Site'),
            'public' => false,  //Do not allow this to be accessed publicly
            'show_ui' => true,
            'hierarchical' => false,
            'capability_type' => 'page',
            'menu_position' => 100,
            'has_archive' => false,
            'revisions' => false,
            'supports' => array('title','editor')
          ));

    Then in your admin you should see a new post type called, “Text Blobs.” You can create your content blocks here and import them into the page just like you’re doing now.

    Thread Starter mr.hoelgaard

    (@mrhoelgaard)

    hmm, sounds like a nice fix.

    It does not appear on my menu when I add your code.

    wordpress support

    I do suspect there will be a difficulty fetching the content of the text blobs. I have been using headway to fetch page content, not sure if I can do the same with posts and other.

    View post on imgur.com

    Okay, now im just uploading random screenshots, hoping it helps. ??

    An illustration of my page can be seen on https://cookingcards.dk/abonner/ – here the different blocks need different content and styling, and to not create bad habbit and coding, i want to take the content from wordpress pages. This way I wont lose all my content if I change theme.

    Its easy to archieve what I want by using headway “text blocks”, but it also means everything will be lost if I decide to use something else than my headway theme in the future – which is not good…

    Maybe it should be hooked into the init event. Try this version:

    function blog_cpt() {
    register_post_type('text_blobs', array(
            'labels' => __('Text Blobs'),
            'description' => __('Content Used Throughout Site'),
            'public' => false,  //Do not allow this to be accessed publicly
            'show_ui' => true,
            'hierarchical' => false,
            'capability_type' => 'page',
            'menu_position' => 100,
            'has_archive' => false,
            'revisions' => false,
            'supports' => array('title','editor')
      ));
    }
    
    add_action('init', 'blog_cpt');

    The good news is that this is the correct way to go about what you’re doing. If you start altering the way that the “page” post type works, it’s going to affect every page on your website.

    The content can be included in the exact same way as before. This is a post type just like a page is a post type. Everything is even stored in the same database table.

    Give this version a go and let me know if it works.

    Thread Starter mr.hoelgaard

    (@mrhoelgaard)

    I will test this out later tonight, and give you a reply.

    Thank you so far for your time.

    Thread Starter mr.hoelgaard

    (@mrhoelgaard)

    So I tested it already, and the text_blobs is showing as another “indl?g” tab. I created a post, and I managed to fetch it. It does seem a little disorganized though.

    If I fetch by ID of the post, where can I find which IDs the different posts have?

    The good news is that there is no child permalink. The bad news is, if I create a lot of posts and try to fetch them in different places, the whole thing will get very big and disoganized on the backend. With pages I can organize my stuff with parents and childs.

    Maybe there is another way to go about it?

    Oh you can enable hierarchies with this post type as well. Custom post types have all of the functionality of the post and page post types that WordPress comes with.

    Just change:

    'hierarchical' => false,

    to:

    'hierarchical' => true,

    Then you can set children and parents just like a page.

    The easiest way to find the ID is to look in the address bar when you’re editing a blob. You’ll see post=#### that references the ID.

    Thread Starter mr.hoelgaard

    (@mrhoelgaard)

    Hey again,

    I have begun testing today again, and now I’m getting:

    Parse error: syntax error, unexpected ‘&’ in /var/www/cookingcards.dk/public_html/wp-content/themes/headway/functions.php on line 24

    I pasted in my function file just like this:

    View post on imgur.com

    Any idea what might cause this?

    Thread Starter mr.hoelgaard

    (@mrhoelgaard)

    Hey, I figured the mistake. My email was rendering the wrong signs and I had to copy paste from here. So far so good. ??

    So I′ve enabled hierachical now, but I am still not getting the options on the edit page. Seems like an UI for hierachical ordering is missing. Is there a way to show this?

    Also would there be a way to show the ID on the edit page?

    Screenshot:

    View post on imgur.com

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Disable page permalinks’ is closed to new replies.