Non-attribution

I’ve commented before on how people use my template conversion, and remove the attribution to myself, and more importantly to Patricia, the original person who did all of the work on the template for vanilla wordpress. What is quite funny is that they remove the tags that attribute me, but usually leave in the AdSense code. Which means anyone clicking on ads on their blog will be doing me a favour. Not that I’ve ever got anything from AdSense. I can’t even log in, since there is a clash between my original AdSense login and my new hosted domain google account. Which they haven’t fixed, last time I checked. Perhaps I should write into the code that attribution needs to be left in. I must check…

Make IE/Blogsome URLs work better

Internet Explorer has some interesting foibles. And by interesting, I mean annoying. For instance, if I’ve visited a page on my site, such as: http://schinckel.net/wp-admin/ Internet Explorer seems to remember it as http://schinckel.net/wp-admin Notice that the trailing slash is missing. Blogsome will report that “Page Does Not Exist”, or if it looks like a Post page, “No posts made”. With access to the HTTP server, this would be easy to fix (just create a rule in the relevant place that allows for URLs of this form), but on Blogsome this is a bit harder. You need to be able to check the last character of the URL string, and if it isn’t a /, append one. This should work fairly well in all cases, since every reader visible URL ends in a /. So how to do this? Getting the URL is easy: {$smarty.server.REQUEST_URI}. However, getting the last character is a bit more difficult. Or so it appears. But Smarty allows for accessing strings as an array, so {$smarty.server.REQUEST_URI[0]} will get the first character. To get the last is a therefore possible. {$smarty.server.REQUEST_URI[-1]} fails, so I’ll need to get the length of the string. {$smarty.server.REQUEST_URI[$smarty.server.REQUEST_URI|count_characters ]} also fails, but {$smarty.server.REQUEST_URI[smarty.server.REQUEST_URI|count_characters ]} works. Now, we just need to test if this value is “/”, and if it isn’t, then reload the page with that added. Which I can’t seem to figure out how to do with Smarty… • Of course, doing the same with JavaScript is a piece of cake: if (document.URL[document.URL.length-1] != "/")     document.location = document.URL + '/'

Custom Error Pages

Thanks to some simple Smarty capture and comparisons, it’s possible to have custom error pages in Blogsome. Read about how to do it at : About How to customize a 404 error page in your free Wordpress blog November 2006 - WebTips See it in action at /404/

Category Dreaming...

…on such a Winter’s Day.

California Dreamin’ • “Room Service” • José Feliciano ★★★

Okay, that’s just a silly lead-in to what I’m going to post about. For some time, I’ve been trying to get Category Pages to handle a bit nicer in Blogsome. I needed to be able to get a Category ID from a Category name, and I hadn’t figured out how to. I’d basically given up. Then I found my new best friend, {get_cat_ID cat_name='Cat_Name'}. He allows me to do this. And much easier than I thought it would be, too.

1     {if $smarty.server.REQUEST_URI|truncate:10:'':1 == '/category/'}
2         {capture name=cat}
3             {single_cat_title}
4         {/capture}     
5         {capture name=catID}
6             {get_cat_ID cat_name=$smarty.capture.cat}
7         {/capture}
8     {/if}

Now, how do we use this to get child categories?

1     {list_cats optionall='0' list='false' child_of='$smarty.capture.catID'}

This appears to not work, as it continues to get all of the categories. I think there is an issue with child_of, at least on Blogsome.

1     {get_category_children id=$smarty.capture.catID}

Only generates the IDs of the child categories. Useful, but not excellent for my uses. However, there exists also a function called {wp_list_cats}, which allows for arguments in the for &arg=value.

1     {wp_list_cats args=&child_of=`$smarty.capture.catID`”} 

Notably, you must use double quotes when trying to embed a variable inside an argument. Final code (not counting CSS, that’s up to you - or look in my StyleSheet):

 1 {if $smarty.server.REQUEST_URI|truncate:10:'':1 == '/category/'} 
 2     {*Category Index Page*}
 3     <div class=“catNav”>
 4         {capture name=cat}{single_cat_title}{/capture}
 5         {capture name=catID}
 6             {get_cat_ID cat_name=$smarty.capture.cat}
 7         {/capture}
 8         Currently browsing 
 9         {get_category_parents category="`$smarty.capture.catID`" link="1" separator="&raquo;"}, which has sub-categories 
10         <ul class=“inlineCatList”>
11             {wp_list_cats args=&&list=0&children=0&child_of=`$smarty.capture.catID`”}
12         </ul>
13     </div>
14 {/if}

And, thanks to minimalnet, since because of the post in the forums: How can i show the Dashboard Blog Stats in my blog?, I began scouring the source code again.

Summer The First TimeBobby GoldsboroRoom Service

Block Comments after X days

Eugenia (who used to write for BeOS sites, back in the day) wanted to know how to stop comments from being posted on posts that are over 10 days. I’ll generalize this to X days, just for completeness. You need to get the date of the post, and the current date. I’ll get the post date, and put it into a variable: {capture name=pdate}{the_time d=“U”}{/capture} {$smarty.now} Now, you need to subtract the two of these: {$smarty.now - $smarty.capture.pdate} Note that it will be somewhat incorrect, as {$smarty.now} is server time, whilst {the_time} is WordPress time. Now, this gives us a value in seconds, so we want to work out how long X days is in seconds. This, again is simple: X days = 60*60*24 seconds X days = 86400 seconds {capture name=diff}{$smarty.now-$smarty.capture.pdate}{/capture} Now, the actual code to display the error message is: {if $smarty.capture.diff/86400 > 10}     I'm sorry, Comments are now closed. {/if} But, we want this to appear instead of a comment form, so you’ll need to find the line that looks a bit like: {if 'open' == $post->comment_status} And replace it with: {if $smarty.capture.diff/86400 > 10}     I'm sorry, Comments are now closed. {elseif 'open' == $post->comment_status} Naturally, replace 10 with however many days of comments you wish to allow.

Electrocution (Hydro Mix)Decoder RingSomersault ★★½

Getting Child Categories

I’ve been racking my brain thinking about how to get child categories of a specific category. And I think I’ve just figured it out. Examine all of the other categories in a complete list, and grab all of them that have the current page’s URL at the start. The next word will be the sub-category . Of course, knowing how to split stuff in Smarty is a bit difficult. I was thinking in JavaScript…

It Don’t HurtSheryl CrowThe Globe Sessions ★★½

Members Only Blog

I had a thought on the way home: how to make a blog that only registered users can see. Basically, it will use a similar method how the template decides whether or not to show the captcha. From the Blogsome site, and my comments.html:

1       {if $captcha_image_URL != "" && $blog_user_level == -1}
2         {$captcha_hidden_form_fields}
3         <p>
4             <input type="text" name="captcha_value_typed"><img src="{$captcha_image_URL}" align="center"><br>
5             Anti-spam measure: please retype the above text into the box provided.
6         </p>
7       {/if}

So, we should be able to use the following code:

1     {if $blog_user_level == -1}
2         This blog is members only.  Please {wp_loginout}.
3     {else}
4         All content goes here.
5     {/if}

Of course, you’ll want do disable just anyone from registering, else it defeats the purpose of it… I’ll try to test this on my test blog over the next couple of days.

Make your Blogsome Blog Private

It’s possible to create a private post within Blogsome, but not a whole private blog. However, if you turn off allowing registration, you can make your blog private. In your Main Page template, find the line that has {$content} on it. Just before the line, insert the following lines: {capture name=loginout}{wp_loginout}{/capture} {if $smarty.capture.loginout|strip_tags:'0' == "Logout"} And then, after it, insert the following lines: {else}     <p>This Blog is Private. Please {wp_loginout} before continuing</p> {/if} This will then prevent non logged-in users from viewing your posts.

Highlight Search Terms

I’m trying to get Search terms from within the Blog’s search engine to be highlighted. I’ve got the following code:

1     {if $smarty.request.s == ""}
2         {$content}
3     {else}
4         {assign var=hilite value="<span class='hilite'>"|cat:$smarty.request.s|cat:"</span>"}
5         {$content|replace:$smarty.request.s:$hilite}
6     {/if}

This works fine, as long as the search term isn’t in a URL, or something like that. In that case, it breaks the URL. To get around this, I need to only replace if it’s not inside an HTML tag. regex_replace to the rescue. This took me about 30 minutes to eventually figure out, a tipoff to wfinn at yakasha dot net, and the comment he made on the PHP documentation pages:

1     {if $smarty.request.s == ""}
2         {$content}
3     {else}
4         {assign var=hilite value="<span class='hilite'>"|cat:$smarty.request.s|cat:"</span>"}
5         {assign var=regex value="/(?![^< ]*?>)"|cat:$smarty.request.s|cat:"/"}
6         {$content|regex_replace:$regex:$hilite}
7     {/if}

Obviously, you’ll need to have some sort of CSS styling for the search term.

1     .hilite {color:red; border:1px dashed; padding:0 3px; 0 3px;}

Bug in {wp_title}

This is actually a bug I’ve come across in other contexts, but the tag {wp_title} has a bit of a bug. When a category is selected, it returns a reasonable value (the title of the category). Ditto for an individual post. However, with a date archive, the value is not as expected. A daily archive is fine, although I don’t like the format: Captain Obvious » 2005 » October » 16.10.05 It doesn’t seem to be possible to alter this, other than the separator: {wp_title sep="•"} But it gets worse. If a monthly or yearly archive is chosen, the date of the last post to be displayed will also be presented: Captain Obvious » 2005 » 13.08.05 Note that this is the last post on the page, not the first post. IIRC, normal Wordpress would be the other way around. Instead, what I use is:

 1     <title>
 2         {bloginfo show="name"}
 3         {single_post_title prefix=" &raquo; "}
 4         {single_cat_title prefix=" &raquo; Category: "}
 5         {if $smarty.request.name == ""}
 6             {single_month_title prefix=" &raquo; "}
 7         {/if}
 8         {if $smarty.request.s != ""}
 9              &raquo; Search: {$smarty.request.s}
10         {/if}
11     </title>

This has the bonus of also noting when it’s a Search.