The MU forums have moved to WordPress.org

how to use jquery within a post in mu? (9 posts)

  1. anointed
    Member
    Posted 14 years ago #

    I'm trying to apply a js sliding door effect to an article page within wordpress-mu without any luck.

    It seems that somehow wpmu is not recognizing my jquery in the header, only within pages and articles and I can't figure out why.

    I have a plugin on my website, where I have coded in the sliding door effect, 'hide text in a hidden div' and it works perfectly so I know everything is configured correctly.

    Does wpmu somehow ignore any jquery when it's referenced within pages or articles?

    Within my article itself, the only code I have to add is
    <a class="trigger" href="#"> and of course I have to add the div's defined within the stylesheet that are supposed to be hidden.

    I have already added the needed code to the stylesheet.

    any help would be greatly appreciated.

  2. tim.moore
    Member
    Posted 14 years ago #

    Have you checked to make sure that your <a class="trigger" href="#"> is still in the page after you save it? WPMU typically strips out most JavaScript and advanced HTML for security reasons.

  3. anointed
    Member
    Posted 14 years ago #

    Yes, the a class stays in the code, it just does not activate the jquery when clicked.

    It's almost like wpmu is processing the content of the post and somehow not allowing the jquery to reference the trigger

  4. tim.moore
    Member
    Posted 14 years ago #

    Do you have a URL with an example of this so we can take a look at it?

  5. anointed
    Member
    Posted 14 years ago #

    non-working example:
    http://shawngaffney.anointed.net/information/

    on the bottom of the page 'some title' should show, the paragraph below should not.

    working example:
    http://shawngaffney.anointed.net/sermons/

    middle of the page below the picture of the pastors, 'click here to view....'

    btw
    Thanks so much for your time with this. and please ignore the mess, it's my sandbox testing site, so many concepts going on in there right now, not to mention the template needs serious help still. (not a designer, so it's a work in progress)

  6. anointed
    Member
    Posted 14 years ago #

    Well I have now tried everything I can think of but still have no luck getting jquery to work within a post or page. I'm open to any ideas the experts may have.

  7. kgraeme
    Member
    Posted 14 years ago #

    The problem is your actual trigger script. You need to use the no conflict format for jquery calls. (The "$" approach.) You actually do it right in the later script that does the superfish menu.

    So this:

    <script type="text/javascript">
    jQuery(document).ready(function(){
    
    	jQuery("a.trigger").toggle(
    		function(elem){
    			jQuery(this).addClass("active");
    		},
    		function (elem) {
    			jQuery(this).removeClass("active");
    		}
    	);
    
    	jQuery('#accordion .trigger').click(function() {
    		jQuery(this).prev().slideToggle();
    		return false;
    	}).prev().hide();
    
    });
    </script>

    Should probably look something like this:

    <script type="text/javascript">
    jQuery(document).ready(function($){
    
    	$("a.trigger").toggle(
    		function(elem){
    			$(this).addClass("active");
    		},
    		function (elem) {
    			$(this).removeClass("active");
    		}
    	);
    
    	$('#accordion .trigger').click(function() {
    		$(this).prev().slideToggle();
    		return false;
    	}).prev().hide();
    
    });
    </script>
  8. anointed
    Member
    Posted 14 years ago #

    thank you for the advice. I had no idea that I was doing it wrong in that script and have made the appropriate changes.

    For some reason, it still is not functioning on the page/post pages, and only seems to work if I use it directly within a template.

    I'm open to any further ideas anyone may have.

  9. anointed
    Member
    Posted 14 years ago #

    Ok, finally figured this out thanks to constantine:

    turns out the js tries to hide the element right before the trigger. In this case it is wordpress adding in the < p > breaks even if I combined all the text together.

    By simply adding <?php remove_filter ('the_content', 'wpautop'); ?> right before 'the_content' in single.php and also page.php the problem was solved.

    I hope this answer helps someone down the road as well.

About this Topic

  • Started 14 years ago by anointed
  • Latest reply from anointed