• On the profile page of each author on my blog, I want to show a link to all posts by a user.

    Okey, that part is easy. But I want to show something else, if the author has not yet made any posts, such as “This author has not made any posts yet”.

    At the moment, the link looks like this:

    <a href="/overlatelser/<?php echo bp_core_get_username(bp_displayed_user_id()); ?>">Show all posts by <?php bp_user_fullname() ?> </a>

    But if the user has not made any posts, they end up at the 404 page, which is a bit unprofessional.

    Is it possible to fix this with some nice coding?

    Any help highly appreciated.

    I am using WordPress MU and Buddypress (latest versions)

Viewing 4 replies - 1 through 4 (of 4 total)
  • I don’t know a whole lot about the buddypress/MU APIs, but I’ll bet that you could nest that link inside some PHP “IF” statements.

    Try using the Comments function as a guide: There are IF statements asking whether comments are open, whether the user is allowed to make/view comments, and whether there are any comments in the first place.

    I’m sure that substituting functions and arguments in the template tags used there would make a rather elegant fix. I.e. you could check to see if the author has made any posts by searching for posts with his author name. If it returns positive, then show the link. If it returns negative, then display “This author has not made any posts”.

    I hope this is what you wanted to do, and that it points you in the right direction,
    MindBlender 3D

    Thread Starter corporatefinance

    (@corporatefinance)

    Thanks for your effort. I am not very familiar with php and the comment template includes too many variables.

    If this could be of any help, I have copied the comment template text below.

    <div id="comments-template">
    
    		<?php if ( have_comments() ) : ?>
    
    			<div id="comments">
    
    				<h3 id="comments-number" class="comments-header"><?php comments_number( sprintf( __('No responses to %1$s', 'buddypress'), the_title( '“', '”', false ) ), sprintf( __('One response to %1$s', 'buddypress'), the_title( '“', '”', false ) ), sprintf( __('%1$s responses to %2$s', 'buddypress'), '%', the_title( '“', '”', false ) ) ); ?></h3>
    
    				<?php do_action( 'bp_before_blog_comment_list' ) ?>
    
    				<ol class="commentlist">
    					<?php wp_list_comments( array( 'style' => 'ol', 'type' => 'all' ) ); ?>
    				</ol><!-- .comment-list -->
    
    				<?php do_action( 'bp_after_blog_comment_list' ) ?>
    
    				<?php if ( get_option( 'page_comments' ) ) : ?>
    
    					<div class="comment-navigation paged-navigation">
    
    						<?php paginate_comments_links(); ?>
    
    					</div>
    				<?php endif; ?>
    
    			</div><!-- #comments -->
    
    		<?php else : ?>
    
    			<?php if ( pings_open() && !comments_open() && is_single() ) : ?>
    
    				<p class="comments-closed pings-open">
    					<?php printf( __('Comments are closed, but <a href="%1$s" title="Trackback URL for this post">trackbacks</a> and pingbacks are open.', 'buddypress'), trackback_url( '0' ) ); ?>
    				</p>
    
    			<?php elseif ( !comments_open() && is_single() ) : ?>
    
    				<p class="comments-closed">
    					<?php _e('Comments are closed.', 'buddypress'); ?>
    				</p>
    
    			<?php endif; ?>
    
    		<?php endif; ?>
    
    		<?php if ( comments_open() ) : ?>
    
    			<div id="respond">
    
    				<h3 id="reply" class="comments-header">
    					<?php comment_form_title( __('Leave a Reply', 'buddypress'), __('Leave a Reply to %s', 'buddypress'), true ); ?>
    				</h3>
    
    				<p id="cancel-comment-reply">
    					<?php cancel_comment_reply_link( __('Click here to cancel reply.', 'buddypress') ); ?>
    				</p>
    
    				<?php if ( get_option( 'comment_registration' ) && !$user_ID ) : ?>
    
    					<p class="alert">
    						<?php printf( __('You must be <a href="%1$s" title="Log in">logged in</a> to post a comment.', 'buddypress'), wp_login_url( get_permalink() ) ); ?>
    					</p>
    
    				<?php else : ?>
    
    					<?php do_action( 'bp_before_blog_comment_form' ) ?>
    
    					<form action="<?php echo get_option( 'siteurl' ); ?>/wp-comments-post.php" method="post" id="commentform" class="standard-form">
    
    						<?php if ( $user_ID ) : ?>
    
    							<p class="log-in-out">
    								<?php printf( __('Logged in as <a href="%1$s" title="%2$s">%2$s</a>.', 'buddypress'), bp_loggedin_user_domain(), $user_identity ); ?> <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="<?php _e('Log out of this account', 'buddypress'); ?>"><?php _e('Log out &raquo;', 'buddypress'); ?></a>
    							</p>
    
    						<?php else : ?>
    
    							<?php $req = get_option( 'require_name_email' ); ?>
    
    							<p class="form-author">
    								<label for="author"><?php _e('Name', 'buddypress'); ?> <?php if ( $req ) : ?><span class="required"><?php _e('*', 'buddypress'); ?></span><?php endif; ?></label>
    								<input type="text" class="text-input" name="author" id="author" value="<?php echo $comment_author; ?>" size="40" tabindex="1" />
    							</p>
    
    							<p class="form-email">
    								<label for="email"><?php _e('Email', 'buddypress'); ?>  <?php if ( $req ) : ?><span class="required"><?php _e('*', 'buddypress'); ?></span><?php endif; ?></label>
    								<input type="text" class="text-input" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="40" tabindex="2" />
    							</p>
    
    							<p class="form-url">
    								<label for="url"><?php _e('Website', 'buddypress'); ?></label>
    								<input type="text" class="text-input" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="40" tabindex="3" />
    							</p>
    
    						<?php endif; ?>
    
    						<p class="form-textarea">
    							<label for="comment"><?php _e('Comment', 'buddypress'); ?></label>
    							<textarea name="comment" id="comment" cols="60" rows="10" tabindex="4"></textarea>
    						</p>
    
    						<?php do_action( 'bp_blog_comment_form' ) ?>
    
    						<p class="form-submit">
    							<input class="submit-comment button" name="submit" type="submit" id="submit" tabindex="5" value="<?php _e('Submit', 'buddypress'); ?>" />
    							<input class="reset-comment button" name="reset" type="reset" id="reset" tabindex="6" value="<?php _e('Reset', 'buddypress'); ?>" />
    							<?php comment_id_fields(); ?>
    						</p>
    
    						<div class="comment-action">
    							<?php do_action( 'comment_form', $post->ID ); ?>
    						</div>
    
    					</form>
    
    					<?php do_action( 'bp_after_blog_comment_form' ) ?>
    
    				<?php endif; ?>
    
    			</div>
    
    		<?php endif; ?>
    
    	</div>

    Hi,

    If this could be of any help, I have copied the comment template text below.

    Actually, your specific comments template really isn’t the solution here. I was just referencing the comments system, because the way that it checks for the state of the comments is very similar to the process requested for testing author posts. I was simply talking about workflow, your comments.php does not need to be changed.

    I am not very familiar with php and the comment template includes too many variables

    That’s kind of funny, because… I am not a PHP genius either. I know enough to get me into trouble (and only a bit more than that, I’m afraid!).

    The reason I thought up the comments idea was because I spent a lot of time getting to know the comments system so that I could customize it. I don’t know anything about the API for BuddyPress. MUCH less than I know about plain WordPress.

    But, despite my lack of knowledge about the specifics, I stand by my suggestion in theory. I am fairly confident that the idea is correct, but someone else will have to look at this thread and provide specific code.

    P.S. Could a moderator move this thread into either the Templates or the Plugins/Hacks forum? Because it might get more attention there. Your judgement call. Thanks ??

    Thread Starter corporatefinance

    (@corporatefinance)

    Thanks for your effort trying to help me. I understood how you meant with the template code, but I was not man enough for the coding =).

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show a link only if it exists? (WPMU and BuddyPress)’ is closed to new replies.