Forums

Only one posts of each category on the home page (9 posts)

  1. never_stop
    Member
    Posted 1 year ago #

    Hi.

    Does anybody know,how can i make my blog do,that on the home page it wont display all of the posts from every category,but only 1 of each category's recent post??

    thank your very much for the answer!!

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    http://pastebin.com/64FZhQU0

    probably need to create a home.php based on index.php and the above code.

    EDIT: typing error in line 7:
    should read:
    'category__in' => $cat->term_id

  3. never_stop
    Member
    Posted 1 year ago #

    thanks for the advice,but i tried already this way,and maybe because im stupid or something,i cant make it work!
    I thought about,what if tha sidebar widget displays the the last 5recent post,and i write that in to the index.php...can it work somehow?

  4. Alkorr
    Member
    Posted 1 year ago #

    Hi never_stop, I'm looking for the same code with no success either...

    alchymyth, the code on the page you provide doesn't work for me. I get the name of each category but the excerpt is always the same one from the latest post from the first category...

    I of course checked the Codex but I didn't find anything about getting the last post from each category.

    Any idea how we could do that? Thanks! :)

  5. alchymyth
    The Sweeper
    Posted 1 year ago #

    @Alkorr
    thanks for the error description;

    typing mistake:

    correction:

    'category__in' => $cat->term_id

  6. Alkorr
    Member
    Posted 1 year ago #

    Hi alchymyth, thanks a lot! :)

    Now I try to display the categories not in alphabetical order but showing first the categories recently updated. As of now, my first alphabetical category has the oldest published post so it's not very appealing for my reader. I tried to use orderby=date but then nothing is showing anymore.

    I also tried to exclude a category from the list using 'category__not_in' => -34, but it didn't change anything, the category I want to exclude is still showing... Maybe you have an idea why it's not working?

    Thanks a lot for your help alchymyth! :)

  7. alchymyth
    The Sweeper
    Posted 1 year ago #

    das excluding has to be done in the first line:

    <?php  $cats = get_categories('orderby=count&order=DESC');

    http://codex.wordpress.org/Function_Reference/get_categories

    as for sorting, categories are not really updated; i know what you mean - the category with the post that got most recently updated.

    i don't think there is a direct connection between the category tables and the modified date of the post table in the database.
    and i am no expert in direct database queries.

  8. Alkorr
    Member
    Posted 1 year ago #

    Ok alchymyth, I will try that.

    Thanks again! :)

  9. Alkorr
    Member
    Posted 1 year ago #

    Ok. Now I'm using the code provided by MichaelH on this thread. Thanks to you alchymyth there no more duplicated posts in the list but I'm still trying to display the categories not in alphabetical order but showing first the categories recently updated. And also to exclude a category from the list.

    Still looking for a way to achieve that, I'm reading the Codex (again).

    Meanwhile if anoyne has an idea, it's welcome, thanks! :)

Topic Closed

This topic has been closed to new replies.

About this Topic