Connections Template

I’ve put the current contents of my template files up on this page. You’ll always be able to find the latest version of my templates there.

globalvar

Looking through the Blogsome/WPµ source, I came across a Smarty function {globalvar}. “Righto,” I thought, “I’ll google that, and see what comes up.” My template file was the first thing that did. Okay, what this function does is take a Smarty variable, and make it global in the PHP scope. Used in my template, and most Blogsome ones, it sets the variable $comment to be a global one. I haven’t come up with another good use for it, but it’s nice to know.

Related Stories.

After hacking through the source, I finally figured out how to make {relatedstories} work. The trick is that it stores the date in a variable called $relatedstories.

 1    {relatedstories}
 2    {if $relatedstories}
 3      <h2>Related Stories</h2>
 4      <ul>
 5      {foreach from=$relatedstories key=key item=story}
 6        <li> <a href="{get_permalink id=$story->ID}" >
 7            {$story->post_title}</a>
 8        </li>
 9      {/foreach}
10      </ul>
11    {/if}

I’ve got it set up in my sidebar at the moment. It’s smart enough to figure out when it’s not a single post page, and won’t show then, so you don’t need any fancy extra Smarty Tags to only show in single post view. Oh, and it also sets the variable $relatedstoriesWords, so it’s possible to do something like: <h2 title="{$relatedstoriesWords}">Related Stories</h2> and when you hover over the title, it tells you the words it’s looking for. I’m still working on how to truncate the title. {$story->post_title|truncate} fails dismally. Quite annoying.

Arguments that don't work

I’ve come across several Smarty Tags that call WordPress functions that have listed arguments that don’t work. I didn’t bother too much about it - usually I can live with it. Then, I realised how I solved one instance of this happening: the Recent Comments plugin.

I downloaded the source to this, and looked at it. Besides there being some spelling mistakes, it had argument names which differed from the documented ones. No wonder it was failing when I tried to change the number of comments, and the comment length! So, looking at the code helped me solve the problem. Maybe it will with the other issues I have come across: most notably {previous_post_link} and {next_post_link}, and {edit_post_link}.

I’ll start with the {edit_post_link}. The codex says the argument I want to change is called text, but the source reveals it to be link. Changing this enabled me to change the text that is presented to whatever I want. The same goes for {edit_comment_link}.

I was originally using the tags {previous_post} and {next_post}, but was unable to change the previous post: next post: text that appeared. Changing the name of the argument from text to previous and next (as applicable) fixed this. Similarly, since {previous_post} and her sister are deprecated, {previous_post_link} has arguments that differ from those detailed in the Codex. The arguments it (and {next_post_link}) can handle are:
  • format - defaults to &laquo; %link. You need to have the %link where you want the URL to appear! You can add more stuff that you want to appear but not be part of the link itself.
  • link - defaults to %title. Add other text that you want to add into the link area.
  • in_same_cat
  • excluded_categories

Depending upon if you want an image clickable, you can either insert the code into the format or link argument. Just for fun, I included my favicon in the non-link section of the link text (ie, the format argument). I’ll leave it there for a while, just to prove it can be done…in the meantime, I’m going to fix the Codex.

Choosy Post Display

Someone on the Blogsome Forums wanted to be able to have the main page only display posts from a certain category. To do this, edit your post.html file, and add the following right at the start: {capture name=in_cat}{in_category category='1'}{/capture} {if $smarty.server.REQUEST_URI != '/' || $smarty.capture.in_cat == '1'} Then, right at the end, add {/if} If you are wanting a category other than the default one to be the only one shown on your front page, look up the category id in the dash, and replace the ‘1’ in the first line with this number. This could easily be extended to get a sticky-post setup. I’ll do that later tonight, when I’m drunk. Just to make it a challenge. Happy 30th Sam.

Connections Edits

Yay! I’ve fixed the Search function so it works. I hadn’t changed the action tag to read "{$Smarty.server.PHP_SELF}", which it needed to be in order to work. What I want to do now is make the previous and next page links not have the words previous post, and next post, just the title and the double-arrows. Also, the Latest Posts does not seem to be updating…I’ll try to fix this.

Popular Post Bug

I have the following code to display my most popular posts in the sidebar: ` {popularposts} {if $pposts != ‘’}   <h2>Most Popular Posts</h2>     <ul>     {foreach from=$pposts key=key item=hits}       <li>{$hits.title truncate:25:”…”}</a>: {$key}</nobr></li>     {/foreach}     </ul> {/if} ` However, it doesn’t work: the links are all to the least recent of my recent posts the last post on the page. I’ll have to fix this. (Note: a fix is in the comments).

$smarty.get.*

I don’t know how I never found this before… You can use {$smarty.get.<var>} to get the URL variable you want. For instance, you can use the following ones in WordPress MultiUser:

  • year
  • monthnum
  • day
  • name
  • paged/page
  • category_name
  • wpblog

Unfortunately, these variables don’t seem to be set with Pages, rather than Posts. However, this has given me some tips as to how to fix the .htaccess RewriteRule problems causing Blogsome not to display subsequent pages of monthly archives. Possibly something to do with the fact it uses page, rather than paged, and that for some reason it parses the word page as the name of the post. This looks like not a .htaccess bug at all, now that I think of it.

Smarty: Insert / Comment Tags

Smarty This may have some use: {insert}. I noticed it when backing up my templates tonight… • Also, I’d like to make buttons that act like the quicktags in the Blogsome backend for commenting: so it inserts the relevant tags in. Will require some JavaScript, I assume…

Category Pages

I want to add some functionality to my site. I used to just have a few categories, but as I wrote more, I wanted to sub-categorize a bit. So now, I have a handful of parent categories, and under (most of) these I have one or more child categories. In some cases this goes three or four deep. But, so the category list isn’t too long, I only show the parent categories in the sidebar. What I want is that when a category page is shown, at the top is a list of the child categories. I can (relatively) easily find out if I am viewing a category page: {if $smarty.server.REQUEST_URI|truncate:10::1 == '/category/'} I can also quite easily find the name of the category, but not the id. This is what I need for creating the category list. I’ve just had a thought. Checks something. The following displays the info that is sent to the server: {foreach from=$smarty.server.argv item=var} {$var} {/foreach} I was hoping it would give the category id. But it doesn’t, only the name. Back to the drawing board.