• Resolved slevenln

    (@slevenln)


    I was wondering if I can show the user (subscriber) in thier own dashboard a box with their posts. because I’m running a multiuser blog , where people register and can add posts , so I want every user to see their own posts ..

Viewing 8 replies - 1 through 8 (of 8 total)
  • duncanjbrown

    (@duncanjbrown)

    How’s this for starters? Put it at the end of your functions.php file.

    See also:
    wp_get_current_user
    WP_Query

    add_action( 'wp_dashboard_setup', 'display_current_user_posts_widget' );
    
    function display_current_user_posts_widget() {
    
    	wp_add_dashboard_widget( 'current-user-posts', 'Your latest posts', 'display_current_user_posts' );
    
    }
    
    function display_current_user_posts() {
    
    $current_user = wp_get_current_user();
    
    $current_ID = $current_user->ID;
    
    $current_user_posts_opts = array (
    	'showposts' => 3,
    	'author' => $current_ID,
    	);
    
    $current_user_posts_query = new WP_Query($current_user_posts_opts);
    
    if ( $current_user_posts_query->have_posts() ) {
    
     	while ( $current_user_posts_query->have_posts() ) : $current_user_posts_query->the_post();
    
    	?><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title('<p>', '</p>'); ?></a>
    
    	<?php
    	endwhile;
    
    } else { echo "You haven't written any posts yet."; }
    
    }
    duncanjbrown

    (@duncanjbrown)

    Sorry, that was a bit long – Pastebin

    Thread Starter slevenln

    (@slevenln)

    Thank you very much duncanjbrown , but if I may ask for a favour to guide me more thru the process of putting the code in the functions.php .. cuz I found multiple files called the same “functions.php” and I’m kind of a newbie 😀 .. I would appreciate that very much !!

    duncanjbrown

    (@duncanjbrown)

    Hi slevenln. No problem. Functions.php is used to add extra functionality (like this) to a theme.

    There are two ways to get at it. Depending on your setup, you may be able to go for option 1, the internal theme editor ( Dashboard > Appearance > Editor ). Select functions.php on the right and paste the code in before the closing ‘?>’ tag, then save.

    If you get a message saying ‘these files aren’t enabled for editing’, you need to either fix your permissions (have a search around the forums for more details) or try option 2.

    Option 2 is to use FTP or ssh. You’ll find functions.php in your /wp-content/themes/[name of your theme]/.

    If you’re not sure which theme you’re using, you can check at ‘ Dashboard > Appearance > Theme ‘.

    Let me know if this works for you
    Duncan

    Thread Starter slevenln

    (@slevenln)

    Perfect !! thank you very much !! I just can’t thank you enough !! 🙂

    duncanjbrown

    (@duncanjbrown)

    no problem sir 🙂

    This should really be a plugin, I think, with options and so on, but what you have will work in the meantime

    ed

    (@wesleysoccer)

    @duncanjbrown

    I have a situation where I want to show subscribers their posts inside of a page…the subscribers are allowed to complete their own posts but I would like to have a page that will show them all their posts or maybe a link to just their posts?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Show the logged in users thier posts.’ is closed to new replies.