root/trunk/EntrySetBasename/readme.markdown

Revision 1090, 5.7 kB (checked in by bsmith, 15 months ago)

typo

Line 
1# EntrySetBasename
2
3## ABSTRACT
4
5This is a utility plugin to assist in setting entry basenames to the value of the dirified entry title.
6
7<em style="color:red"><strong>WARNING:</strong> Using the `<$mt:EntrySetBasename$>` tag will cause Entry basenames to be changed in the blogs database. This plugin and the tag is provides is meant to be used once to set basenames and then it should be removed.</em>
8
9
10## HISTORY
11
12In MT4.2 the dirify function was updated to not remove dashes. If the phrase to dirify was:
13
14    Foo-Bar Baz
15
16Dirify in MT4.1 would produce:
17
18    foobar_baz
19
20Dirify in MT4.2 would produce:
21
22    foo-bar_baz
23
24
25This change to the dirify function has affected urls of blogs which use a dirified entry title in the archive map, such as in this example:
26
27    archives/<$mt:EntryTitle dirify="1"$>.html
28
29Though MT tags can be used to create archive mappings, because there is a specific tag for doing this, it is kind of a hack... albeit a popular one!
30
31This was most-commonly used to overcome the 100 character default limit (which can be increased to 250 in Entry Settings) but could have also been lack of knowledge of how the `<$mt:EntryBasename$>` works.
32
33Though MT tags can be used to create archive mappings, the entry basename was meant to be used when creating urls to the entry because the basename is created to be unique among all entries and never changes once the entry is published. A dirified entry title will change if the title of the entry changes or... if the dirify function changes. So ideally basename should be used when creating archive mappings.
34
35- how entry basename is created when creating an entry
36
37There are a few limitations with basename, but since :
38
39* it must be 250 characters or less
40* it is limited to letters, numbers, dashes, and underscores
41
42
43## SOLUTION
44
45The basic solution is to populate past basenames with previously dirified entry titles.
46
47By hand this could be difficult--but thanks to Mr. Brad Choate--there is a super simple utility plugin to help!
48
49<em style="color:red"><strong>WARNING:</strong> But please be warned, using the `<$mt:EntrySetBasename$>` tag will cause Entry basenames to be changed in the blogs database. This plugin and the tag is provides is meant to be used once to set basenames and then it should be removed.</em>
50
511. As always when performing massive changes to data, create a backup in the case that you need to revert.
522. Install EntrySetBasename plugin.
53
54        $MT_HOME/
55            plugins/
56                EntrySetBasename
57
583. Set basename length to 250 (or desired length) in Preferences > Entry Settings
594. Update archive mappings to use basename. Thus this mapping:
60
61        archives/<$mt:EntryTitle dirify="1"$>.html
62
63    would become:
64
65        archives/<$mt:EntryBasename$>.html
66
675. Create an index template named "Dirify" and paste the following code:
68
69        <ul>
70            <$mt:setvar name="first_entry_id_in_4_2" value="12345"$>
71            <mt:Entries lastn="99999">
72                <$mt:EntryID setvar="entry_id"$>
73                <mt:if name="entry_id" lt="$first_entry_id_in_4_2">
74                    <$mt:EntryTitle dirify="1" setvar="new_dirified_title"$>
75                    <$mt:EntryTitle regex_replace="/-/g","" dirify="1" setvar="old_dirified_title"$>
76                    <mt:if name="new_dirified_title" ne="$old_dirified_title">
77                        <li>
78                            <$mt:EntrySetBasename value="$old_dirified_title" test="1"$>
79                        </li>
80                    </mt:if>
81                </mt:if>
82            </mt:Entries>
83        </ul>
84   
85    This code will output a page listing the entries in your blog if the entry id is less than the id of the first entry created in MT4.2 and if the title dirified previous to MT4.2 and dirified in MT4.2 are not the same. For each matching entry the basename will be set to the value specified on the mt:EntrySetBasename tag, if the test attribute is not set to 1.
86
876. If you have created posts since upgrading to MT4.2, find the id of the first post created in MT4.2 and enter the id number as the value for the variable "first_entry_id_in_4_2".
88
897. If you have more than 99999 entries, update the lastn value of the `<$mt:Entries$>` loop to be higher than the number of entries you have in your blog.
90
918. Save the "Dirify" index template with the code above and modifications in the last two steps and publish it. Because the EntrySetBasename tag has a test attribute set to 1, no basenames will be rewritten.
92
939. Review the published output from the Dirify index template to review the changes that will be made. They will look similar to this:
94
95    * Entry #1921, 'NY-Times Shocker' basename set to 'nytimes_shocker'
96   
97    If you'd like to have more testing data (and a link to directly edit the entry) add these lines _before_ the `<$mt:EntrySetBasename$>` tag inside the HTML list item (placing after the tag will effect output of the `<$mt:EntryBasename$>` tag):
98   
99        EntryBasename: <$mt:EntryBasename$><br />
100        EntryTitle: <$mt:EntryTitle$><br />
101        new_dirified_title: <$mt:Var name="new_dirified_title"$><br />
102        old_dirified_title: <$mt:Var name="old_dirified_title"$><br />
103        <a href="<$mt:AdminScript$>?__mode=view&amp;_type=entry&amp;id=<$mt:EntryID$>">Edit Entry</a><br />
104
10510. Once you are ready to set all the basenames to the pre-MT4.2 dirified title, remove the "test" argument from the mt:EntrySetBasename tag and republish the Dirify index template. So that
106
107        <$mt:EntrySetBasename value="$old_dirified_title" test="1"$>
108   
109    becomes:
110   
111        <$mt:EntrySetBasename value="$old_dirified_title"$>
112
11311. Uninstall the plugin and delete the Dirify index template.
114
11512. Republish your Blog.
116
117## Versions
118
119* Version 1.0 - Initial Release - Tag code by Brad Choate. Documented and tested by Beau Smith.
Note: See TracBrowser for help on using the browser.