WordPress.org

Ready to get started?Download WordPress

Forums

Code to have one category in a page (18 posts)

  1. parcifal
    Member
    Posted 6 years ago #

    Hello,
    I seek for the php code wich allow me to publish the content of one category in a static page. I mean I want all the articles of this category in my page.
    Do u know what is the code for that?
    Thx for your answer.

  2. moshu
    Member
    Posted 6 years ago #

    No, you shouldn't do that. There is no reason to do anything like that.
    Pages are not meant to display multiple posts.
    Use Category_Templates instead.

    (just curious: WHY do you want to do something in the hard way when it is already built-in?)

  3. parcifal
    Member
    Posted 6 years ago #

    because for me it's very simple to use the system of the articles instead of use html text. I think it's just a question of replace the text of my home page by one who show only one category

  4. moshu
    Member
    Posted 6 years ago #

    because for me it's very simple to use the system of the articles instead of use html text.
    This just doesn't make sense as an aswer to my question: Why a Page (and I really mean that you read that article!!!) when the Category Template does exactly what you want: displays posts from one single category.

    it's just a question of replace the text of my home page by one who show only one category
    Changing "text", a.k.a. content on your homepage has nothing to do with how posts are displayed. I guess you meant "code".

    If that's what you want: displaying posts only from a certain category on your homepage... the why don't you ask THAT question? Don't assume you know the HOW. You, obviously, don't.
    So better describe WHAT you want to achieve, and we will tell you the how-to.
    For excluding posts from the homepage - you need a plugin.
    Like this one: http://wordpress.org/extend/plugins/advanced-category-excluder/

  5. parcifal
    Member
    Posted 6 years ago #

    hey
    Thank you for your answer, excuse my poor english i am french.
    I've find some days ago the php code to exclude the category n°9 to my homepage so no problem.
    Now the thing is to display the content of this category 9 in an other page wich show the content like that link:

    "http://mon_blog.com/?cat=3"
    .
    My question is simple what code (php) i have to insert in this page to display just this category? how can i build a page (virgin) with simple code wich show the content of one category

  6. MichaelH
    Member
    Posted 6 years ago #

    I'd think a Category Template would serve you.

    Resources:
    Stepping into Templates
    Template Hierarchy

    If it is required that a Page handle this then you want to look at the query post category parameters also.
    http://codex.wordpress.org/Template_Tags/query_posts#Category_Parameters

  7. moshu
    Member
    Posted 6 years ago #

    My question is simple what code (php) i have to insert in this page to display just this category?

    You don't have to anything. WP does it for you out of the box.

  8. parcifal
    Member
    Posted 6 years ago #

    sorry to be a such noob but when i insert the following code :
    <?php query_posts('cat=9'); ?>
    in my page it doesn't show the content of my category :/
    Sorry but i am not very good at php and i do this site for my school i'm quite lost with all this stuff.

  9. parcifal
    Member
    Posted 6 years ago #

    Can you give me all the code i have to insert in my page?
    Or where can i find this code in what file?

  10. moshu
    Member
    Posted 6 years ago #

    Hmmm...
    Whenever we are talking about code - it must be put in the files, never in the content of a Page or of a post.

    I still don't understand WHY are you trying to do this the hard way. Why not simply use the Category Templates as it was told several times?
    What is the reason you want stubbornly this Page solution? Explain...

  11. parcifal
    Member
    Posted 6 years ago #

    Because when I create a page in my wp's interface it's very simple because it's create a button in the top automatically.

    If i don't use the system of a page I don't know how to create a button like that.

  12. moshu
    Member
    Posted 6 years ago #

    We could have saved a lot of typing and time if you have posted THIS question at the very beginning... :)
    Se if this helps:
    http://www.transycan.net/blogtest/2007/07/26/pages-and-categories/

  13. parcifal
    Member
    Posted 6 years ago #

    To explain that look at my site http://cinetrip.tk/.
    It's very hard to put in form the page "bons plans". It's why i want to replace the content of this page by the category 9 that i have created.
    Can you tell me the steps to do that?

  14. moshu
    Member
    Posted 6 years ago #

    I don't see anything complicated in that.
    Put your header.php in http://wordpress.pastebin.ca and post back the URL.

  15. parcifal
    Member
    Posted 6 years ago #

  16. moshu
    Member
    Posted 6 years ago #

    Try this
    http://wordpress.pastebin.ca/757899

    Replace CAT TITLE with your own category name/title in the code!

    Oh, and delete the Page with the same title!

  17. parcifal
    Member
    Posted 6 years ago #

    Ha yes you rocks!!! it's work !
    Thank you for all!

  18. wpNewbie80
    Member
    Posted 5 years ago #

    Hello, I have been trying a similar thing..to list posts from a particular category on a Page. My reason for doing it this way is that my Page navigation is displayed via a plugin within a widgetized sidebar.

    Would it still be possible to add a link to a particular category archive to appear within my navigation rather than a link to the Page?

    thanks

    j

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.