Community Forums › Forums › Archived Forums › Design Tips and Tricks › (Pretty Creative) Order of Portfolio Page Items
Tagged: Portfolio CPT, pre_get_posts, Pretty Creative
- This topic has 7 replies, 3 voices, and was last updated 8 years, 4 months ago by paulag01.
-
AuthorPosts
-
April 28, 2016 at 3:54 pm #184638paulag01Member
I am using the Pretty Creative Theme for a new site (URL below)
I am using a custom field called portfolio-order to order the 6 portfolio items on the home page. That works as it should.
On the Portfolio Archive Page (Which I am linking to from the Samples nav menu item) - I cannot control the # of items displayed or the order. (http://karinrex.com/newsite/portfolio/)
How can I simply display them in the same order as the home page? There is no "settings" page in the Portfolio feature.
http://karinrex.com/newsiteApril 28, 2016 at 9:34 pm #184655Doug EdgingtonMemberI haven't used this theme. But you should be able to control the order by modifying the post dates. They likely display in descending order - most recent date first.
In regards to controlling the number of portfolio items, you can go to settings-->reading and set "Blog pages show at most" to the desired setting. But this will also affect your blog. If you need to single out the portfolio section separate from the blog, you could use code like the example below to modify the query. The example assumes the post type name is portfolio. The code would need to be placed in the functions.php file.
//* Change the number of portfolio items to be displayed to 9 add_action( 'pre_get_posts', 'dee_portfolio_count' ); function dee_portfolio_count( $query ) { if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'portfolio' ) ) { $query->set( 'posts_per_page', '9' ); } }
Doug Edgington
http://www.dougedgington.comApril 29, 2016 at 6:18 am #184674paulag01MemberThanks Doug. The reading setting for blogs worked like a charm. She isn't going to have a regular blog so it works.
My bigger concern is the display order. Basically one portfolio item for each area of her business service. So each time she would add/update something, it would change the order. What she really wants is a set order all the time (regardless of last updated date). Is there any way to have it order differently (by a custom field or similar)?
Thanks
PaulaApril 29, 2016 at 8:31 am #184684Doug EdgingtonMemberYou could modify the query to display by menu_order rather than the date. And you could then set the "order field" in the attributes box for each post.
If you have a taxonomy applied to the portfolio custom post type, you can also categorize the portfolio posts like would a blog. Not sure if this would help out in any way with what you are doing.
Doug Edgington
http://www.dougedgington.comApril 30, 2016 at 12:26 am #184725Brad DaltonParticipantIs there any way to have it order differently (by a custom field or similar)?
You can use the custom field parameters from WP_Query as seen here
May 2, 2016 at 9:06 am #184802paulag01MemberThank you Brad and Doug for the info.
So Brad, if I am tracking right with your response, I would need to make a change to the php that generates the blog posts for that page then.
But I am not sure syntactically how to handle adding in an order and orderby parameter to what exists there. Can I just add an $order and $orderby parameter, but then how does it get recognized by the $wp_query (or does it happen automatically).
Like
'meta_key' => 'portfolio-order',
'orderby' => 'meta_value',
'order' => 'ASC',function be_portfolio_post_class( $classes ) {
if ( is_main_query() ) { // conditional to ensure that column classes do not apply to Featured widgets
$columns = 3; // Set the number of columns here
$column_classes = array( '', '', 'one-half', 'one-third', 'one-fourth', 'one-fifth', 'one-sixth' );
$classes[] = $column_classes[$columns];
global $wp_query;
if( 0 == $wp_query->current_post || 0 == $wp_query->current_post % $columns )
$classes[] = 'first';
}
return $classes;---
One of these great "template only" jobs turned.... but can we customize this? Scenarios.
Any insight much appreciated.
Thanks
PaulaMay 2, 2016 at 5:29 pm #184851Brad DaltonParticipantUse the code Doug posted and add the order and orderby parameters.
Something like this:
//* Change the number of portfolio items to be displayed to 9 add_action( 'pre_get_posts', 'dee_portfolio_count' ); function dee_portfolio_count( $query ) { if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'portfolio' ) ) { $query->set( 'posts_per_page', '9' ); $query->set('meta_key', 'portfolio-order' ); $query->set('orderby', array('meta_value' => 'ASC', 'date' => 'DESC')); } }
You could also add is_home() to the conditional checks.
Untested.
May 3, 2016 at 11:22 am #184908paulag01MemberThanks for these. I did give this a whirl with a few edits but couldn't seem to make it change the order.
Maybe I just need to try it on another test site at some point....
//* Change the number of portfolio items to be displayed to 9
function dee_portfolio_count( $query ) {
if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'portfolio' ) ) {
$query->set( 'posts_per_page', '6' );
$query->set('meta_key', 'portfolio-order' );
$query->set('orderby', array('meta_value_num' => 'ASC', 'date' => 'DESC'));
}
return $query;
}add_action( 'pre_get_posts', 'dee_portfolio_count' );
/**
* Display as Columns
*
*/
function be_portfolio_post_class( $classes ) {
if ( is_main_query() ) { // conditional to ensure that column classes do not apply to Featured widgets
$columns = 3; // Set the number of columns here
$column_classes = array( '', '', 'one-half', 'one-third', 'one-fourth', 'one-fifth', 'one-sixth' );
$classes[] = $column_classes[$columns];
global $wp_query;
if( 0 == $wp_query->current_post || 0 == $wp_query->current_post % $columns )
$classes[] = 'first';
}
return $classes;
}
add_filter( 'post_class', 'be_portfolio_post_class' );If there's something glaring I am missing, let me know... else I may just create a test site and play with basics (away from this theme). I convinced the client it was out of scope for now, so that problem is solved.
Appreciate both of you taking time to help move me along. At least I've learned something (even if I didn't solve the immediate problem) I can apply ongoing.
Paula
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.