1

This should be a simple question. On websites like themeforest where you can buy themes others have built, when you preview the themes almost all the themes will have seperate pages for you to view seperate functionality

For example if a theme has a portfolio, a blog with sidebars, a blog without sidebar, a blog with 2 sidebars. They will link you to different pages to see what each looks like.

How do you do this? I mean if I just build a file called portfolio.php and put all my code to build that page, if I go to portfolio.php in the URI it isn't going to load that page, so how can I access a separate file, like portfolio.php

3
  • Puh... Templates can look & behave like different themes. Depending on what styles, scripts, images & layout you use for it. So they're simply: Pages with Templates.
    – kaiser
    Dec 10, 2011 at 12:10
  • @kaiser sorry you have misunderstood my question, I am not asking how to format a page. I am asking if I add the FILE test.php to my themes folder, how can I access this file is the question, no need for a downvote on a legit question. I know for a fact it is possible, I have seen themes with files named portfolio1.php portfolio2.php portfolio3.php these are note "pages" in WP with different styling
    – JasonDavis
    Dec 10, 2011 at 12:12
  • Add a template comment on top of them, assign them to a page and done.
    – kaiser
    Dec 10, 2011 at 12:36

2 Answers 2

1

Paste the Following code to the top of your template:

<?php 

/* Template Name: Portfolio*/

?>
<!-- Do stuff here-->

This will make the Template selectable as a page template in the Backend :)

2
  • Hi thanks I finally found that a little bit ago, I didn't realize that was a built in feature so I was looking for a solution to do it with posts and pages but now I see this feature and it is for pages. Technically it does answer my question that I had posted so thank you for that. Now what I realized that I really want is to be able to pick a template on a per posts basis. To do this there is a plugin but I don't want to go that route because I plan on adding this to a theme I will distribute. SO the solution I have come up with is to use a custom_meta_box then I can let the...contined
    – JasonDavis
    Dec 10, 2011 at 16:12
  • author select the template, just like the method you posted above but for posts. Then on my template file I can do something like $value = get_post_meta($post->ID, 'meta-box-name',true); if($value == 1){/* do this...*/ } else if($value == 2){/* do that...*/} and then include the appropriate template
    – JasonDavis
    Dec 10, 2011 at 16:15
0

This should work as far as I can tell, but it will cause your layout to break when the user fails do add the custom field, or adds it with a typo and so forth. Use Custom Post Types or Post Formats instead. Basically you can add a custom post type in your functions.php like so:

add_action( 'init', 'create_post_type' );
    function create_post_type() {
        register_post_type( 'review',array( //add a handle for your custom post type, should be something that explains the post type, not just generic my_post or some such
            'labels' => array(
                'name' => __( 'Reviews' ), //name can be anything
                'singular_name' => __( 'Review' )
            ),
            'public' => true, 
            'has_archive' => true,
            'rewrite' => array('slug' => 'reviews'),
            'supports' => array('title', 'autor', 'editor', 'comments', 'custom-fields', 'revisions')
            )
        );

You can then add template files for the custom post type by preceding their names with the custom posts slug, for example single-rewiew.php or achive-review.php.

Here is some more info: http://codex.wordpress.org/Post_Formats http://codex.wordpress.org/Post_Types#Custom_Types http://ottopress.com/2010/post-types-and-formats-and-taxonomies-oh-my/

Hope this gets you started in the right direction :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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