• I want to use template tags on a page to show only posts from one category. It seems that template tags are the best way to do this. However, can I post the PHP code directly in the editor?

    The blog is set up on a page at site.com/blog
    I already used PHP template tags to exclude the blog category from the main page so that’s fine.

    This is the code so far
    <?php
    query_posts(’cat=6′, ’showposts=10′);
    ?>

    I probably got the formatting wrong since I’m not a programmer. Also, how can I set up a back button so people can go through older posts?

Viewing 10 replies - 1 through 10 (of 10 total)
  • I want to use template tags on a page to show only posts from one category.

    WordPress already does this for you. E.g.: “www.your-blog-domain.com/category/your-category-name/” only shows the posts in the “your-category-name” category. If you want a custom page for that category, you can create a category template page named “category-6.php” where “6” is the ID of the category you want. See the Template Hierarchy.

    If you really want a page instead of linking to the category archive, then instead of using PHP inside the content of a page, create a Page Template with the code you want. Then for the particular page, select that template in the Page Template drop-down box.

    (Yes, there are plugins that will allow PHP inside a post or page, e.g. Exec-PHP, but, personally, that should be a last resort, especially when WP’s templating features can be used, instead.)

    Also, how can I set up a back button so people can go through older posts?

    See Codex: Blog Design and Layout — check out the “Next and Previous Links” page.

    Thread Starter clockworkjoe

    (@clockworkjoe)

    How do you apply a template to a specific page? I don’t see any drop down menus.

    Thread Starter clockworkjoe

    (@clockworkjoe)

    Actually, is there any way to take my current page: site.com/blog and apply site.com/category/blog to it?

    What do you mean “apply”? That is a category structure. It’s dynamically generated if you set it up in the permalinks tab. Are you sure you know what you want? Because I’m not.

    *winds up clockworkjoe and points him in the direction of scribblerguy’s post*

    Read that again, particularly the part about page templates, Joe.

    If you want to create a new page template, here’s where I’d start:
    https://codex.www.ads-software.com/Pages#Creating_Your_Own_Page_Templates

    Thread Starter clockworkjoe

    (@clockworkjoe)

    Then for the particular page, select that template in the Page Template drop-down box.

    I have no idea where that is. I don’t see it anywhere.

    Read the link I provided. It explains how to create a page template that will appear in the Page Template dropdown box.

    Have you created the page template file and uploaded it to your theme directory?

    i created a file called category-6.php but i dont see it in the template drop down?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘can i use php when writing a post or page?’ is closed to new replies.