The MU forums have moved to WordPress.org

List a User's Site-wide Blog Posts (16 posts)

  1. callumalden
    Member
    Posted 14 years ago #

    Hey everyone. First off: I love this community. So far I've found pretty much every query answered, in depth, by users of this forum (or through the wider WPMU community). I know for sure that I've chosen the right solution for our magazine blog-- even though I went against the flow ('use DRUPAL!'). Thanks for making this process so enjoyable.

    Question: Many of the authors on my main blog, lets call it "1", have an personal blog "2" hosted on the same WPMU install. Is there a plugin that can detect these accounts and link to then through a plugin / widget on the Author Page on blog "1"?

    Visiting the Author's Page would return a list of recent posts from blog "1" and perhaps a list of posts from "2", or simply a link to blog "2".

    Sounds useful. I'm sure its straightforward. Maybe a job for Site Wide Tags?!

  2. inecho
    Member
    Posted 14 years ago #

    I guess that you are trying to have the same function that wordpress currently use at their homepage?

    We are currently implementing it at our blog .

    Make a search on "AHP Sitewide recent posts". I guess it will solve your problem.

  3. callumalden
    Member
    Posted 14 years ago #

    Thanks inecho, but the query i'd like is for use on the "author.php" template / the 'authors' page. Currently there you can list all of an authors posts on one blog just fine. Great. But I want to take it the next step and also include a link to the author's alternative blogs (and display excerpts from those blogs) within that same "authors" page on my main blog. Currently there's no simple query or hack i can find to do that.

    Example:

    so 'sally' has an 'authors' page at:

    website.com/author/sally

    she contributes to

    [1] website.com
    [2] sally.website.com
    [999] sallys-other-blog.website.com

    on her authors page (back on website.com/author/sally) it only lists her contributions to that blog (ID=1), but i'd like to show that sally has posts on blog 2, 999 AND 1.

    does that make any sense?

    i may simply be using the wrong code this basically my authors' template (authors.php):

    <?php query_posts($query_string.'&posts_per_page=4'); if (have_posts()) : echo "\n"; while (have_posts()) : the_post(); ?>
    
    		<h3><?php the_title(); ?></h3>
    
    		<p><?php the_excerpt(); ?></p>
    
    	<a class="date" href=""><?php the_time('M jS') ?></a>
    	<a class="tag" href=""><?php the_category(', '); ?></a>
    	<?php comments_popup_link(__('<a class="comment" href="">Comment</a>'), __('<a class="comment" href="">Comments</a>'), __('<a class="comment" href="">Comments</a>')); ?>
    
    	<?php endwhile; else: ?>
    	<p><?php _e('No posts by this author.'); ?></p>
    	<?php endif; ?>

    AHP Sitewide Recent Posts is great, I use it on my homepage to create a flow of the latest / active blogs.

    Why this should exist (if it doesn't already)
    even if Sally doesn't contribute to website.com (blog ID=1) she has (for an odd quirk of Wordpress' code maybe) an accessable author's page... where it explains 'no posts are available'. seems an obvious behaviour that there should be an option to list site-wide posts by this author. No?

    - Callum

  4. DeannaS
    Member
    Posted 14 years ago #

    You could use the sitewide tags plugin, and then on the author page you can do a switch_to_blog() to the sitewide tags blog and pull the author's posts from there.

  5. callumalden
    Member
    Posted 14 years ago #

    Deanna, I was looking into that- sounds like the most realistic option. But doesn't that require me to manually enter the blog ID for each author page? I'd like this to be pretty much dynamic... but I'll give it a whirl, thanks!

    Any further options welcome!

    - Callum

  6. DeannaS
    Member
    Posted 14 years ago #

    Nope. The tags blog is set as a sitewide option. So, in your theme's author template you'd just do something like so:

    $tags_blog = get_site_option('tags_blog_id');
    if (is_numeric($tags_blog) {
       switch_to_blog($tags_blog);
       // output all the author posts here - the permalinks will go to the correct blog
    }
    else {
      // go with just the normal behavior here (if there is no tags_blog set)
    }
  7. callumalden
    Member
    Posted 14 years ago #

    Deanna! you are my new best friend. Will try this one out and hopefully it'll rock. Will post the results later.

    Thanks!!!

  8. callumalden
    Member
    Posted 14 years ago #

    i have persevered for the last few hours, but to no avail. i'm having a problem with your code. i'm a php novice... so probably just me! site wide tags is installed and works great. but there seems to be an issue with the code above (i'm attempting to use it to call a loop of latest items-- i'll finish that code later) on the author's page.

    basic example loop:

    <?php
    $tags_blog = get_site_option('tags_blog_id');
    if (is_numeric('$tags_blog')) {
    switch_to_blog('$tags_blog');
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>
    			<div class="post">
    
    			<!-- Display the Title as a link to the Post's permalink. -->
    			<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    			<!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
    			<small><?php the_time('F jS, Y') ?> by <?php the_authors_post_link() ?></small>
    
    			<div class="entry">
    			<?php the_content(); ?>
    			</div>
    
    			<p class="postmetadata">Posted in <?php the_category(', '); ?></p>
    			</div> <!-- closes the first div box -->
    
    			<?php endwhile; else: ?>
    			<!-- meh -->
    			<?php endif; ?>
    
    		</div>
    <?php
    }
    else {
    echo 'Sorry, no posts matched your criteria.';
    } ?>

    so far all i'm getting is 'Sorry, no posts matched your criteria', have messed / googled around. where's the best resource for this plugin's ins-and-outs?

    feel free to call me an idiot and send me an angry letter about doing the wordpress community a disservice (i've been calling myself a 'blogger' for 5 years now... eek).

    :P

    - C.

  9. andrea_r
    Moderator
    Posted 14 years ago #

    this part:

    ('tags_blog_id')

    has to contain the ID number of the actual tags blog.

  10. callumalden
    Member
    Posted 14 years ago #

    okay, i figured that was what i should do. thanks Andrea. unfortunately i have tried that and a few different variations... no joy. perhaps the problem is with my 'tags blog' which i did not create, rather i used an existing blog, was that a bad move?

    will start again with a 'tags blog' from scratch. post a few new items and see how it goes. thanks for all your help!

    - Callum.
    p.s. is there a way to force site-wide tags to "re-index" i.e. cover the back catalogue of blog posts site-wide, as standard it only works for posts created after the install of the plugin, doesn't it? i imagine altering old posts (i.e. adjusting the date / some small change) would cause the posts to be listed on the 'tags blog'?

  11. DeannaS
    Member
    Posted 14 years ago #

    Yah, there's no way to have it re-index all the old posts. You have to "touch" all the old posts to get them to index.

    also, in your code, you're putting ticks around 'tags_blog' so, the code is interpreting that as the literal string. You need switch_to_blog($tags_blog) instead of switch_to_blog('tags_blog').

  12. callumalden
    Member
    Posted 14 years ago #

    great, am currently familiarising myself with these WPMU functions. all new to me. but i guess a quick class in PHP would help too. thanks for your patience on this one Deanna!

    - Callum

  13. callumalden
    Member
    Posted 14 years ago #

    here's the bare code that made it work in the end:

    <?php
    global $switched;
        switch_to_blog('INSERT THE TAGS BLOG ID HERE');
            $lastposts = query_posts($query_string.'&posts_per_page=4');
            foreach($lastposts as $post) :
                    setup_postdata($post);
                    the_excerpt();
            endforeach;
        restore_current_blog();
    ?>

    phew, that's another one off the to-do list! thank you all once again. RESOLVED! *tick*

  14. DeannaS
    Member
    Posted 14 years ago #

    So, I hope that you're still dynamically figuring out the tags blog id, though. And, making sure it's numeric. I speak from past experience when I say that if you don't do this, you will forget and use this theme on another install where those settings are different. And, it will fail.

  15. callumalden
    Member
    Posted 14 years ago #

    Fixed. Thanks Deanna.

  16. callumalden
    Member
    Posted 14 years ago #

    ooh, just discovered the most useful/dangerous(!) piece of code out there for 'touching' or rather 'indexing' or maybe it should be 're-indexing' ;) all posts for use with SiteWide Tags.

    First off, BACKUP BACKUP BACKUP! Then: Install: Power Tools Plugin, Login and enable the plugin, then access the plugin's option page via Admin Dashboard > Site Admin > Power Tools. Then in the PHP Code Executor box enter the following:

    $posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'publish'" );
    if ( !empty($posts) ) {
        foreach ( $posts as $post ) {
            if($post != 1 && $post != 2)
                sitewide_tags_post($post, get_post($post));
        }
    }

    Then click the "Execute this code on all blogs" option, and finally 'Execute'.

    Took a good few minutes on my WPMU install, but does seem to have done the trick!

    (via existencialmedia' forum post here.)

About this Topic

  • Started 14 years ago by callumalden
  • Latest reply from callumalden