Specific project type on front page
-
Hi,
I can’t find out how to display projects from a specific project type on my homepage using Blask template page. I mean I don’t want to show every project. I can only do it using shortcodes and the default template page which is without Blask style.
Any idea would be much appreciated!!!
Thanks.
-
This topic was modified 9 years, 3 months ago by
floriangoguillon.
-
This topic was modified 9 years, 3 months ago by
-
Definitely doable 🙂
The key here will be to alter the project type that the front page requests, without disrupting any other uses of the Portfolio Page Template.
Start by creating a child theme.
In your child theme’s
functions.phpfile, add the following filter:function my_home_project_type( $query ) { if ( is_front_page() && is_main_query() ) { $query->set( 'tax_query', array( array( 'taxonomy' => 'jetpack-portfolio-type', 'field' => 'slug', 'terms' => 'project-type-slug', ), ) ); } } add_action( 'pre_get_posts', 'my_home_project_type' );You’ll want to replace project-type-slug with your own project type, of course 🙂
Let me know how it goes!
Thanks a lot!!!!! It works almost perfectly. Do you know why the menu disappears with your code ?
The code shouldn’t affect the menu – but if this is a brand new child theme, you’ll want to add your menu back in under Appearance > Menus. Menus are specific to each individual theme/child theme 🙂
Thanks again for your help. Sorry I should have been more precise. The menu is missing only on the front page. This is not a new child theme by the way.
Your code seems to make my menu disappear on this particular page. The menu is back as soon as I try without it.
Could it be because of pre_get_posts interfering with the menus query ?
When I type “functions make my menu disappear” on Google, I can see similar cases but I have no knowledge about that so I can’t fix it.
Thanks for your time.
Thanks again for your help. Sorry I should have been more precise. The menu is missing only on the front page. This is not a new child theme by the way.
Your code seems to make my menu disappear on this particular page. The menu is back as soon as I try without it.
Could it be because of pre_get_posts interfering with the menus query ?
When I type “functions make my menu disappear” on Google, I can see similar cases but I have no knowledge about that so I can’t fix it.
Thanks for your time.
I found the solution adding the following code :
add_action( ‘pre_get_posts’, ‘my_pre_get_posts’ );
function my_pre_get_posts($query) {
if ($query->get(‘post_type’) === ‘nav_menu_item’) {
$query->set(‘tax_query’,”);
}
}Thanks again.
-
This reply was modified 9 years, 2 months ago by
floriangoguillon.
Glad you found a solution – I’m still not sure why it was affecting your menu (it didn’t do that on my own site).
The code checks to make sure it’s running on the page’s main query, so it doesn’t break other items on the page 🙂
If you’ve gotten it working, feel free to mark this as Resolved over in the sidebar 🙂
I have successfully, with support help, resolved a similar query. Is there a further procedure to complete my aim and get rid of the lettering at the top of the page which has appeared? I also guess your advice to redo the menu would apply to me as well?
The support thread of my previous help that has led to this is below.
https://ww.wp.xz.cn/support/topic/front-page-exclusive-project-type/#post-9252518
Hi @timyoungorg!
The text I see at the top of your site (
/* Theme Name: Blask Child Template: blask Version: 1.0.0 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Text Domain: blask-child */) Looks like the code comment that gets placed in thestyle.cssfile of a child theme.Check your child theme’s other files, and make sure this text only appears at the top of the
style.cssfile. Make sure it does not (for example) appear in something likefunctions.php.For the menu question, yes – you should be able to reset your menu in the Customizer under Menus.
Your advice worked in getting rid of the code comment. Thanks Chad.
On the matter of the menu, I have added back two items on the menu. The design heading works in just listing design items when clicked, but the illustration heading brings up all items—design and illustration. I still have my projects tagged as either design or illustration. Whether this is pertinent or not—when I visit the media library, I just get a spinning ball. Would you have any advice to get the illustration heading to work? Thanks.
The Illustration link in your menu points to http://timyoung.ca/wordpress/illustration
That is a page using the theme’s portfolio template, not the specific illustration tag.
Check under Appearance > Customize > Menus, and make sure you’ve added the project tag (or project type, depending on how you’ve organized them) to your menu, instead of a page.
As you say, I don’t want to add another page to get the “illustration” heading to appear in the menu. I can’t see how otherwise to do this. I don’t know if you can view my menu structure under “appearance” in timyoung.ca where I was experimenting with categories and project types.
hey @timyoungorg
I can’t see into your dashboard, no – but you don’t need to create a new page. All you are changing is the menu structure.
Under Appearance > Customize > Menus, click Add Items. Now you’ll get a list of all of the different kinds of things you can put in your menu. WordPress automatically generates archives of most content types. Look in Project Types for Illustrations – you can add a link to that archive into your menu, so all of the projects belonging to that type are listed.
The Menu page instructions make sense to me and I have an Illustration Project Type added to the Menu Structure but it does not appear as a menu item on my website. The Design heading as a page heading does appear on the menu area. This heading appears without any box selected under Menu Settings. When I check Primary Menu in the settings, the Design heading disappears on my website. Well, whatever works, but this seems strange.
I apologize if this seems elementary, but it has me stumped.
No need to apologize!
It sounds from here like you have set up a menu with the links you want, but haven’t actually enabled it.
In addition to menus, there are also menu locations. You can create a custom menu, but you need to actually assign it to the menu location for it to appear.
Make a not of the name of the menu that has the right links, and make sure it’s set to the primary menu location.
-
This reply was modified 9 years, 2 months ago by
The topic ‘Specific project type on front page’ is closed to new replies.
