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 8 years ago by
floriangoguillon.
-
This topic was modified 8 years ago by
-
I have set my menu display location to Primary Menu with the intended menu name and menu items. No items then appear when visiting the website. When I uncheck the Primary Menu, the Design heading then appears.
This may have something to do with the child theme set up for the home page to land on the Design projects types alone and not the whole archive and now I have to work around this to also add and show other project types as items in the menu.
Depending on how the child theme is set up, it shouldn’t impact the menu listing. It’s strange that you’re setting a custom menu to display but nothing is coming up.
It might be worth testing your menu on the parent theme, see if it works. Then try it again on the child theme.
I tried it with nothing in the child theme but it made no difference. The only way at this time for me to get a listing in the menu is to add a new page called “illustration”. As before, if I check “primary menu” no listings appear.
Perhaps if I made an alternate addition to the child theme along the lines of the code there for “design”, I could have a separate page which only listed illustration projects. Below is the child theme code for the design projects.
/*
Theme Name: Blask Child
Template: blask
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: blask-child
*/
<?phpfunction my_theme_enqueue_styles() {
$parent_style = ‘parent-style’;
wp_enqueue_style( $parent_style, get_template_directory_uri() . ‘/style.css’ );
wp_enqueue_style( ‘child-style’,
get_stylesheet_directory_uri() . ‘/style.css’,
array( $parent_style ),
wp_get_theme()->get(‘Version’)
);
.site-branding {
display: none;
}.site-info { display: none; }
}
add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’ );
// https://www.ads-software.com/support/topic/specific-project-type-on-front-page/#post-8873507
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’ => ‘design’,
),
)
);
}
}
add_action( ‘pre_get_posts’, ‘my_home_project_type’ );
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’,”);
}
}Looks like you’ve included @floriangoguillon’s code to fix his missing menu. Looking back through this thread, I’m still not sure why that menu had trouble to begin with.
I’ve just created a brand new site, installed Blask, and tested my original snippet again (using ‘design’ as the slug to hopefully match your setup exactly).
The homepage was properly filtered, and the menu was unaffected.
I then clicked into Appearance > Customize > Menus.
I created a new menu, and clicked Add Items.
Under Pages, I added a link to the home page, and changed the label to say Design, to match your setup.
I then used the Project Types panel to add my Illustrations project type into the menu. Saved everything, closed the Customizer, and tested – everything works.
My advice would be to remove that second snippet of code, and use just the one from my original answer.
If that doesn’t work, you’ll probably want to get as fresh a start as you can:
– Uninstall Blask
– Delete your child theme
– Delete any custom menus you’ve saved
– Reinstall Blask (fresh copy from the .org repo)
– Recreate your child theme with just the first snippet (linked above)
– Test the site – is your menu still there?
– Edit your portfolio projects. Make sure there are some assigned to the Illustrations project type
– Use My Site > Customize > Menus to create a new menu that includes a link to the Home page and a link to the Illustrations project type.If you don’t succeed somewhere along the way through that process, it must be something else in your install – a conflicting plugin perhaps.
Start by removing that second snippet from your child theme, and let me know what happens!
Hello Chad,
Thanks for the above thorough instructions. I tried your list of directions on my site and now have success in listing both my menu items with the project types.
On the other hand, I am not having success now with the child theme which was meant to have my opening page just present my “design” projects. I understand that when you suggested using the first snippet of code you meant the following—
<?php
function my_theme_enqueue_styles() {
$parent_style = ‘parent-style’;
wp_enqueue_style( $parent_style, get_template_directory_uri() . ‘/style.css’ );
wp_enqueue_style( ‘child-style’,
get_stylesheet_directory_uri() . ‘/style.css’,
array( $parent_style ),
wp_get_theme()->get(‘Version’)
);
}
add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’ );
// https://www.ads-software.com/support/topic/specific-project-type-on-front-page/#post-8873507
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’ => ‘design’,
),
)
);
}
}
add_action( ‘pre_get_posts’, ‘my_home_project_type’ );
I used the above code in my child theme but it didn’t work as it did originally.
I just get the combined project types “design” and “illustration”. I disabled plugins but it had no effect.I decided to also start from scratch, to make sure we were working with identical canvases.
This time (totally new Blask install, brand new child theme) I actually was able to reproduce what you and @floriangoguillon originally reported, with the menu missing.
Not sure why it didn’t happen on my test site when I first proposed that solution, but I see what was happening now.
So, with that in mind, I’ve taken a new approach. Let’s work directly in the Portfolio Page template (this assumes that the Design-only home page is the only place on the site that you intend to use this template).
First – remove the code we’ve been using. Your child theme’s
functions.php
file should have only the initial enqueueing function.Next, go into the parent Blask theme, and copy
portolio-page.php
into your child theme’s folder. Open up that copy.This template runs a special query for just portfolio items. We’re going to modify that query.
Currently, the arguments for the query look like this:
$args = array( 'post_type' => 'jetpack-portfolio', 'posts_per_page' => $posts_per_page, 'paged' => $paged, );
We’re going to add the project type we want into them, so they look like this instead:
$args = array( 'post_type' => 'jetpack-portfolio', 'posts_per_page' => $posts_per_page, 'paged' => $paged, 'tax_query' => array( array( 'taxonomy' => 'jetpack-portfolio-type', 'field' => 'slug', 'terms' => 'design', ), ) );
Now, because the query modification is happening directly in the template, there’s no chance of it interacting with the menu ??
Let me know how that goes!
I removed the code from the child theme, copied the Blask parent theme portfolio-page.php and inserted it into the child theme functions.php file. The code you posted is different from that in my parent file, mine is without #? numbers. My code is shown below.
$args = array(
‘post_type’ => ‘jetpack-portfolio’,
‘posts_per_page’ => $posts_per_page,
‘paged’ => $paged,When I added your code after the code above in my functions.php child theme with the now parent portfolio-page.php, I got a total white screen and had to go back to my cpanel and trash my child theme.
-
This reply was modified 7 years, 6 months ago by
timyoungorg.
mine is without #? numbers
I’m not sure what you mean here but let’s attack this a little differently to make sure we’re on the same page.
Your child theme should have the following:
style.css
/* Theme Name: Blask Child Theme URI: Description: Blask child theme. Author: Me Author URI: Template: blask Version: 0.1.0 */
functions.php
<?php add_action( 'wp_enqueue_scripts', 'blask_parent_theme_enqueue_styles' ); function blask_parent_theme_enqueue_styles() { wp_enqueue_style( 'blask-style', get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'blask-child-style', get_stylesheet_directory_uri() . '/style.css', array( 'blask-style' ) ); }
portfolio-page.php
use the code at this link (this is a full dump of my own child theme’sportfolio-page.php
file).Set up a child theme with just that code, and just those three files, and you’ll be running exactly what I am here ??
Also, if you need to post code, put a backtick before and after the code block (usually the top left of your keyboard, on the same key as the ~ symbol). That will preserve the formatting of your code ??
I followed the steps of your latest posting and after adding the code you gave in the link to the function.php file. My screen was white except for the code below,
across the top.Getting better than a blank screen I guess. No backticks added in this case.
functions.php <?php add_action( ‘wp_enqueue_scripts’, ‘blask_parent_theme_enqueue_styles’ ); function blask_parent_theme_enqueue_styles() { wp_enqueue_style( ‘blask-style’, get_template_directory_uri() . ‘/style.css’ ); wp_enqueue_style( ‘blask-child-style’, get_stylesheet_directory_uri() . ‘/style.css’, array( ‘blask-style’ ) ); }
I hope the last bit I sent didn’t sound smart-ass. I wonder if there is anything else to be done going down this route. I don’t want to take up too much of your time. Would hiring a freelance designer be the way to go? It might not take much time if they were working on it directly.
I hope the last bit I sent didn’t sound smart-ass.
Not at all ??
I followed the steps of your latest posting and after adding the code you gave in the link to the function.php file
That sounds like your problem.
The code from the link will be used to create a copy of
portfolio-page.php
in the child theme.The
functions.php
file in the child theme should have only this code:<?php add_action( 'wp_enqueue_scripts', 'blask_parent_theme_enqueue_styles' ); function blask_parent_theme_enqueue_styles() { wp_enqueue_style( 'blask-style', get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'blask-child-style', get_stylesheet_directory_uri() . '/style.css', array( 'blask-style' ) ); }
Chad,
I have the problem sorted out finally and I want to thank you for all your help on this problem. I hope the rest of the sorting out of my site goes a lot more smoothly.
Glad it’s working ??
-
This reply was modified 7 years, 6 months ago by
- The topic ‘Specific project type on front page’ is closed to new replies.