• Along with my plugin work I’ve been spending a bit of time on template experiments, proof of concepts in organizing content differently in WordPress 1.5.

    A method that’s requested often, and one that caught my interest, is to display recent posts organized within their respective categories, instead of just by date (descending). I’ve come up with one solution through a (very) modified post loop in a home.php template, and would like feedback on what I have so far, such as improvements to structure, streamlining code, etc.

    download template | view template | demo

    The modifications to The Loop I’ve made still only handle the last N posts, but it first retrieves the categories they’ve been posted to, and then organizes posts under each. By default categories are organized by latest post first, but uncomment the following line (remove the //) to sort/list the categories alphabetically:

    // uasort($cats, strcasecmp);

    I’ve commented throughout the template, but please ask if something isn’t clear.

    Finally, the template is designed around the default (Kubrick) theme, so it’ll work best with that; however the loop framework can be imported into any layout (with appropriate tweaking).

Viewing 15 replies - 16 through 30 (of 51 total)
  • Thread Starter Kafkaesqui

    (@kafkaesqui)

    When I change it to this:

    <?php if(!in_category(1)) : ?>
    <h2 style="text-align: center; background-color: #48b; margin: 0 -20px 0 -20px;" id="cat-<?php echo $current_cat; ?>"><a style="color: #fff;" href="<?php echo get_category_link($current_cat); ?>" title="View all posts in <?php echo get_the_category_by_id($current_cat); ?>"><?php echo get_the_category_by_id($current_cat); ?></a></h2>
    <?php endif; ?>

    It simply removes the category header. I don’t see a problem with posts (other than the posts in my #1 cat seems a little lost without a category header to list them under).

    I know this was designed to work with the kubrick template, but is it possible to display each catagory and its posts horizontally next to each other rather then vertically with the way that you have written your code ?

    Any help in making that happen would be hugely appreciated.

    Thanks

    bawk, i’m not sure how you want the posts displayed, but a handy way to adapt the code to a new layout:

    run through the code, and replace any queries inside <? ?> with dummy text:

    <h2 style="text-align: center; background-color: #48b; margin: 0 -20px 0 -20px;" id="dummy"><a style="color: #fff;" href="dummylink" title="View all posts in dummy">dummy category</a></h2>

    so you can see it’s only a header 2 tag.

    now, make the layout you do want to use, for example, have them all appear in on one line together, separated by |

    <a href="dummylink" title="View all posts in dummy">dummy category</a> |

    and replace the dummy text with the code you need:
    <a href="<?php echo get_category_link($current_cat); ?>" title="View all posts in <?php echo get_the_category_by_id($current_cat); ?>"><?php echo get_the_category_by_id($current_cat); ?></a> |

    if you want more complex CSS horizontal layouts for lists, see:
    https://www.alistapart.com/articles/taminglists/

    Hi there! This looks interesting ?? But I need some help. Will it be possible to do something like this (copying from another topic)?

    I’m trying to adapt my front page, but since I don’t know much php, I’m not having much luck with understanding the loop guides…

    I want to keep three articles from my main category over my two other categories which should be listed in a two columns view with five articles each.

    Here is a schematic look of what I want in the main content area of my front page:

    Main category | Sidebar
    Main category | Sidebar
    Main category | Sidebar
    Category2 | Category3 | Sidebar
    Category2 | Category3 | Sidebar
    Category2 | Category3 | Sidebar
    Category2 | Category3 | Sidebar
    Category2 | Category3 | Sidebar

    thanks for this great code. i have one question. does anybody know how i to create a layout with 3 columns near to each other?

    Probably a lot people know, but that’s a “design basics” question, not really a WP issue. I assume you’d have 3 different divs in the content area, or something like that.

    kvalvik, it should be possible, but you really have to know well at least (x)html and css. And some basic php – to the extent to be able to read and copy/paste it.

    this is great.

    however, do you think it’s possible to keep a category always on top and the other ones under that? so that the categories don’t come up on the top whenever there’s a new post added to it.

    Did you take a look at the demo? – I mean before asking…

    i did. and i also installed it.

    If you want one category always on the top – you probably need another solution.
    POssible the one explained to me in this thread:
    https://www.ads-software.com/support/topic/28203?replies=11#post-193667

    I did it thanks so much.

    https://artistsunite-ny.org/indexc.php

    One problem. I have set up three loops on the page with each one eliminating a few categories. the center loop should eliminate all categories but one (Feature Articles) but instead it shows 3 categories and I can’t figure out why.

    How do I install this plugin? What folder do I put it in?

    Sorry, I’m very very new to WordPress!

    This is not a plugin. It is a template file that should go in the theme folder.
    Go back and read the OP (original post).

    I’m working on a template that has two columns side-by-side each displaying the top posts from my two main categories. Your solution is the closest thing I have found & I really appreciate it, but I’m still not sure how to modify it to reach my design. I’m still an extreme novice at this – any input you have would be very appreciated. Thank you.

    https://www.jeffdomke.com – you can see the columns.

Viewing 15 replies - 16 through 30 (of 51 total)
  • The topic ‘Display by Category home.php template’ is closed to new replies.