js_escape - why nothing? (4 posts)

  1. joebeauchamp
    Posted 7 years ago #

    I want to use a nice javascript "ticker" for "news" on my main site. Unfortunately, the nice looking one "ballistic" needs text in 1 line. I thought of trying to modify it with the approach of "proHTML ticker", but that looked like a LOT of work, if I could figure it out. Then I came across js_escape(). That could take care of my unknown uses of "'" in random story text - and I'm left with having to strip crlfs (somehow). Well, I can't get js_escape to do anything. I started with examples on the net -- makes no diff.

    A piece, for example, is Posted in <?php the_category(', ') ?> and I have a category with "'" in the title - so this seems like an easy confirmation -- but it doesn't work for me. I changed it to: Posted in <?php js_escape(the_category(', ')) ?>

    So, not wanting to get a PHD in wordpress-ology, I thought I'd see if someone can tell me what I'm doing wrong (or better, how to fix this and strip the crlf's in the_excerpt, too).

    Here is an example of what I need in one line for the scroller: pausecontent2[0]='News.com: Technology and business reports'

    Here is the code which does a fine job displaying what I want, but not as one line with escaped "'".

    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

    <div class="post" id="post-<?php the_ID(); ?>">

    <h2>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><h5><?php the_title(); ?></h5></h2>

    <div class="entry-content-alt">
    <?php the_excerpt(); ?>


    <p class="postmetadata">Posted in <?php the_category(', ') ?> by <?php the_author() ?> : <?php the_time('F j, Y - g:ia') ?></p>

    <?php endwhile; ?>

    <?php else : ?>

    <h2>Not Found</h2>
    <p>Sorry, but you are looking for something that isn't here.</p>

    <?php endif; ?>

    --- Any help would be appreciated! It seems that I need to spend weeks learning wordpress, php, javascript to make this simple change work for me -- I'd really like to avoid that...uh...help?

    Thanks a bunch!! --- Joe B.

  2. scribu
    Posted 7 years ago #

    Please paste that code into pastebin.ca so that it will be easier to read.

  3. joebeauchamp
    Posted 7 years ago #

    OK, maybe I missed something -- I replied 2 days ago after putting the code out there - and I don't see my reply and I know I posted it. Well, I don't know what the pointer is to that code now -- OK, I can't find it there, either? Hmm... parallel universe?

    So, I just did it again http://pastebin.ca/1374915 - but the code is simple, I assume I'm missing something fundamental. a piece is changing
    and it does nothing. If the text is "this freakin' thing" instead of getting "this freakin\' thing" I get the same as before I put in js_escape.

    I don't know why, I looked around and found other peoples' examples of similar. So, I figure this would be a snap for many people here to tell me what I'm doing wrong.

    -- Joe B. [Gee, I hope that THIS reply sticks..?? HA!]

  4. scribu
    Posted 7 years ago #

    Instead of


    echo js_escape(get_the_excerpt())

    get_the_excerpt() returns the content, instead of echoing it directly.

    Alternatively, you could use a filter:

    add_filter('the_excerpt', 'js_escape')

Topic Closed

This topic has been closed to new replies.

About this Topic