WordPress.org

Ready to get started?Download WordPress

Forums

Path
How can I include user_submit_name value in the post (8 posts)

  1. stuudio
    Member
    Posted 5 months ago #

    Maybe this is a question for Path theme and not for the plugin guys.
    http://wordpress.org/support/topic/how-can-i-include-user_submit_name-value-in-the-post?replies=1

    I am using "User Submitted Posts" plugin and like to hack the Path child theme do display custom field "user_submit_name" in the published post, so it looks like:

    "user_submit_name here" writes: Blaa blaa blaa aka what ever he wrote

  2. Sami Keijonen
    WordPress-asiantuntija
    Theme Author

    Posted 5 months ago #

    Where would you like to appear that? And do you have a code snippet from plugin author how to get user_submit_name?

  3. stuudio
    Member
    Posted 5 months ago #

    This will have to show up in a post (content).

    Here is the code used to call the name from the custom field

    <?php if (function_exists('usp_author_link')) usp_author_link(); ?>

  4. Sami Keijonen
    WordPress-asiantuntija
    Theme Author

    Posted 5 months ago #

    Try something like this in your custom plugin or in child theme functions.php. Code is not tested so do not try it on live site.

    function my_filter_content( $content ) {
    
       if( is_singular( 'post' ) && is_main_query() ) {
    
          if ( function_exists( 'usp_author_link' ) ) {
             $new_content = usp_author_link();
             $content .= $new_content;
          }
    
       }	
    
       return $content;
    }
    add_filter( 'the_content', 'my_filter_content' );
  5. stuudio
    Member
    Posted 5 months ago #

    Thank you Sami but I still end up with a post where name and content are not one continuous line

    "user_submit_name here"

    writes: Blaa blaa blaa aka what ever he wrote

  6. stuudio
    Member
    Posted 5 months ago #

    function my_filter_content( $content ) {
    
    //        if( is_singular( 'post' ) && is_main_query() ) {
    
              if ( function_exists( 'usp_author_link' )) {
                 $new_content = usp_author_link();
                 $content .= $new_content;
    //           }
    
           }	
    
           return $content;
        }
        add_filter( 'the_content', 'my_filter_content' );

    I also commented out the is_singular part

  7. stuudio
    Member
    Posted 5 months ago #

    here is an example, how it works exactly as needed:
    Everything is in one line, author name shows up only if submitted by regular user or anonymous user.
    from: http://wordpress.org/support/topic/how-can-i-include-user_submit_name-value-in-the-post?replies=3

    // USP prefix submitted content
    function my_the_content_filter($content) {
    	global $post;
    	$usp_author = get_post_meta($post->ID, 'user_submit_name', true);
    	if (usp_is_public_submission()) {
    		$content = $usp_author . ' writes: ' . $content;
    	}
    	return $content;
    }
    add_filter('the_content', 'my_the_content_filter');

    here is change I made to my child-theme content.php:

    ...
    </header><!-- .entry-header -->
    
    		<div class="entry-content">
    		<?php if (function_exists('usp_author_link')) usp_author_link(); ?>
    		<?php echo $post->post_content = ' writes: ' . $post->post_content; ?>
    
     			<?php /*the_content(); */?>
  8. stuudio
    Member
    Posted 5 months ago #

    <div class="entry-content">
    		<?php if (function_exists('usp_author_link')) usp_author_link(); ?>
    		<?php echo $post->post_content = ' kirjutas: ' . $post->post_content; ?>
    
     			<?php /*the_content();*/ ?>

    This is not working if you have a image in your post. :(

    Any advice is welcome.

Reply

You must log in to post.

About this Theme

About this Topic

Tags

No tags yet.