• I want to create about 5 Components with content, and what I create a new post I can choose one (or more) of those components top add in the end of the posts, so if I make changes in one of the components – It will change in all the posts. can I do this?

Viewing 15 replies - 1 through 15 (of 17 total)
  • Sounds like you could use a shortcode to load either a specified category of post, or a custom post type.

    Thread Starter tamarhp

    (@tamarhp)

    how do I do that?

    How good are your coding skills?
    Are you familiar with Custom Post types?
    What will be in the ‘components’?
    How often will the components change?
    Who will change the components – what skill level will they have?

    Thread Starter tamarhp

    (@tamarhp)

    I know php quite good,
    I want to be able to add and edit the components without getting into the code (it’s for my client, he doesn’t know how to develope…), so I prefer that the components will be posts or something like that – I just need to know how I can insert a content from one post in another post without change the code every time (after I give the site to the client). I’m quite new in wordpress..

    If categories are used for the components, will that cause problems in other parts of the site? Do you know how to exclude the categories from menus and searches?

    If categories are a problem, do you know how to create/use custom post types and taxonomies?

    Inserting the content into another post is fairly easy. The hard part is finding a way to store the content so it does not show up in other parts of the site! Custom post types and taxonomies are ideal for this, but can be complicated to set up. There are some plugins that can help if you can use them.

    Do you want to proceed with custom types?

    Thread Starter tamarhp

    (@tamarhp)

    Yes, I’ll be glad to hear more about this.

    [It’s a new site and we didn’t start yet, first I need to check what and how we can do things before we start..]

    Since you have not started yet, let me suggest that you use categories since that is easier to set up.

    You would start by creating categories for your components.

    You would install the Simply Exclude plugin and exclude the component categories from the Front Page, and possibly other uses.

    For each component, you would create a new Post and assign it one of the categories.

    Next, you would add code to your functions.php to define the shortcode. It would look something like this (UNTESTED):

    <?php
    // Function for shortcode to retrieve a component category post.
    // Example: [mm_component slug=category-slug]
    function mm_component_function ($atts) {
    	extract(shortcode_atts(array(
             'slug' => '',
                                    ), $atts));
    	$output = '';
       if ($slug) {
          $args = array(
             'category_name' => $slug,
             'posts_per_page' => 1,
             'numberposts' => 1,
             'caller_get_posts' => 1
          );
          $rows = get_posts($args);
          if ($rows) {
             $output = apply_filters('the_content',$rows[0]->post_content);
          }
       }
       return $output;
    }
    add_shortcode('mm_component','mm_component_function');
    ?>

    Finally, in your normal posts, you would use the shortcode to insert the component contents. Suppose the slug for ‘Component One’ is component-one. Then the shortcode would be like this:

    [mm_component slug=component-one]

    That should do it.

    Thread Starter tamarhp

    (@tamarhp)

    thanks, I’ll try!
    can I use the same category for all of the components?

    Thread Starter tamarhp

    (@tamarhp)

    mmm… it doesn’t work.. it accept the shortcode but it doesn’t show the content of the component.

    (I havn’t installed the plugin yet)

    you have any image for that post. Exactly what will you show in your post?

    have any URL for your site?

    Thread Starter tamarhp

    (@tamarhp)

    it’s just a try now –
    the component post: https://daatsolutions.info/merav_test/contacts/contact-lala/

    the post that I want to put the component into: https://daatsolutions.info/merav_test/sustainability/post-1/
    under the “texttext..” I put the shortcode..

    You must use a different category for each component. Then, you use the slug for the component you want in the post’s shortcode. So, if the contact-lala post is assigned category contacts, in the post-1 you would put [mm_component slug=contacts].

    BTW – if you site is to be ‘Industrial’, it is misspelled in the title and caption.

    Thread Starter tamarhp

    (@tamarhp)

    great!! it worked!

    and I’ll fix the error ??

    Thread Starter tamarhp

    (@tamarhp)

    Is there any way to put a content from a post without open a new category for that? like putting the slug/ID of the post in the shortcode (with a different function)?

    Sure. Just create a new shortcode and function, and change ‘slug’ to ‘post-id’, and ‘category_name’ to ‘p’ for the new function.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘different content’ is closed to new replies.