The MU forums have moved to WordPress.org

home.php recents posts from ALL blogs (37 posts)

  1. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    Well here's the deal...I am setting up a nice little company blogging site for my business. Technically right now its just my own blog so I could use the regular wordpress but in the future, I will be adding more to it so I figured it might be easier to get MU ready and in-place now.

    I have my theme all picked out. I copied index.php to home.php for modification purposes, and here is the code I found it uses to display recent blog posts.

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <div class="post" id="post-<?php the_ID(); ?>">
    	<h2 class="title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    	<div class="meta">
    		<?php the_time ('M d, Y @ h:i a'); ?> by <?php the_author (); ?>
    	</div>
    
    	<div class="storycontent">
    		<?php the_content(__('more...')); ?>
    		<?php wp_link_pages(); ?>
    	</div>
    
    		<div class="feedback">
    			Posted under <?php the_category (',') ?>
    			<?php edit_post_link(__(' | Edit This')); ?>
    			|
    			<?php comments_popup_link(__('No Comments'), __('1 Comment'), __('% Comments')); ?>
    		</div>
    </div>
    
    <div id="comments">
    <?php comments_template(); ?>
    </div>
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    This looks good, but my issue is more on the technical side, since this is for a home page I just don't want recent posts from the admin blog, I want recent posts from all blogs.

    Now I'm not a PHP scriptor, rather a small business owner, but I do have some PHP knowledge, and I am assuming the real magic of the code I gave above happens here:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    Specifically in those functions, are their any functions I can replace those with that will do essentially the same thing but for all blogs, not just admin blog.

    If not, where are those functions at, so I can create new functions based off of them to do what I need, and I'm sure depending on the complexity if I have to write my own fucntions from theirs I will need further help.

    Or if for some reason I am completley wrong about how this works let me know. Thanks for your time.

  2. lunabyte
    Member
    Posted 16 years ago #

  3. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    Thanks for the post lunabyte but you got to give credit where credit is due. I'm no idiot, I know how to search and it pulled up nothing useful, but thanks for trying to help.

    Aside from that, as I've been studdying the code, I think I have more of an understanding about how it works. My focus I think needs to come to the function have_posts().

    I personally see two options for this:

    1) Maybe the function have_posts() has arguments, specifically one that could allow me to specify to look for posts in all blogs

    if not

    2) write a new function have_posts_all() which would be havily based on have_posts() but would look at all blogs.

    From the codex I cannot find if have_posts has any arguments so I am going to guess it does not. I have looked in functions.php, post.php, and mu-functions.php and have not found this function (unless somehow I missed something). So the first thing I will need is to find this function, anyone know where I can find it?

  4. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    Well I have really come far. I think I may have gotten it, well almost, I actually found this (http://mu.wordpress.org/forums/topic.php?id=5352) in a google search, not sure why it wasn't in the forums search I did ealier, but...it works, just not styled the way I want it. So right now my taks is to restyle the output to match my theme...don't worry I will probably return soon once I've screwed it up. ;)

    EDIT:
    Well I didn't crash it updating it...just a few issues...

    1) it displays 2008-01-27 22:59:24 by admin when it should display Jan 27, 2008 @ 10:59 pm by admin

    In the code originally used they specified the layout with the_time ('M d, Y @ h:i a');

    2) I can't figure out how to end each post correctly

    3) It used the guid for the link which i think i remember reading it a bad way of doing it.

    Some Links:

    My Home Page With a Test Post: http://blogs.rcbitsolutions.com/

    An example of what it should look like (only this shows the full post): http://blogs.rcbitsolutions.com/testing/

    My Code: http://blogs.rcbitsolutions.com/my-code.txt

    Hope someone can help, I think here I am thoughly stuck and will not be able to find my own way though.

  5. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    Also can no longer edit mmy last post...lol...but I forgot, I also want to remove the posted date restriction where the code I got will only show posts made today, I don't care if the post was made today or last year if its one of the 10 most recent I want it shown.

    Thanks again.

  6. andrea_r
    Moderator
    Posted 16 years ago #

    The first code you posted was something called The Loop, which is the WP magic for displaying post sof one blog (as you found out).

    Secondly, to save your head bashing, the search luna gave above should have lead you to this already being done. Actually, multiple times. Soem people just pull in a sitewide feed and display others (like me) prefer to use a plugin. Read the SQL in this one:
    http://wpmudevorg.wordpress.com/project/Most-recent-posts

  7. DanYork
    Member
    Posted 16 years ago #

    RCB-IT-Solutions,

    I feel your pain. Back in October I was in the same situation as you when we were trying to create http://blogs.voxeo.com/

    We wound up trying out a whole range of different plugins, including the one andrea_r mentioned, before we finally wound up using this one with a bunch of modifications:

    http://www.wpmudev.org/project/list-all-Posts

    At some point soon I'll try to write up what we did. FYI, if you're doing a corporate blog portal, I'm trying to write about what we're doing on our blog portal at http://blogs.voxeo.com/behindtheblog/

    Good luck with it,
    Dan

  8. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    I'll look into that plugin...thanks.

    EDIT: So I am trying out this other plugin...without modifying it, it already broke on me.

    Warning: Invalid argument supplied for foreach() in /home/rcbit/public_html/blogs/wp-content/mu-plugins/list-all-posts.php on line 47

    Line 47: foreach ($arrayName as $arrayElement) {

    I don't see what's cuasing the problem, I see no syntax error...

  9. andrea_r
    Moderator
    Posted 16 years ago #

    there's at least three of them out there - just move on to the next plugin till you find one that does work for you.

  10. DanYork
    Member
    Posted 16 years ago #

    RCB - We did have to do a bunch of modifications to make it work. I don't recall precisely what we did and unfortunately probably won't have time to look into it until later this week.

  11. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    Well thats ok, I noticed andrea_r mentoned sitewide RSS feed. I got a plugin for it (http://wpmudevorg.wordpress.com/project/WPMU-Sitewide-Feed-Plugin---ITDamager) which seems like it will work, from what I've read it incorporates the ability to include recent posts on a page, so thats what I am looking to do.

    Also, I got a slightly diffrent theme now (just to complicate things more...lol)

    But this will be interesting because I will need to get the month and the day seperate for the images to work, ect...this will be fun. So I will look into getting this to work, plus this gives my users a site wide RSS feed to use. So this might be a good thing.

  12. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    I installed the site-wide rss plugin and it didn't show anything, so I figured it must not show existing posts, so I made a new one, still nothing showing.

    I feel like I am running out of alternative here. Any other suggestions.

    DanYork: If you could release the code for what you did on your company blogs for this, I know I would appriciate it, it would save me a big headache. A am also sure others would find it useful as well.

  13. andrea_r
    Moderator
    Posted 16 years ago #

    "I installed the site-wide rss plugin and it didn't show anything"

    Didn't show anything where? All it does is create a sitewide feed. If you want to display that somewhere other than the feed (which would be yoursite.com/wpmu-feed/ )

    It;s up to you to use that feed, get it parsed and spit the content out where you want it. Kinda like is done on the dashboard.

  14. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    I can't use the feed to display anything, if the feed is empty, which it is.

    Ok I have better things to deal with than this, so if you can do this to my specifications, letme know, include your price. If I find any reasonable rates I'll hire you to do this so we can all move on. Or if you prefer to do it for free and just release it for anyone to use that would be even better.

  15. Vimm
    Member
    Posted 16 years ago #

    I didn't bother with plugins and went straight to the database. With some optimized SQL queries you can pull the latest posts without having to actually check each blog. I also added paging. It's 60 lines of code in home.php if anyone wants it. I also created a site-wide RSS feed plugin based on the same code.

  16. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    Vimm: If you want to share your code that would be great, I'm sure many other than myself could find it useful.

  17. andrea_r
    Moderator
    Posted 16 years ago #

    We already released a plugin. I mentioned it in the post above.

    You can see it in action at http://homeschooljournal.net and a few other sites, like http://realsportsbloggers.com .

    Also note that, if there's no posts (like you mentioned above, with the feed being empty) then none of these plugins out there will show any content. If there are existing posts, and they are too old, they won't show up either. It's nothing to slap up a couple test entires though.

    the only differnece between a plugin (or this plugin specifically) and adding a whole pile of code is the plugin is wrapped in a function to call.

    In the one I mentiopned above, I've taken the contents of the plugin and pasted it right in the theme's index.php.

  18. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    Thanks for trying to help, but reading the thread will go along way, to avoide duplicate answers or questions being asked that i already mentioned above.

  19. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    well i did some reading and I found a fuction to display the posts, i just nedd the blog id and post id from the most recent posts. What would the query be that would be to get me that info?

  20. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    Ok well I thaught I may have figured out how to modify ah_recent_posts to do what I need see http://www.rcbitsolutions.com/blogs/recent_posts_mu.txt

    but it doesn't display anything. Any suggestions?

  21. politicalbear
    Member
    Posted 16 years ago #

    First, I have to ask....does IT stand for Information Technology?

    Ok, What code are you putting on the page you are trying to display the recent posts. I you are using Andrea's plugin it should be something like <?php ah_most_recent_posts(10) ?> or whatever the function name is.

    I am a total novice so this could be completely wrong, but that is at least close to what I did.

  22. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    Lets ee i've tried

    recent_posts_mu($how_many = 15, $perblog = 15, $chars = 200);

    as well as

    recent_posts_mu(15, 15, 200);

    Neither is working, I'm thinking its something in the functions code but I don't see what.

  23. politicalbear
    Member
    Posted 16 years ago #

    Wow, I see why they gave up on you.

    The funtion isn't named "recent_posts_mu". Someone correct me if I am wrong, but I think this might be the one lesson I kind of understand.

    The function is named "ah_recent_posts_mu" Cut and paste this. <? php ah_recent_posts_mu(10) ?> Then mess around with, but only after it works.

    I am not using this one, but I am using a recent post plugin on my site.
    http://politicalbear.com

  24. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    no it is called recent_posts_mu...I think I would know concidering I wrote it.

  25. politicalbear
    Member
    Posted 16 years ago #


  26. politicalbear
    Member
    Posted 16 years ago #

    And I should have checked to make sure.

    Damn, I am just as bad. Use Andreas.

  27. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    It borrows alot of it's code from Andreas but I do't just use Andreas because it just doesn't get all the info I want.

  28. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    Well I think I may be getting closer, since the site wide RSS feed won't work, I had an idea, isn't there a way to combine several RSS feeds into one feed? So I did some googling and found that yes in fact its possible I found feedblendr.com so I will use this to combine all the feeds into one, my last step it to find out how to use this new sitewide feed to show the posts. I am looking at PHP RSS scripts, woundering if you can recommend any?

  29. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    Well I got one for sourceforge, I coded home.php and it's mostly working now, just a few bugs...
    Specifically I am having issues displaying the date, author name, plus I need to get the blog name and link, and limit the content length.

    The best I have to work with from the RSS is the post guid, knowing this is stored in the db I'll work on a uery tomarrow, in the mean time, from the guid is their an easy way to get the blogs id?

  30. celius
    Member
    Posted 16 years ago #

    How is it working out for you?

About this Topic

  • Started 16 years ago by RCB-IT-Solutions
  • Latest reply from andrea_r