Domanda

I've been trying to break apart the returned string from bp_activity_action, but have been going in circles.

By default it returns "User" wrote a new post, "Post Title", on the site "Site Title" "Time Stamp"

How can i get the values of "User", "Post Title", and "Site Title" so that I can place them where I want?

Currently my code looks like this:

<?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) . '&action=new_blog_post' ) ) : ?>
  <?php while ( bp_activities() ) : bp_the_activity();  ?>
    <div class="activity-header">           
      <?php bp_activity_action(); ?>
    </div>   
  <?php endwhile; ?>
<?php endif;?>

I have checked through the documentation and haven't been able to find a solution. In the forums I found some suggestions about using filters, but am unfamiliar with their use and could not get it to work.

Any help would be appreciated.

È stato utile?

Soluzione

I do not have a complete solution for you, but I have at least succeeded in breaking out the time stamp. Here is code I have modified from entry.php in the Buddypress legacy template:

<div class="activity-header">

    <div class="activity-title">

        <?php 
            $args = array(
                'no_timestamp' => true,
            );
            bp_activity_action( $args ); 
        ?>

        <?php if ( 'activity_comment' == bp_get_activity_type() ) : ?>

            <div class="activity-inreplyto">
                <strong><?php _e( 'In reply to: ', 'buddypress' ); ?></strong><?php bp_activity_parent_content(); ?> <a href="<?php bp_activity_thread_permalink(); ?>" class="view" title="<?php esc_attr_e( 'View Thread / Permalink', 'buddypress' ); ?>"><?php _e( 'View', 'buddypress' ); ?></a>
            </div>

        <?php endif; ?>

    </div>

    <div class="activity-time">

        <?php echo bp_core_time_since( bp_get_activity_date_recorded() ); ?>

    </div>

</div>

The bp_activity_action() function allows an argument to hide the timestamp. There is an explanation of how the argument works in the function code, which you can find in buddypress\bp-activity\bp-activity-template.php.

In the code above, I have used the argument to hide the timestamp from the bp_activity_action() output. Then I have used the bp_core_time_since() function to output the timestamp, which, on my site, is formatted separately on another line.

You can see the formatted output here: https://i.stack.imgur.com/akbiS.jpg

There is some discussion of enhancing Buddypress to provide for separate output of the elements you mention. See https://buddypress.trac.wordpress.org/ticket/5261. According to this discussion the changes were to have been implemented in Buddypress 2.0, but I am not able to find them.

Hope this helps. :-)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top