WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Page Templates vs Categories (24 posts)

  1. steverobertsco
    Blocked
    Posted 3 years ago #

    Hello WordPress Folks!

    I have a new question being a new starter. If any would like to help me and I will respond to all replys. Thank you in advance.

    Here is the question.

    Do I need to create a page template for each page?
    or can I do this using Categorys and how?

    Here is what I mean. I have three templates. The index.php, gallery.php and page.php.

    I have around 8 pages I want in there based on the page.php template. How do I get it so that I can have all these pages using that one template?

    My easy option idea is to create a template for each page so that I can put in the id's where needed.

    Please help!!?

    :)

  2. steverobertsco
    Blocked
    Posted 3 years ago #

    Just to update this question. :)

    I know about the Template Hiererchy but unsure if this fits in or does not explain exactly what I need to know. Just furthering what I mean so you all understand.

    I have created for example:

    Homepage posts which go to id's which are uncatergorized so to go to the home page.

    I have created an 'About' post which goes to a category named 'About' which I also have a Page called 'About' which links to the page.php template.

    The above works fine but I have had to in the page.php template put an id in there for the id from the About post. Now thats all fine but I need another post, category, page liking to the same page.php template file which has an id already in there. In the php template file, is there a code to place in there?

  3. steverobertsco
    Blocked
    Posted 3 years ago #

    Bump! Anyone?

  4. steverobertsco
    Blocked
    Posted 3 years ago #

    Anyone at all?! Please help?!

  5. steverobertsco
    Blocked
    Posted 3 years ago #

    Im thinking my further posts on this post is making it look like it is gettings replys but it is not resolved. Can anyone help?

    I feel its just a simple question for anyone who knows wordpress unlike me being a beginner. Any help?

  6. steverobertsco
    Blocked
    Posted 3 years ago #

    PLEASE HELP?! ANYONE?!

  7. steverobertsco
    Blocked
    Posted 3 years ago #

    Its all me so far. Ok Ill try and make this question easier.

    How do I get a specific post to a specific part of a page?
    I am php savvy but new to wordpress. Please help?

  8. keesiemeijer
    moderator
    Posted 3 years ago #

    It isn't exactly clear what you want to do.

    All Posts go to the home page (Pages do not).
    You can create a custom Page template to show's post of a certain category with a query posts on the loop
    http://codex.wordpress.org/Function_Reference/query_posts
    http://codex.wordpress.org/Function_Reference/WP_Query

    http://codex.wordpress.org/Pages#A_Page_of_Posts

  9. steverobertsco
    Blocked
    Posted 3 years ago #

    Sorry. Thanks for the reply. I will read those links but will just post what I do first.

    Ok, How I have figured out how to do this which is probably the worst and most time consuming.

    1) I create a template .php file for each page.
    2) create a post for each section I want to edit.
    3) Create a category for each post.

    The code I put in the template for the section where the post is gonna go is the following:

    <?php
    $second_query = new WP_Query( array( 'cat' => '23' ) );
    			while( $second_query->have_posts() ) : $second_query->the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; wp_reset_postdata(); ?>

    Ok. Is this correct or is there an easier way to do this?

  10. steverobertsco
    Blocked
    Posted 3 years ago #

    Just to add something I forgot. I also create a page for each page aswell as a template for each page.

  11. keesiemeijer
    moderator
    Posted 3 years ago #

    If you want to show Posts with a category ID 23 on a "Page" that's the way to do it (the code I mean).

    With the WP_Query you alter the loop that would normally show a Page.

    You can also just use archive.php or category.php to show these posts with ID 23.

  12. steverobertsco
    Blocked
    Posted 3 years ago #

    Thank you so much. That is a big help. Good to know once ive got something wether it is right or not. Thank you

  13. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    Can you describe in more detail exactly what you're wanting to accomplish?

    Static Pages, by default, use the page.php template file.

    The category.php template file is used to output a category archive index.

    The index.php template file is simply the default fallback, that WordPress uses when no other, more-specific template file is available.

    So, can you explain what it is you want to do?

  14. steverobertsco
    Blocked
    Posted 3 years ago #

    I thought static pages by default use the index.php?

    This is going to be used more as a CMS so I believe the category.php is more for blogging and can work with ecommerce.

    As above. What I do in order is:

    1) I create a template.php file for each page.
    2) I create Page for each page and template file
    3) I create a post for each section on the pages I want to edit.
    4) I create a category for each post.

    Is that a correct format or is there an easier way? What I was thinking wordpress does is that I create a template and then can have all my Pages use that one template, and I know this can be done but in the php code of that template I only know how to put in the id to that particulur category or even post. I want it so that it will show that Post for that Page.

    I hope that makes sense. Also does anyone have the php code to place in a menu?

  15. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    You should review the Template Hierarchy Codex entry; it will be helpful.

    I thought static pages by default use the index.php?

    No; static Pages use the page.php template file by default. The actual hierarchy for static Pages is:

    1. Custom Page Template (user-defined, via the Page Attributes metabox on the Edit Page screen)
    2. page-{slug}.php (where {slug} is the Page slug - e.g. for a Page titled "About Me", the default slug is about-me)
    3. page-{id}.php (where {id} is the numeric Page ID)
    4. page.php
    5. index.php

    So, index.php is only used if none of the previous 4 template files is found.

    This is going to be used more as a CMS so I believe the category.php is more for blogging and can work with ecommerce.

    Right; the category.php template file has nothing to do with static Pages.

    As above. What I do in order is:

    1) I create a template.php file for each page.

    Why do you do this? What are you trying to do?

    2) I create Page for each page and template file
    3) I create a post for each section on the pages I want to edit.

    Why are you creating Posts related to Pages? Generally, you should not cross the use or content of Posts and Pages. Posts are blog posts. Pages are static content.

    4) I create a category for each post.

    Is that a correct format or is there an easier way?

    I'm still not sure what you're trying to do.

    If you're just trying to create static content, can I suggest, for the time being, just create static Pages, and don't worry about template files? Switch to a Theme such as TwentyEleven, create some static Pages, and then see how those Pages are output on the front end. Once you're comfortable with how to create content in WordPress, and how WordPress displays that content, only then should you even start to think about template files, and custom template files.

    What I was thinking wordpress does is that I create a template and then can have all my Pages use that one template, and I know this can be done but in the php code of that template I only know how to put in the id to that particulur category or even post. I want it so that it will show that Post for that Page.

    That template file is page.php. You don't need to put any Page IDs in page.php; WordPress already knows to use it for static Pages.

    I hope that makes sense. Also does anyone have the php code to place in a menu?

    I would start a new thread for your menu question.

  16. steverobertsco
    Blocked
    Posted 3 years ago #

    If you're just trying to create static content, can I suggest, for the time being, just create static Pages, and don't worry about template files? Switch to a Theme such as TwentyEleven, create some static Pages, and then see how those Pages are output on the front end. Once you're comfortable with how to create content in WordPress, and how WordPress displays that content, only then should you even start to think about template files, and custom template files.

    If I had the time, I would. Im just basically looking to build a cms site using wordpress, I know it can be done. What I told you that I do is just to give you an example and to see if you know of any other way.

    Pages seem to help towards getting an idea of what page is what, or is that done through categorys.

    I would start a new thread for your menu question.

    I did about two hours ago.

  17. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    Im just basically looking to build a cms site using wordpress, I know it can be done. What I told you that I do is just to give you an example and to see if you know of any other way.

    There is a better way: just pick a Theme, and start creating content. :)

    If your site is mostly (or all) static content, you'll want to make one settings change in particular:

    1. Go to Dashboard -> Settings -> Reading
    2. Change "Front Page Displays" from Your latest posts to A static page
    3. In the "Front Page:" dropdown list, select the static Page you want to use as your site's front page
    4. In the "Posts Page:" dropdown list, select the static Page you want to use to display your blog posts. If you don't want to display any blog posts, then leave this dropdown empty/unchanged.

    Really, that's all there is to it. Any current Theme will handle display of static Pages with no problems. If you just want to get a site up quickly, don't worry about messing with template files. You honestly don't need to.

  18. steverobertsco
    Blocked
    Posted 3 years ago #

    Its ok. Thanks :)

    Ive already got as far as now having the site up with the templates in place etc. Its all there now. I created a template for each page and a category for each page and section of a page to put a post in that section. Probably the long wrong way of doing it but it works.

    So I did that instead of having a seperate template for say two or more pages, I created a template for each page so to be able to put the right id of that category in that template.

    Maybe you can help me on my menu question? :) Thank you Ill just put this one as solved for now.

  19. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    Ive already got as far as now having the site up with the templates in place etc. Its all there now. I created a template for each page and a category for each page and section of a page to put a post in that section. Probably the long wrong way of doing it but it works.

    This is where I'm confused. Pages don't have Categories. Categories are a taxonomy that applies only to Posts, not to static Pages.

    So I did that instead of having a seperate template for say two or more pages, I created a template for each page so to be able to put the right id of that category in that template.

    Do you have a live example of what you're doing? Maybe seeing it will help me understand what you're doing.

    Maybe you can help me on my menu question? :) Thank you Ill just put this one as solved for now.

    Looks like esmi is getting you squared away, but I did add a bit to that thread also. :)

  20. steverobertsco
    Blocked
    Posted 3 years ago #

    Here is the site being developed in wordpress Link and here is the original Link.

  21. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    Okay, that helps!

    I think I see what you mean by "sections" of Pages; though, really, all the content on any given Page can still simply be one Page.

    Now: what are you doing with "categories" for each Page? I still don't get that part.

  22. steverobertsco
    Blocked
    Posted 3 years ago #

    Ok for some reason. I have to have a category for each section of a page. For example:

    I have a page with two sections that need to be editable seperatly. Of course I have a post for each section say #description and #news_item for example. I have a post for each one and within the template to that page I have an id. Now this id can be the id of the post but I have put it as an id for the category and created categorys description and news_item. So now if I go to that post to edit it, on the right I click the correct category that that post goes into.

    I hope that makes sense. For some reason I have to have a category for each post.

  23. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    Are you saying that you have to have a category for each section of the page, because of user requirements, or because of WordPress?

    I have a page with two sections that need to be editable seperatly. Of course I have a post for each section say #description and #news_item for example. I have a post for each one and within the template to that page I have an id. Now this id can be the id of the post but I have put it as an id for the category and created categorys description and news_item. So now if I go to that post to edit it, on the right I click the correct category that that post goes into.

    Which Page behaves this way? The one your originally linked (the About Us Page) doesn't appear to follow the description above.

    I hope that makes sense. For some reason I have to have a category for each post.

    That is true. Posts are required to have at least one category. However, if you're using WordPress primarily to manage static content, then you shouldn't be using Posts to generate that static content.

  24. steverobertsco
    Blocked
    Posted 3 years ago #

    No. Its just me being a beginner and unsure how to do it after many goes of trying.

    Which Page behaves this way? The one your originally linked (the About Us Page) doesn't appear to follow the description above.

    Thats just an example.

    That is true. Posts are required to have at least one category. However, if you're using WordPress primarily to manage static content, then you shouldn't be using Posts to generate that static content.

    Thats what i thought. They are static pages but I have created i page for each one from the Pages section of the dashboard.

Topic Closed

This topic has been closed to new replies.

About this Topic