Viewing 15 replies - 1 through 15 (of 17 total)
  • I’m not sure what you’re asking, but I’ve made three guesses.

    1. Show the category(ies) associated with a particular post — for example just below the title?
    Inside the loop, the template tag the_category will do that for you.

    2. Show all the posts in a particular category on on page of your site?
    While it doesn’t appear anywhere in the list of WordPress “pages”, the address https://yoursite/category/your-category-name will show the posts in that category. The exact layout of the page in the browser will depend on which theme file is used to display the category. See the Template Hierarchy for a discussion of whether index.php, archive.php, category.php or a more specific file from the theme will be used.

    3. Show all the posts in a particular category on one specific WordPress page
    While you can create a custom page template to do this, it’s likely that you can get by with a category page as described in #2. The question then may be how to put such a page into your site navigation (since normally it is the WordPress pages that go there). If that’s what you’re wondering, please ask again because it can be done. Giving a link to which theme you are using may help people be more specific in answering this.

    Thread Starter jarred89

    (@jarred89)

    2. is sort of what I want.

    I want to display all the posts in a category on a page.

    Thread Starter jarred89

    (@jarred89)

    Anyone?

    In your page.php:

    <?php
    get_header();
    
    query_posts('cat=123');
    if(have_posts()) :
      while(have_posts()) :
        the_post();
        ?><li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php
      endwhile;
    else :
      ?><li>No posts.</li><?php
    endif;
    wp_reset_query();
    
    get_footer();
    ?>

    Thread Starter jarred89

    (@jarred89)

    Do all pages in wordpress have there own .php file?

    Jarred,

    Your wish (nr 2) is sort of standard in WP.
    Make a new category and assign posts to it or write (at least) one new post in that category.
    Depending on your theme, the category name will show up in the menu and when you click that menu item all your posts (or max 10 according to the seting under Dashboard/Settings/Reading) will be shown on “a page”. Again, depending on your theme, they will be shown as an excerpt or in full.

    I’ve got a similar issue. I need to be able to display all the posts of a particular category, but only for the latest week. Or if this is not feasible, then to just break them down by week.

    CATEGORY “FOO” PAGE which should display as follows, assuming Week 5 is the current week:

    Week 5:
    A post in category foo
    Another post in category foo
    Yet another post in category foo
    More foo

    Week 4:
    A post in category foo
    Another post in category foo
    Yet another post in category foo
    More foo

    Week 3:
    A post in category foo
    Another post in category foo
    Yet another post in category foo
    More foo

    And so on. I know I can pull all the posts from a certain category, but how can I tell WordPress to also break them down this way? Loops?

    Thanks!

    Oh, and Jarred, what you really need to do if you have a specific category that you want to do this with is just create a category template for that category. You need to go to the category page in the WP dashboard and find the category ID. Make note of it. Let’s assume it’s ID is 5. You’ll then name your new category template category-5.php

    You can then go hog wild and style the crap out of that template; you can choose excerpts (which I recommend) or full posts, just titles and dates or have it basically any way you want. This is something I do regularly.

    Here’s some more info on a custom category template:
    https://codex.www.ads-software.com/Category_Templates

    https://anthologyoi.com/wordpress/custom-category-templates-on-a-archive-or-index-page.html

    https://gabediaz.com/blog/custom-category-page-and-post-templates-for-wordpress/

    I take it the week blocks are seperate blocks on your site.
    This command: <?php wp_get_archives( $args ); ?> does weekly also.

    https://codex.www.ads-software.com/Template_Tags/wp_get_archives

    You can use it more than once in a template but how to make it dynamic, I would not know (assuming you are going for the 3 (or more) most recent weeks).

    Here it’s about time parameters, about halfway:
    https://codex.www.ads-software.com/Template_Tags/query_posts

    #henk, if the above was meant for me, thanks. The query posts code is nudging me in the right direction. Right now I have a custom category page that is pulling in weekly archives and I need to add the query to make it specific to that category, because apparently, WP is not honoring the category-x.php extension. It’s throwing all weekly posts there. So I guess I need that query string.

    I’m trying to do number 2 as explained above. However, I’m running into two problems:

    1. https://deepbluetrees.com/category/category-name does not seem to be working. I have tried with “categories” and different capitalization of the category names, (images versus Images) and that doesn’t seem to be the problem.

    2. I can’t seem to be able to find the setting in the “Create a new page” panel to assign it to a particular category

    help is much appreciated. thanks.

    @joni,

    In my rightcolumn.php for my site (which is included by my index.php etc like any sidebar) I have two queries for a single category.
    One example:

    <div class = "gelebalk">&nbsp;Persberichten: </div>
    <ul>
    <?php query_posts('category_id=#&showposts=#');?>
    <?php $posts = get_posts('category=9&numberposts=6&offset=0');
    	foreach ($posts as $post) : start_wp(); ?>
    <li><h5><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h5></li>
    <li><div class = "shortlist">
    <?php the_excerpt_rereloaded('11','---&raquo;&raquo;','no','plain','no'); ?>
    </div></li>
    <?php endforeach; ?>
    </ul>

    Tou can see the category id number (9) and the numberofposts (6). (The excerpt re-reloaded is a plugin.) Normal excerpt will work too.

    @deepbluetrees.
    Let’s stick to category templates here. Just with Notepad copy your category.php or even index.php and save it with another name like category-5.php , upload it to the server in wp-content/themes/yourtheme/ and when someone clicks on your menu link to category 5 that specific template will be used (so you can style it to fit your needs for that category. For example not including the sidebar or including another footer or whatever).

    converting2wp

    (@converting2wp)

    @deepbluetrees

    You may have changed something since posting, but it looks as if you’re using a tag-based classification scheme, rather than one based on categories.

    On the other hand, the link
    https://deepbluetrees.com/category/images
    does now look like it’s working.

    Finally, WordPress doesn’t have a good way to assign categories to pages — just to posts. Is that what you were asking?

    Is this resolved?

    deepbluetrees

    (@deepbluetrees)

    Yes, I have just defined my link structure to include https://deepbluetrees.com/%tag%

    and

    https://deepbluetrees.com/%category%

    This should probably make it easier, but as a total XHTML / CSS / Web design beginner I’m having difficulty assigning pages to display every post from a certain category.

    vtxyzzy

    (@vtxyzzy)

    This thread may help.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Display posts on a page’ is closed to new replies.