WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Specific Category Page Template (18 posts)

  1. rufaswan
    Member
    Posted 6 years ago #

    I was wondering can I customize a page template to display all post under one specific category only.

    Then the post will have excerpted content (said 20 words) below the title.

    And the most important part is all post displayed must be sorted alphabetically, according to title.

    And that's about it.

    P/S I was able to find this link, but I have no clue how to customize it
    http://wordpress.org/support/topic/112230?replies=2

  2. moshu
    Member
    Posted 6 years ago #

    Forget Page as in Pages. That's a different thing.
    All you need is here: Category_Templates

    And clicking on a category name will always display ONLY posts from that category, it is done out of the box by WP.

  3. rufaswan
    Member
    Posted 6 years ago #

    Well moshu, the page I'm trying to do is something like when you clicked on the "categories" or "tags", and have page 1, page 2 navigation below.

    The only difference is the post are not sort according to date. It should be sorted by alphabet for easy navigation.

    BTW please do not ask me to modify any of my wordpress core files. I don't know how to re-create this "miracle" after an update.

  4. moshu
    Member
    Posted 6 years ago #

    Did I mention anything about modifying any WP core files???
    No, I didn't.

    Did you read the resources I linked to?
    I will write here the short version: DO NOT USE PAGES. Period.

    First make working category templates. Not Pages but category template files (e.g. category-1.php, category-3.php etc. - the sidebar thing can be applied to them, too)
    After that we will take care of the alphabetical order.

  5. rufaswan
    Member
    Posted 6 years ago #

    Hey moshu, don't be so angry.

    And yes, I did went through the link, but forgive me for I am not a programmer, I don't really understand how to do it.

    Since you mention about some php files, I done a google search, I assumed that those files are located within the template directory.

    Then, I edit the file with my limited understanding of that page. Here is the file:

    <?php

    /*

    Template Name: Archieve
    */

    ?>

    <?php get_header();?>

    <div id="main">

    <div id="content">

    <div class="post">

    <h2 class="title">" rel="bookmark"><?php the_title(); ?></h2>

    <div class="entry">

      <?php query_posts('cat=4&showposts=10'.get_option('posts_per_page')); ?>
      <?php the_excerpt(); ?>

    </div>

    </div>

    </div>

    <?php get_sidebar();?>

    <?php get_footer();?>

  6. moshu
    Member
    Posted 6 years ago #

    That's a Page template. I don't know how to do it with Pages.

    I told you how it should be done the easy way. You don't need to google for anything: everything is written down at the Codex turorials.

    If you want to do it in another way - don't ask me.
    (I am not angry - yet...)

  7. rufaswan
    Member
    Posted 6 years ago #

    At least I got ONE thing right.

    But I have problem to understand the tutorial. I don't know where and how to put it those code.

    Maybe there is some copy-and-paste solutions out there, somewhere...

  8. moshu
    Member
    Posted 6 years ago #

    You do NOT use that code of yours because it is not good.

    You save your index.php or archive.php file (NOT the archives.php Page template!!!) as category-xx.php file(s). Edit them for the inclusion of your custom sidebar.
    What is soooo complicated in this?

    Then use a plugin like CQS to set the number of posts shown and the order.
    Done.

  9. rufaswan
    Member
    Posted 6 years ago #

    Why don't you tell me about this plugin from the beginning, this plugin rocks!!

    It completely solved my problem. All thanks to you!

    So now, problem solved, case closed!

    See ya!

  10. moshu
    Member
    Posted 6 years ago #

    Why don't you tell me about this plugin from the beginning,

    Because you were obsessed with Pages... and the plugin is not for Pages. That's why. I told you in my second post: take care of the properly functioning category templates and we will take care later of the alphabetical order. But when users have preconceptions - they are not receptive to common sense solutions.

  11. rufaswan
    Member
    Posted 6 years ago #

    Hi moshu, I'm still around. Never though of that do you?

    Well, thanks to you, I can somehow solve the problem, at least with some tweaking, for now.

    And BTW, I hope you won't mind if I want to dig to the bottom of this. I wish to understand the "solution" that you intended for me. Nothing special, just for the sack of curiosity.

    I noticed this part, but I cannot find any matching place to put:
    http://codex.wordpress.org/Category_Templates#What_categories_do_you_show_to_the_visitors.3F

    And it say something about query_post, place before the loop, that I have no clue what to do.

    If you want the achieve.php, here it is.

    [code removed]

  12. moshu
    Member
    Posted 6 years ago #

    1. I never want code here - nobody can read it.
    (use a pastebin service, like http://wordpress.pastebin.ca if you feel the urge to post a long code)
    2. There is no achieve.php template file.
    3. That's a completely stupid and wrong part on that Codex page: it is about archive.php and NOT category templates. Should be removed. Sorry, that's not your fault!
    4. Don't post code and don't get technical. Ask in plain, simple English WHAT do you want to do. WHAT is the result you want? We will tell you the HOW. It saves a lot of time and anger...

  13. rufaswan
    Member
    Posted 6 years ago #

    Sorry for that, I thought you need to see the code, that's why I post it.

    So... how?

  14. moshu
    Member
    Posted 6 years ago #

    So, "how" what?
    Don't show me code. I am code illiterate. Describe me what is the desired end result what you want.

  15. rufaswan
    Member
    Posted 6 years ago #

    You said

    "3. That's a completely stupid and wrong part on that Codex page: it is about archive.php and NOT category templates. Should be removed. Sorry, that's not your fault!"

    but you also said

    "You save your index.php or archive.php file (NOT the archives.php Page template!!!) as category-xx.php file(s). Edit them for the inclusion of your custom sidebar."

    What is the meaning of these? Aren't they the same? And what should I do?

    And most important of all, what result did your "solution" was intended to give? Same thing as your plugin?

  16. moshu
    Member
    Posted 6 years ago #

    Listen! Forget EVERYTHING you tried to do till now, before you started to ask. Everything.

    Close your theme's files. All of them.

    Open an unaltered (virgin) copy of the default theme.
    Look at the file names.
    There is
    archive.php
    and there is
    archives.php (with plural S at the end)

    Those are two very different things - and you are mixing them all the time. I am open to arguments if you know what are you talking about. If you don't, just follow the instructions to the letter.

    archive.php (no S) is a template file used to list/display the monthly and category archives: i.e. listing posts for one month or for one category. That is the file you were supposed to work from!!!

    archives.php is a Page template - close it and forget it. We will not work with it. Period.
    We will not work with any of your Page templates either. Close them. Throw them away... whatever.

    When you understood this, come back and we will take it from there.

  17. rufaswan
    Member
    Posted 6 years ago #

    There is
    archive.php
    and there is
    archives.php (with plural S at the end)

    Nope, they are only archive.php (the one you said it is too long and deleted it) and page-archives.php (which is the short code I put earlier)

    I presume you meant the long one. OK now, the file is opened in front of me.

  18. moshu
    Member
    Posted 6 years ago #

    Your page-archives.php must be the same as archiveS.php - at least regarding its role and use.

    [Good reading about the Template_Hierarchy]

    In a normally made theme and a simple WP setup the result (read: the display of) the archives Page template should be something like this:
    http://www.transycan.net/demo/archives/

    However, the archive.php is used to display listing of posts, e.g. for a category:
    http://www.transycan.net/demo/category/important/

    or a month:
    http://www.transycan.net/demo/2007/07/

    Your original question was regarding a "category archive" - listing post in ONE category. This is done by WP just by clicking on a category name.
    Now, if you wanted a separate sidebar for each category listing, you were supposed to use Category_Templates - a separate file for each category calling for its sidebar (or one category template file with a lot of conditional tags to call different sidebar for each category).

    The easiest way to make a category template is to save archive.php or index.php as category.php (if a general template is the goal) or save it several times as category-xx.php where xx = the category's ID number.
    After that you can edit teh template tags in it, e.g. replace the_content with the_excerpt and so on.
    Simple, effective, clean.
    Then with the plugin you set the number of posts shown and the order of them.

    This is the normal way to do it.
    Using Page templates... is the abnormal and complicated way.

Topic Closed

This topic has been closed to new replies.

About this Topic