Community Forums › Forums › Archived Forums › General Discussion › HELP! I need assistance from a conditional statement guru!
- This topic has 8 replies, 2 voices, and was last updated 7 years ago by Bill.
-
AuthorPosts
-
March 26, 2017 at 11:22 am #203835BillParticipant
I want to add a genesis widget area at the bottom of my content area, but I want it to only show in this manner:
1) display widget area on the bottom of pages and NOT posts
2) display the widget area on the bottom of two custom post types....a custom post type called "cpt1" and also another custom post type called "cpt2"
3) but I also want to EXCLUDE the widget area on different custom page templates I created called "page-template-1" and "page-template-2"
This is what I came up with but, in application, it does not exclude the widget area in the page templates listed in #3.
// Add after entry widget to posts and pages
add_action( 'genesis_after_entry', 'mcq_after_entry' );
function mcq_after_entry() {if ( is_singular( array ('page', 'cpt1', 'cpt2')) && !is_page_template ( array ('page-template-1', 'page-template-2') )) {
genesis_widget_area( 'content-bottom', array(
'before' => '<div class="content-bottom widget-area">',
'after' => '</div>',
) );
}
}Anyone know what I am doing wrong?
March 26, 2017 at 11:31 am #203836Brad DaltonParticipantChange the && to || and make sure you use the correct page template conditionals
March 26, 2017 at 11:44 am #203837BillParticipantThank you for the reply Brad. I looked at the conditionals for the page template...I thought that was right when I wanted to include two different page templates to exclude. What do you see wrong with it?
Also, I thought the || was for the term "OR", not "IN ADDITION TO". I need it to be treated like "IN ADDITION TO". Am I wrong in thinking that?
March 26, 2017 at 11:49 am #203838Brad DaltonParticipantMarch 26, 2017 at 2:03 pm #203843BillParticipantI created two genesis page templates to be able to display property listings generated from a real estate idx plugin. I created the templates, then assigned the templates in the idx plugin admin area.
one template is for listing results like this:
the other template is for details for individual property listings like this:
Here is a link to the actual template files
https://www.dropbox.com/sh/kgste23wj4oiy6b/AACUW81wm5k2xOzHAbn_f94va?dl=0in my initial inquiry above, I changed the name of the cpt's and the page templates for simplicity....but in my testing I do change them to the appropriate CPT names and appropriate template names.
FYI: The sidebar (found and assigned in these template files) is not the widget area I am talking about in my inquiry. Those are assigned to switch out the primary sidebar for these template pages. MY inquiry is about eliminating a content-bottom widget area for these template pages.
March 26, 2017 at 3:03 pm #203847Brad DaltonParticipantTry adding the filenames as the i.d's like this:
if ( is_singular( array ( 'page', 'cpt1', 'cpt2' ) ) || is_page_template( array( 'idxpress-results-template.php', 'idxpress-details-template.php' ) ) )
March 26, 2017 at 3:39 pm #203848BillParticipantHi Brad... that didn't work either. whether or not I have the .php at the end for each template name makes no different.
Let me ask this then....if I eliminate the page template array and leave it as this....
// Add after entry widget to posts and pages add_action( 'genesis_after_entry', 'mcq_after_entry' ); function mcq_after_entry() { if ( is_singular( array ('page','cpt1','cpt2') ) ) genesis_widget_area( 'content-bottom', array( 'before' => '<div class="content-bottom widget-area">', 'after' => '</div>', ) ); }
is there a different function I can use to eliminate this sidebar on the two different page templates?
March 26, 2017 at 3:46 pm #203849Brad DaltonParticipantTry using the id's like this
page-template-idxpress-details-template-php
and
page-template-idxpress-results-template-php
These aren't for a custom post type are they?
You can set the full width layout on any edit page screen
or
Conditionally set the layout to full width using code
You are adding the code to functions.php right?
March 26, 2017 at 5:54 pm #203851BillParticipantHi Brad... that didn't work either....but, I was able to accomplish it by going about it a different way (not sure why it took me so long to realize this method)....
I eliminated the second array for the page templates in the functions file, and then just removed the widget in the actual page template itself. ....Works like a champ.
Thank you for your assistance!!!
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.