The MU forums have moved to WordPress.org

the_content() on aggregated homepage, how? (11 posts)

  1. Melodiefabrieknl
    Member
    Posted 10 years ago #

    I am having problems using the the_content('read more') function on the aggregated homepage of blogs. Yes, out of the loop just using it on content I select directly from the database.

    Anyone a suggestion?

  2. lunabyte
    Member
    Posted 10 years ago #

    Like displaying the most recent X number of posts (with an excerpt), for an individual blog, or from the entire collection of sites in your MU?

  3. andrea_r
    Moderator
    Posted 10 years ago #

    I think it has to be used in the loop.

  4. Melodiefabrieknl
    Member
    Posted 10 years ago #

    @lunabyte: yes, that's what I want

    I also think it can only be used in the loop. There really are no aggreated functions available in WPMU.

  5. Melodiefabrieknl
    Member
    Posted 10 years ago #

    A little routine would be okay I guess, something like this:
    $the_moreposition = strpos($the_content,"<!--more-->");
    $the_content= substr($the_content,0,$the_moreposition);

    Or are their more things I should consider?

  6. andrea_r
    Moderator
    Posted 10 years ago #

    "There really are no aggreated functions available in WPMU."

    No, there aren't really. Almost all the functions are based on (identical to) regular WP.

  7. lunabyte
    Member
    Posted 10 years ago #

    You mean something like this? Change the html to match your own layout, but this will get you in the ballpark. At least, it should.

    <?php
    $lastposts = get_posts('numberposts=2&order=DESC&orderby=ID');
    foreach($lastposts as $post) :
    setup_postdata($post);
    ?>
    <h3 class="featuredtitle"><a href="<?php the_permalink(); ?>" id="featuredpost-<?php the_ID(); ?>-1" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    <div class="featured">
    <?php the_excerpt(); ?>
    <a href="<?php the_permalink(); ?>" id="featuredpost-<?php the_ID(); ?>-2" title="<?php the_title(); ?>">Read more of <?php the_title(); ?>...</a>
    </div>
    <?php endforeach; ?>

    If you wanted a horizontal rule, separation image or something between each post, you can put it before the ending of the foreach loop, as an example.

    the get_posts function is set to display the most two recent posts, but you could change it to whatever number you are comfortable with by modifying 'numberposts=2...' to declare the number you want returned.

    It's the setup_postdata that creates the ability to use the reference tags (id, excerpt, permalink, etc) outside of the normal WP loop.

    [edit]

    In addition, you'll notice that instead of using the normal id=post-(the_id) in the tag for the title and link, it says featuredpost-(the_id), and for the link adds a -2 after that.

    Reason behind it is to keep from having id matches between the featured posts, and if by chance the real post is displayed in the main content area. The -2 does the same thing, but to keep the conflict between the link and the title in the code above from matching as well.

  8. lunabyte
    Member
    Posted 10 years ago #

    Oh, it should only return the posts from the current site being viewed, just so you know.

    If you're looking for the last X posts across all blogs, beats me at the moment.

  9. andrea_r
    Moderator
    Posted 10 years ago #

    The last X posts across all blogs is all over the forums here. :) Doesn't use hardly any WP functions though, mostly straight SQL. Gotta build your own "read more" link.

  10. Melodiefabrieknl
    Member
    Posted 10 years ago #

    Thanks for the suggestions. I am showing posts from all kinds of blogs.

    I have wrote this routine:
    $the_moreposition = strpos($the_content,"<!--more-->");

    if ($the_moreposition!=0){
    $the_content = substr($the_content,0,$the_moreposition) . "
    (lees verder...)";
    }

    There seem to be an issue with embedded videos at the moment. I am looking into it.

  11. Melodiefabrieknl
    Member
    Posted 10 years ago #

    sorry, the routine was not complete: it lacks the read more URL. here's what I do:
    $the_moreposition = strpos($the_content,"<!--more-->");

    if ($the_moreposition!=0){
    $the_content = substr($the_content,0,$the_moreposition) . "(read more...)";
    }

    I will release a couple of plugins when I am ready.

About this Topic

  • Started 10 years ago by Melodiefabrieknl
  • Latest reply from Melodiefabrieknl