This gonna drive me crazy. Can’t make it work 
<?php if ( is_page_template('page-portfolio-2-columns-isotope.php')
|| is_page_template('page-portfolio-3-columns-isotope.php')
|| is_page_template('page-portfolio-4-columns-isotope.php') ) : ?>
// script goes here
<?php endif; ?>
But it isn’t works for me. And this:
if ( is_page_template('page-portfolio-2-columns-isotope.php')
|| is_page_template('page-portfolio-3-columns-isotope.php')
|| is_page_template('page-portfolio-4-columns-isotope.php') ) :
wp_enqueue_script( 'jquery.isotope.min' );
endif;
works well. How could it be? Any help, guys?
- Most Wanted Bounty Winner
- Sold between 250 000 and 1 000 000 dollars
- Has been a member for 5-6 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Won a Competition
- Bought between 100 and 499 items
- Exclusive Author
- Referred between 200 and 499 users
Why don’t you post the entire code? Maybe you have an issue inside //script goes here .. I have some small snippets of scripts put like that in my themes and they work just fine .. it doesn’t look like any kind of php issue.
Do you see your script outputted in the source code?
RubenBristian said
Why don’t you post the entire code? Maybe you have an issue inside //script goes here .. I have some small snippets of scripts put like that in my themes and they work just fine .. it doesn’t look like any kind of php issue. Do you see your script outputted in the source code?
Nope, I don’t see my script outputted in the source code, tha’t the problem. Actually my script is big enough, here it is:
<?php if ( is_page_template('page-portfolio-2-columns-isotope.php')
|| is_page_template('page-portfolio-3-columns-isotope.php')
|| is_page_template('page-portfolio-4-columns-isotope.php') ) : ?>
// Isotope
// modified Isotope methods for gutters in masonry
jQuery.Isotope.prototype._getMasonryGutterColumns = function() {
var gutter = this.options.masonry && this.options.masonry.gutterWidth || 0;
containerWidth = this.element.width();
this.masonry.columnWidth = this.options.masonry && this.options.masonry.columnWidth ||
// or use the size of the first item
this.$filteredAtoms.outerWidth(true) ||
// if there's no items, use size of container
containerWidth;
this.masonry.columnWidth += gutter;
this.masonry.cols = Math.floor( ( containerWidth + gutter ) / this.masonry.columnWidth );
this.masonry.cols = Math.max( this.masonry.cols, 1 );
};
jQuery.Isotope.prototype._masonryReset = function() {
// layout-specific props
this.masonry = {};
// FIXME shouldn't have to call this again
this._getMasonryGutterColumns();
var i = this.masonry.cols;
this.masonry.colYs = [];
while (i--) {
this.masonry.colYs.push( 0 );
}
};
jQuery.Isotope.prototype._masonryResizeChanged = function() {
var prevSegments = this.masonry.cols;
// update cols/rows
this._getMasonryGutterColumns();
// return if updated cols/rows is not equal to previous
return ( this.masonry.cols !== prevSegments );
};
// cache container
var $container = jQuery('#portfolio');
// initialize isotope
$container.isotope({
masonry: {
columnWidth: <?php if ( is_page_template('page-portfolio-2-columns-isotope.php') ) { ?> 454, <?php } else if ( is_page_template('page-portfolio-3-columns-isotope.php') ) { ?> 292, <?php } else if ( is_page_template('page-portfolio-4-columns-isotope.php') ) { ?> 212, <?php } ?>
gutterWidth: 30
}
});
// filter items when filter link is clicked
jQuery('#filters a').click(function() {
var selector = jQuery(this).attr('data-filter');
$container.isotope({ filter: selector });
return false;
});
// set selected menu items
var $optionSets = jQuery('.option-set'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function(){
var $this = jQuery(this);
// don't proceed if already selected
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('.option-set');
$optionSet.find('.selected').removeClass('selected');
$this.addClass('selected');
});
<?php endif; ?>
It’s really strange, it should works fine, but for some reason it doesn’t. A php conditions don’t work.
- Most Wanted Bounty Winner
- Sold between 250 000 and 1 000 000 dollars
- Has been a member for 5-6 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Won a Competition
- Bought between 100 and 499 items
- Exclusive Author
- Referred between 200 and 499 users
Do you have the php conditionals inside the <script> ?
You should make a brand new <script> and put the conditionals before it.. That’s how i do it.
add_action('wp_enqueue_scripts', 'your_prefix_port_scripts');
function your_prefix_port_scripts(){
if ( is_page_template('page-portfolio-2-columns-isotope.php')
|| is_page_template('page-portfolio-3-columns-isotope.php')
|| is_page_template('page-portfolio-4-columns-isotope.php') ) {
wp_enqueue_script( 'jquery.isotope.min' );
}
}- Most Wanted Bounty Winner
- Sold between 250 000 and 1 000 000 dollars
- Has been a member for 5-6 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Won a Competition
- Bought between 100 and 499 items
- Exclusive Author
- Referred between 200 and 499 users
OrganicBeeMedia saidHe doesn’t want to enqueue isotope .. he wants to add a small snippet inside the theme. no external js file.
add_action('wp_enqueue_scripts', 'your_prefix_port_scripts'); function your_prefix_port_scripts(){ if ( is_page_template('page-portfolio-2-columns-isotope.php') || is_page_template('page-portfolio-3-columns-isotope.php') || is_page_template('page-portfolio-4-columns-isotope.php') ) { wp_enqueue_script( 'jquery.isotope.min' ); } }
RubenBristian said
OrganicBeeMedia saidHe doesn’t want to enqueue isotope .. he wants to add a small snippet inside the theme. no external js file.
add_action('wp_enqueue_scripts', 'your_prefix_port_scripts'); function your_prefix_port_scripts(){ if ( is_page_template('page-portfolio-2-columns-isotope.php') || is_page_template('page-portfolio-3-columns-isotope.php') || is_page_template('page-portfolio-4-columns-isotope.php') ) { wp_enqueue_script( 'jquery.isotope.min' ); } }
well thats just a bad idea in the first place, if he needs variables he should be using localized scripts
http://codex.wordpress.org/Function_Reference/wp_localize_scripteither way
if ( is_page_template('page-portfolio-2-columns-isotope.php')
|| is_page_template('page-portfolio-3-columns-isotope.php')
|| is_page_template('page-portfolio-4-columns-isotope.php') ) {
put your js here
}
Chris, this:
if ( is_page_template('page-portfolio-2-columns-isotope.php')
|| is_page_template('page-portfolio-3-columns-isotope.php')
|| is_page_template('page-portfolio-4-columns-isotope.php') ) {
put your js here
}
doesn’t work for me, but in this case:
if ( is_page_template('page-home.php')
|| is_page_template('page-portfolio-3-columns-isotope.php')
|| is_page_template('page-portfolio-4-columns-isotope.php') ) {
put your js here
}
works well only for page-home.php. So, for one template it’s works well but another ignores. How could it be? I really don’t understand, maybe it is a bug?
Pixelous said
Chris, this:if ( is_page_template('page-portfolio-2-columns-isotope.php') || is_page_template('page-portfolio-3-columns-isotope.php') || is_page_template('page-portfolio-4-columns-isotope.php') ) { put your js here }doesn’t work for me, but in this case:
if ( is_page_template('page-home.php') || is_page_template('page-portfolio-3-columns-isotope.php') || is_page_template('page-portfolio-4-columns-isotope.php') ) { put your js here }works well only for page-home.php. So, for one template it’s works well but another ignores. How could it be? I really don’t understand, maybe it is a bug?
do you have any dev tools on? see if its throwing any errors at you
wp_debug in the config file will do enough but theres a ton of plugins to assist with errors
also are you sure those are the correct names?
- Sold between 100 000 and 250 000 dollars
- Won a Competition
- Author was Featured
- Item was Featured
- Referred between 500 and 999 users
- Author had a Free File of the Month
- Author had a File in an Envato Bundle
- Bought between 10 and 49 items
echo get_page_template_slug( get_queried_object_id() );to check if page template slug is correct
BF
