Support » Plugins » Hacks » Using an Array as a post title

  • realmattbender


    I am looking to store multiple elements as an array, and then call them based on one of the element’s size. For example-
    We have a page titled:
    Pet Assure | Daily Pet Calendar – Smoke (Bloodhound) Jun 23
    I would like to store
    “Pet Assure | ” as value 0
    “Daily ” as value 1
    “Pet Calendar- ” as value 2
    “<?php¬†single_post_title();¬†?> ” or “Smoke (Bloodhound)” as value 3
    “<?php the_time(‘M j’) ?>” as value 4.

    I would then like to dynamically set the page title.
    If “Value 3” is less than or equal to 21, display the full string: “0” “1” “2” “3” “4”
    Val 3=22-34 display “1” “2” “3” “4”
    Val 3=35-40 display “2” “3” “4”
    Val 3=41+ display “3” “4”

    We have a blog with approx 1350 post with page title exceeding 100+ characters, and we are trying to remedy this.

    Any help able to be provided would be awesome!

Viewing 1 replies (of 1 total)
  • RossMitchell


    I think this will work. It will require quite a bit of effort and various skills.

    Extract from your database all of the Titles, keep the Article IDs with it too, maybe this is via a .CSV file, maye it is the result of an SQL query and you save the results.
    You then have a text file, one line per article, in the form ID number, TITLE

    Someone goes through this file reading each line, and places a character not otherwise used at the breakpoints, say TILDE ~
    Place it at the various breakpoints in the title.
    As an alternative you could use other characters to tag various title components, just be careful that they are not otherwise used.

    Reload your database titles with this edited list.

    You should be using a child theme, if not then do this now.

    In the functions.php file of your child theme, add a function which when given one of your encoded titles, breaks it into components and assembles a title of suitable length. Use the function hook mechanism so that this function gets to process the article title. Of course this function also removes these tag characters.

Viewing 1 replies (of 1 total)
  • The topic ‘Using an Array as a post title’ is closed to new replies.