Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need a little help and/or consulting for my next steps. (I'm a beginner!)

I've been working on my plugin, using a Custom Post Type "Project", some help from the plugin "Advanced Custom Fields" - and now I have succeeded in the general functionality. Have a look at the images here and http://www.project22.org/project/ to see the functionality. I admit, there might be plugins doing something similar, but I'm not advanced enough yet to understand and adjust their code to my specific needs ;(.

I worked within a child theme of Twentytwelve and needed to work with some template files, e.g. I created single-project.php and project_loop.php to use with get_template_part().

Problem:

  • I'm not so happy with Twentytwelve anymore - I'd like to retain some flexibility in changing my themes.
  • Maybe one day I want to share my plugin with someone, who knows?

So now my aim is to move all parts of the functionality into a plugin ...

Questions:

  • How can I display these little pieces of information related to various posts on any theme? I couldn't find appropriate hooks nor filters.
  • How can I avoid creating theme template files, which might later screw up new themes?

I'm really confused, where I should use []-Shortcodes, create template files or snippets, where I can hook or filter into.

I appreciate any advice from you, thanks Flo

share|improve this question
2  
You need to split this into separate Questions, one per issue. If you check the FAQ and How to Ask, you'll know how to make precise/answerable questions. For the main issue you're having, check Where to put my code: plugin or functions.php?. In general, you'll find very good stuff in the tag plugin-development. –  brasofilo May 24 '13 at 8:50
    
thanks a lot - I'll check those things, but so far I wasn't very successful. Maybe I just need some recommendations --- –  Flow May 24 '13 at 23:27
add comment

1 Answer

Shortcode is definitely a good start. It is very flexible in terms of where you output the content (widget, post, page, inside php function, etc).

You can also override the template output easily by using action hooks and custom post type that you create:

add_action('the_content', 'add_project_content');

function add_project_content($content) {
    // Only override the content of project custom post type page
    if (is_singular('project')) {
        // You can re-use original content stored in $content and simply add things before and after, or you can simply override them with something new
        $content = "whatever you want";
        $content .= somefunction_output();
    };

    return $content;
}

This will lift you up from having to deal with template files and worry about matching changes for theme updates. With these methods I get away with creating any extra template files in my child theme folder.

share|improve this answer
    
You're code proposal is using an action hook, so it actually replaces the old $content, right? I mean it doesn't filter.?. –  Flow May 25 '13 at 12:10
    
And one more question on the_content() - would that be one of the main areas, a theme developer will adjust and redesign? To me it sounds like I shouldn't just override it ... –  Flow May 25 '13 at 12:12
    
The content override generally just replace the user input data from the main editor (WYSIWYG / HTML) so you are not really changing theme structure. So you already have complete freedom in that area anyway and this hook just help you programmatically generate them. For example, if you create a custom post type for each employee, you can restrict the data entry via method like Advanced Custom Field to only enter name, title, and bio. Then, you can write the action hook for that custom post type so that content is always output in your desired structure that simply replace the 'content' area. –  Elisha Terada May 25 '13 at 12:59
    
So this is a nice way to work with whatever current theme you are using without having to copy the PHP template that you cannot re-use in other themes. –  Elisha Terada May 25 '13 at 13:02
    
thanks - I'm checking things now –  Flow May 26 '13 at 6:02
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.