• johnnyjp

    (@johnnyjp)


    hey there

    im trying to customize user’s profile page, to show his/her pictures just underneath the avatar.

    i’ve taken a look at file called bp-album-templatetags.php and i tried to use the default loop (the one included in the comment at the top) but after doing this i get this error

    Fatal error: Call to a member function the_picture() on a non-object in /home/punk182/public_html/site/wp-content/plugins/bp-album/includes/bp-album-templatetags.php on line 157

    how can i make it work?

    http://wordpress.org/extend/plugins/bp-album/

Viewing 9 replies - 1 through 9 (of 9 total)
  • foxly

    (@foxly)

    It sounds like you’re trying to use a BP Album+ template tag inside a template that doesn’t belong to the plugin.

    Post a copy of the template file you’re trying to edit and I’ll take a look at it.

    ^F^

    Thread Starter johnnyjp

    (@johnnyjp)

    hey

    its a child theme based on default theme for buddypress and the file name that i’d like to include this tag in is my_theme/members/single/member-header.php

    heres the original code for that file

    <?php do_action( 'bp_before_member_header' ) ?>
    
    <div id="item-header-avatar">
    	<a href="<?php bp_user_link() ?>">
    		<?php bp_displayed_user_avatar( 'type=full' ) ?>
    	</a>
    </div><!-- #item-header-avatar -->
    
    <div id="item-header-content">
    
    	<h2 class="fn"><a href="<?php bp_user_link() ?>"><?php bp_displayed_user_fullname() ?></a> <span class="highlight">@<?php bp_displayed_user_username() ?> <span>?</span></span></h2>
    	<span class="activity"><?php bp_last_activity( bp_displayed_user_id() ) ?></span>
    
    	<?php do_action( 'bp_before_member_header_meta' ) ?>
    
    	<div id="item-meta">
    		<?php if ( function_exists( 'bp_activity_latest_update' ) ) : ?>
    			<div id="latest-update">
    				<?php bp_activity_latest_update( bp_displayed_user_id() ) ?>
    			</div>
    		<?php endif; ?>
    
    		<div id="item-buttons">
    			<?php if ( function_exists( 'bp_add_friend_button' ) ) : ?>
    				<?php bp_add_friend_button() ?>
    			<?php endif; ?>
    
    			<?php if ( is_user_logged_in() && !bp_is_my_profile() && function_exists( 'bp_send_public_message_link' ) ) : ?>
    				<div class="generic-button" id="post-mention">
    					<a href="<?php bp_send_public_message_link() ?>" title="<?php _e( 'Mention this user in a new public message, this will send the user a notification to get their attention.', 'buddypress' ) ?>"><?php _e( 'Mention this User', 'buddypress' ) ?></a>
    				</div>
    			<?php endif; ?>
    
    			<?php if ( is_user_logged_in() && !bp_is_my_profile() && function_exists( 'bp_send_private_message_link' ) ) : ?>
    				<div class="generic-button" id="send-private-message">
    					<a href="<?php bp_send_private_message_link() ?>" title="<?php _e( 'Send a private message to this user.', 'buddypress' ) ?>"><?php _e( 'Send Private Message', 'buddypress' ) ?></a>
    				</div>
    			<?php endif; ?>
    		</div><!-- #item-buttons -->
    
    		<?php
    		 /***
    		  * If you'd like to show specific profile fields here use:
    		  * bp_profile_field_data( 'field=About Me' ); -- Pass the name of the field
    		  */
    		?>
    
    		<?php do_action( 'bp_profile_header_meta' ) ?>
    
    	</div><!-- #item-meta -->
    
    </div><!-- #item-header-content -->
    
    <?php do_action( 'bp_after_member_header' ) ?>
    
    <?php do_action( 'template_notices' ) ?>
    foxly

    (@foxly)

    I need you to post the code that is *not* working …lol 🙂

    ^F^

    Thread Starter johnnyjp

    (@johnnyjp)

    well its the default snipped included in bp-album-templatetags.php

    /**
     * Example use in the template file:
     *
     * 	<?php if ( bp_album_has_pictures() ) : ?>
     *
     *		<?php while ( bp_album_has_pictures() ) : bp_album_the_picture(); ?>
     *
     *			<a href="<?php bp_album_picture_url() ?>">
     *				<img src='<?php bp_album_picture_thumb_url() ?>' />
     *			</a>
     *
     *		<?php endwhile; ?>
     *
     *	<?php else : ?>
     *
     *		<p class="error">No Pics!</p>
     *
     *	<?php endif; ?>
     *
     *
     */

    foxly

    (@foxly)

    You are trying to use a BP Album+ template tag *outside* of the part of BuddyPress that BP Album+ has control over.

    With the exception of functions that retrieve global system variables, template tags are not universal objects that work everywhere in a BP installation. Most of them only work within a specific “loop” that fetches data related to the tag.

    Here’s how it works:

    ============ bp_album_query_pictures($args) ================

    (Media template object is now filled with pictures matching query and is ready to be “looped” through)

    =============== bp_album_has_pictures() =================

    ============ bp_album_the_picture() =================

    (All media item template tags work at this point)

    ========================================================
    ========================================================
    ========================================================

    We (and all other plugins) run “the query” for you, before loading the template, because it’s *complicated*. And since the BP Album+ query doesn’t get run until BP hands execution control over to our plugin, our template tags are not valid in the “member-header.php” file, because that file gets loaded *before* our plugin.

    Now, that being said, you can be naughty and “hijack” that file.

    <?php
    
    global $bp, $pictures_template;
    
    bp_album_query_pictures($args)
    
    ?>
    
    <?php if ( bp_album_has_pictures() ) : ?>
    
       <?php while ( bp_album_has_pictures() ) : bp_album_the_picture(); ?>
    
          <a href="<?php bp_album_picture_url() ?>">
     				<img src='<?php bp_album_picture_thumb_url() ?>' />
     			</a>
    
     		<?php endwhile; ?>
    
     <?php else : ?>
    
     		<p class="error">No Pics!</p>
    
     <?php endif; ?>

    Where $args is an array, and these are the parameters:

    /**
             * Returns an array of Media Item objects based on user supplied parameters
             *
             * @version 1.0
             * @since 0.1.8
             * @param int $max | Unknown function. Please add documentation.
             * @param int $owner_id | The numeric member id of the member that uploaded the media
             * @param string $owner_type | The system role of the member that uploaded the media
             * @param int $id | The bp-album GUID for the piece of media
             * @param string $ids | A comma separated list of bp-album GUIDs for multiple media items
             * @param int $page | Used to set current page when traversing a multi-page data set
             * @param int $per_page | Number of objects to return per page when transversing multi-page data set
             * @param int string bool $privacy  | Sets the privacy level of the media item
             * @param bool $priv_override  | Makes system ignore privacy level when returning results
             * @param string $ordersort  | Sets sort order of the returned data set
             * @param string $orderkey  | Sets which parameter to order the returned results by
             * @param string $groupby  | Sets how to group returned results
             * @param string $tag  | Tag or comma separated list of tags used to search for media items
             * @param string $album  | Album or albums used to search for media
             * @param int $tagged_member  | BuddyPress member ID to search for in media items
             * @param string $adjacent  | 'next' gets the next media item if it exists, 'prev' gets the previous one.
             * @param bool $count  | Makes system returns a count of the number of results the query will return
             * @param int $offset  | Shifts results page forward or backward "n" items within the returned data set
             * @return bool|int|array False on failure. Int on count. Array of media item objects on success.
             */

    Note, however, that this code will break with the next release of the plugin.

    Enjoy!

    ^F^

    Thread Starter johnnyjp

    (@johnnyjp)

    thanks, it works perfect 🙂

    maybe this could a feature considered for the next release?

    Thread Starter johnnyjp

    (@johnnyjp)

    okay, one more thing – which one should i use to sort the results by desc date? order key or odred sort? and what will be the values?

    DESC / ASC = whether to sort the results in ascending or descending order.

    $orderkey = which parameter to sort the results by. Valid args are: ‘id’, ‘user_id’, ‘status’

    ^F^

    Thread Starter johnnyjp

    (@johnnyjp)

    great, thanks a lot for help!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Plugin: BuddyPress Album ] error when trying to use bp album template tags’ is closed to new replies.