• Resolved philowen

    (@philowen)


    I’m working on building a page for recently updated posts/pages using the code snippet on this forum. I can’t seem to get the modified date to show. the_modified_author and comments_number tags work fine, but not the_modified_date . Could there be a conflict with using the foreach loop? Some other problem?

    (Note: I’m a newbie to theme development – have only been digging my hands into it for a few weeks.)

    Here’s what I’m trying to do:

    <iframe src="http://pastebin.com/embed_iframe.php?i=QUbxBn9Q" style="border:none;width:100%"></iframe>

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter philowen

    (@philowen)

    oops, looks like the pastebin thing didn’t work.

    Try again:

    foreach ($recentposts as $post) {
            if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
            echo "
    <li><a>ID)."'>";
            the_title();
            echo '</a>';
            echo ' was modified by ';
            the_modified_author();
            echo ' on ';
            the_modified_date();
            comments_number();
            echo '</li>
    ';
    }
    Thread Starter philowen

    (@philowen)

    I’ve also tried some other date type functions, including the_time(), but it seems none of these will work. Any ideas?

    possibly needs setup_postdata($post);

    see http://codex.ww.wp.xz.cn/Template_Tags/get_posts#Examples

    Thread Starter philowen

    (@philowen)

    Thanks alchymyth, but this doesn’t seem to do it.

    Here’s my complete code, with the setup_postdata function call included:

    EDIT: Providing a pastbin link instead of code after reviewing forum welcome/etiquette page: http://pastebin.com/WWwXjCYH

    The above code produces this kind of format:

    Recently Commented Pages by philowen on No Comments
    Page Activity by philowen on No Comments
    Opportunities by on No Comments
    Resources by on No Comments
    Training by on No Comments

    the_modified_time and the_excerpt function calls still don’t work. Could it have something to do with the foreach loop being wrapped in an “if” statement?

    my mistake – I went for the (wrong) obvious first and missed the real cause:

    SELECT ID, post_title FROM

    you are only selecting post ID and title with your query;

    possibly change that to:

    SELECT * FROM

    – seems actually to work without setup_postdata($post) ;-(

    Thread Starter philowen

    (@philowen)

    Thanks alchymyth, but I got it! Figured out a much simpler way to accomplish what I was trying to do. The query function allows the modified date to be used in the “orderby” parameter.

    Code at http://pastebin.com/BJJSvn9A

    See it in action (needs a little styling) at http://walkthurston.info/page-activity/

    That’s my first custom query/loop. Not bad for a noob, eh?

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Page update date in a foreach loop?’ is closed to new replies.