ncrocfer avatar ncrocfer committed b779b4f

Changed the widget to make it compatible with the template system

Comments (0)

Files changed (2)

includes/bp-portfolio-functions.php

  * Render the latest projects
  */
 function bp_portfolio_show_last_projects( $max = 5 ) {
-    
-    while ( bp_portfolio_has_items( array('posts_per_page' => $max) ) ) : bp_portfolio_the_item();
-    ?>
-
-        <div class="widget-item-project">
-            <div class="widget-item-project-pictures">
-                <img src="<?php bp_portfolio_item_thumbnail( 'portfolio-widget-thumb' ) ?>" width="36px" height="36px" />
-            </div>
-            <div class="widget-item-project-content">
-                <p>
-                    <a href="<?php echo bp_core_get_user_domain( bp_portfolio_get_user_id() ) . BP_PORTFOLIO_SLUG; ?>" title="<?php echo sprintf(__('from %s', 'bp-portfolio'), bp_portfolio_get_item_author()); ?>"><?php bp_portfolio_item_title() ?></a>
-                </p>
-            </div>
-        </div>
-
-    <?php
-    endwhile;
-    ?>
-
-    <span class="widget-all-projects"><a href="<?php echo trailingslashit(site_url()) . BP_PORTFOLIO_SLUG; ?>"><?php _e('See all projects', 'bp-portfolio'); ?></a></span>
-
-    <?php
+    global $bp_portfolio_widget_last_projects_max;
+    $bp_portfolio_widget_last_projects_max = $max;
+    load_template( apply_filters( 'bp_load_template', BP_PORTFOLIO_PLUGIN_DIR . '/templates/' . BP_PORTFOLIO_TEMPLATE . '/widgets/last-projects-widget.php' ), false );
 }
 
 

templates/default/widgets/last-projects-widget.php

+<?php
+global $bp_portfolio_widget_last_projects_max;
+
+$projects = new BP_Portfolio_Item();
+$projects->get(array('posts_per_page' => $bp_portfolio_widget_last_projects_max));
+//print_r($projects);
+?>
+
+<?php
+foreach($projects->query->posts as $project) :
+    
+    $attachment = wp_get_attachment_image_src($project->post_parent, 'portfolio-widget-thumb');        
+    if($attachment != 0)
+        $thumbnail = apply_filters( 'bp_portfolio_get_item_thumbnail', $attachment[0]);
+    else
+        $thumbnail = apply_filters( 'bp_portfolio_get_item_thumbnail', BP_PORTFOLIO_PLUGIN_URL . '/templates/' . BP_PORTFOLIO_TEMPLATE . '/img/default.png');
+?>
+
+    <div class="widget-item-project">
+        <div class="widget-item-project-pictures">
+            <img src="<?php echo $thumbnail; ?>" width="36px" height="36px" />
+        </div>
+        <div class="widget-item-project-content">
+            <p>
+                <a href="<?php echo bp_core_get_user_domain( $project->post_author ) . BP_PORTFOLIO_SLUG; ?>" title="<?php echo sprintf(__('from %s', 'bp-portfolio'), bp_core_get_user_displayname( $project->post_author )); ?>"><?php echo $project->post_title; ?></a>
+            </p>
+        </div>
+    </div>
+
+<?php
+endforeach;
+?>
+
+<span class="widget-all-projects"><a href="<?php echo trailingslashit(site_url()) . BP_PORTFOLIO_SLUG; ?>"><?php _e('See all projects', 'bp-portfolio'); ?></a></span>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.