Wordpress Themes - WP Forum at BFA
Click Here To DONATE! Support the theme development, get more attention and additional benefits based on your donation level. Your forum name will be highlighted.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Montezuma Theme »

Split Headlines on punctuation (code update)


Build custom WP THEMES, without
coding.
Click here for THEMEFRAME

From the author of Atahualpa, the #1 most
downloaded (700,000+) theme @ wordpress.org
  #1  
Old Nov 21, 2012, 02:38 PM
troyp
 
10 posts · Mar 2011
I wanted to split the headlines on a few punctuation characters I use on my site for headers. To do that I updated the SPLIT HEADERS section of includes/get_javascript.php

Now the code will split around a hypen, vertical bar, colon, or else default back to spaces.

I've included my initials in comments around my changes. I hope this helps others.
PHP Code:
$js .= "
/*******************************
 *  SPLIT TITLES
 ******************************/
/* Split titles: 2-color titles for site-, post- and widget titles     */
$('" 
$dual_title_colors "').each( function() {
    var str = $(this).text();
    /*TRP add more tests here */
    if( str.indexOf('') > 0 ) { var space = ''; } else
    if( str.indexOf('|') > 0 ) { var space = '|'; } else
    if( str.indexOf(':') > 0 ) { var space = ':'; } else /*TRP end of tests */
    if( str.indexOf(' ') > 0 ) { var space = ' '; } 
    else { var space = ''; }
    var strArray = str.split(space),
    fullLength = strArray.length,
    halfLength = Math.ceil( fullLength / 2 ),
    restLength = fullLength - halfLength,
    newstr = '<span class=\"firstpart\">';
    for( var i = 0; i < halfLength; i++ ) {
        newstr += strArray[i] + space;
    }
    newstr += '</span>';/*TRP don't add space here */
    for( var i = halfLength; i < fullLength; i++ ) {
        newstr += strArray[i] + ((i<fullLength-1)?space:'');/*TRP only add delimiter if not the last segment */
    }
    $(this).html( newstr );
});
"

  #2  
Old Nov 23, 2012, 01:02 PM
RobertO
 
2 posts · Nov 2012
This worked perfectly. Thank you for sharing this.
  #3  
Old Nov 24, 2012, 07:21 PM
jerryc
 
367 posts · Oct 2012
Florida
It almost worked for me. I want ".org" to be the second color, but the period is still the first color. I imagine it won't take much to edit the code to do that, but I couldn't figure it out.

Another question. Why is this even done with Javascript at all; can't it just be done with CSS?

Thanks for your help on this.
  #4  
Old Sep 23, 2014, 09:52 AM
drf
 
2 posts · Sep 2014
An invisible split character would be nice. For example the Unicode Character Zero-width_non-joiner.

Here the code:

Code:
$('" . $dual_title_colors . "').each( function() {
        var str = $(this).text();
        if( str.indexOf(' ') > 0 ) { var space = ' '; }
        else if( str.indexOf('\u200C') > 0 ) { var space = '\u200C'; }
        else { var space = ''; }
Would you be so kind and add something like this to the next release?

Thanks

Last edited by lmilesw; Sep 25, 2014 at 12:33 PM.
  #5  
Old Sep 25, 2014, 08:27 AM
drf
 
2 posts · Sep 2014
To gain more control over the splitting it would be better to check for \u200C first and then for space:

Code:
$('" . $dual_title_colors . "').each( function() {
        var str = $(this).text();
        if( str.indexOf('\u200C') > 0 ) { var space = '\u200C'; }
        else if( str.indexOf(' ') > 0 ) { var space = ' '; }
        else { var space = ''; }

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
No spaces after punctuation studentofstone Atahualpa 3 Wordpress theme 6 Nov 22, 2011 04:38 PM
SPACES REMOVED after punctuation in 3.6.7 avantlit New Versions, & Updating 8 Sep 16, 2011 05:34 PM
Spaces removed after punctuation mlanger Atahualpa 3 Wordpress theme 2 Jul 30, 2011 04:30 AM
[SOLVED] Lost Google Analytics code with last update sjolyjuly New Versions, & Updating 4 May 10, 2011 08:28 AM
[SOLVED] Keep post headlines, remove page headlines verymarie Center area post/pages 1 Mar 17, 2011 12:14 PM


All times are GMT -6. The time now is 09:03 AM.


Powered by vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.