Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

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

Split Headlines on punctuation (code update)


  #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 = ''; }
  #6  
Old Jul 10, 2015, 07:50 AM
ralfsteck
 
55 posts · Oct 2009
Hi all,

is it possible that this doesn't work anymore in the newest Montezuma release?

I had it working perfectly in the last release, but upgraded brainlessly without saving the old version. And the last backup I have is 3 days after the update.

I copy/pasted troyp's complete function in ma .php file but still it doesn't work.

Help please.
  #7  
Old Jul 10, 2015, 08:30 AM
ralfsteck
 
55 posts · Oct 2009
The secret is: You have to save any Montezuma CSS once before it starts working again, I guess this is because of the virtual files structure of Montezuma.

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 05:12 AM.


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