438 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $5,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
Pixelous says

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?

3711 posts Ruben Bristian
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
+10 more
KrownThemes says

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?

438 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $5,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
Pixelous says

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.

3711 posts Ruben Bristian
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
+10 more
KrownThemes says

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.

3437 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says
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' );
     }
}
3711 posts Ruben Bristian
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
+10 more
KrownThemes says

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' );
     }
}
He doesn’t want to enqueue isotope .. he wants to add a small snippet inside the theme. no external js file.
3437 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says


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' );
     }
}
He doesn’t want to enqueue isotope .. he wants to add a small snippet inside the theme. no external js file.

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_script

either 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
     }

438 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $5,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
Pixelous says

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?

3437 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

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?

501 posts
  • Has referred 1000+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+8 more
pixelentity says
echo get_page_template_slug( get_queried_object_id() );
to check if page template slug is correct

BF

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by