• For a theme I am working on I need to include a synopsis (summary) of the latest post for each category.

    I am new to theme creating and would appreciate any hints on which functions or sample code to look at.

    Thanks in advance,
    Claude Needham

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter gxxaxx

    (@gxxaxx)

    Thank you. Two very good references.

    In the args passed to query_posts we have

    $args = array(
    'posts_per_page' => 1,
    'cat' => $cat->term_id,
    );

    I changed the 5 to 1 because I want only a single post.
    I need the most recent post.

    Now here’s the part where I really expose my newbishness to wordpress.

    Since wordpress has its foundation as a blog, are the posts always returned in latest (most recent) first — unless specified differently? Or, do I need to tell the query_posts that I want the last one?

    Thanks again for previous reply
    Claude

    Since wordpress has its foundation as a blog, are the posts always returned in latest (most recent) first — unless specified differently? Or, do I need to tell the query_posts that I want the last one?

    that is right – default is to show latest post first;

    for a full list of query parameters, see (these are more-or-less the same for query_posts(), WP_Query() and get_posts() ):

    https://codex.www.ads-software.com/Class_Reference/WP_Query#Parameters

    Thank you.

    Thread Starter gxxaxx

    (@gxxaxx)

    The code from https://www.ads-software.com/support/topic/latest-5-posts-from-each-category
    was a great starting point for my problem.

    For my application I had to change a few things to get it to work.
    1) The endforeach; at the bottom (just before the endforeach) required parens. endforeach(); If I did not change this I could not use a static home page. It would revert to the index.php but only show one post.

    2) I needed to set $more to zero or the whole post would show. And I just wanted the part up to the “more”. Had to remember to reset the $more to its previous value or none of my pages would show the full content.

    I’m sure there would have been a more elegant way to handle this. I’m just hacking my way through the code with a machete and lot’s of hoping ??

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Thread Starter gxxaxx

    (@gxxaxx)

    Can’t read the Forum Rules at the moment.
    Get the following response:
    Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.

    Rules must have changed in the past few months, I posted a slightly modified version of code that was taken from a 10 month old post.

    rules are a bit tighter now – it is 10 lines of code max in a topic; this keeps even long topics readable, and makes replying to code easier, as the pastebin comes with syntax higlighter and line numbers, and the possibility to reply with an adapted code.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘List of latest post for each category’ is closed to new replies.