Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2004-07-26 04:35:19

datafirm
Archived Plugin Author
From: Seattle, WA
Registered: 2004-07-22
Posts: 35
Website

wnp_clean_site: Clean URL plugin for small site management

After reading some threads about clean URL issues I created this plugin. My inspiration is from nimnix (Thanks). Hope someone else has a use for this.

<a href=“http://mercurycloud.com/~datafirm/txp/wnp_clean_site.txt”>wnp_clean_site</a>

Here is a description:

<p>People managing smaller websites that wish to use cleaner URLs may enjoy the use of this plugin. A few assumptions were made when creating this plugin. The idea is that each section, section/article, or section/category/article would only have one article associated with it. This is how most smaller sites would be managed.</p>

<p>Below are a few example of acceptable URLs:</p>

<p> http://domain.dom/section<br /> The following will pull up the article for the section (main nav) </p> <p> http://domain.dom/section/article<br /> The following will pull up the article for the article (sub nav) in the section (main nav) </p> <p> http://domain.dom/section/category/article<br /> The following will pull up the article within the category (sub nav) in the section (main nav) </p> <p>&nbsp;</p> <p> <strong>Instructions for use:</strong><br /> <ul> <li>Create a “section” for each main navigational element</li> <li>You must create a category named “main” and assign it to each main navigational element (section).</li> <li>Create additional articles and associate them with the appropriate “section” (main navigation). These will act as the sub nav articles</li> <li>Each article must have a “URL-only title” associated with it. This can be set while creating the article, under “Advanced Options”</li> <li>Additional articles that you wish to have under a sub nav (category) just need to be created and assigned to the appropriate “catgory”. The “category” must have the same name as its parent sub nav</li> </ul> </p> <p>Functions are provided to access the section, article url title, category (if appropriate), set the page title, and print the article to the page.</p> <p> <code>&lt;txp:wnp_clean_site /&gt;</code><br /> Place the on the top of your “page” to initialize the clean page plugin on any page you wish to make use of it. </p> <p> <code>&lt;txp:wnp_page_title /&gt;</code><br /> Used to get a page title, you can specify the separator as an attribute. </p> <p> <code>&lt;txp:wnp_article /&gt;</code><br /> Returns article for the clean URL, you can specify form as an attribute. </p> <p> <code>&lt;txp:wnp_article_title /&gt;</code><br /> Returns url_title as string. </p> <p> <code>&lt;txp:wnp_article_category1 /&gt;</code><br /> Returns category1 as string. </p> <p> <code>&lt;txp:wnp_section_name /&gt;</code><br /> Returns section as string. </p>

Last edited by datafirm (2004-07-26 07:19:09)

Offline

#2 2004-07-26 17:42:15

datafirm
Archived Plugin Author
From: Seattle, WA
Registered: 2004-07-22
Posts: 35
Website

Re: wnp_clean_site: Clean URL plugin for small site management

Addendum:

  • You must have “clean” URL mode enabled
  • You must follow rules for clean URLs (editing .htaccess and adding placeholder files)

Offline

#3 2004-07-26 18:59:03

datafirm
Archived Plugin Author
From: Seattle, WA
Registered: 2004-07-22
Posts: 35
Website

Re: wnp_clean_site: Clean URL plugin for small site management

Some additions that I may later in the week.

  • Allow attribute to wnp_clean_site that will display list of aticles if one lands on section or section/category instead of displaying an article
  • 404 type handling for mistyped section, categories articles; this would make use of the above addition but would not need the attribute set
  • Anything else??

Last edited by datafirm (2004-07-26 18:59:24)

Offline

#4 2004-08-27 21:57:53

asno
New Member
Registered: 2004-07-09
Posts: 3

Re: wnp_clean_site: Clean URL plugin for small site management

A few questions while playing with this plugin…

1. Is it possible to auto-generate clean URL tags by using link_to_next?
2. Have you added the attribute to wnp_clean_site yet? What about the 404 thing?

I’m going to have some free time this weekend, so maybe I can add a function that would generate next & previous links and add it on to your plugin. Would you like the code if I do that?

So far, good start on a nice little clean URL plugin :).

Offline

#5 2004-08-27 22:16:55

datafirm
Archived Plugin Author
From: Seattle, WA
Registered: 2004-07-22
Posts: 35
Website

Re: wnp_clean_site: Clean URL plugin for small site management

I have not added any of the mentioned functionality. I have since then modified the clean_url_plugin mostly for my events calendar system you can see on this site:
http://unfuknblvble.com/calendar/events/2004/08/.

The site is almost finished, but the home page and all flash banners are not there yet.

I think you could make those type of URLs with no problem, however, I had no need for them. It certain sections of the site I have integrated article type listing or event listing rather than “paged” based.

The latter would be even easier for me to do i think. I will try and have a look at it when I have some free time!

Thanks

let me know if you make any changes or have some questions

> asno wrote:

> A few questions while playing with this plugin…

1. Is it possible to auto-generate clean URL tags by using link_to_next?
2. Have you added the attribute to wnp_clean_site yet? What about the 404 thing?

I’m going to have some free time this weekend, so maybe I can add a function that would generate next & previous links and add it on to your plugin. Would you like the code if I do that?

So far, good start on a nice little clean URL plugin :).

Offline

#6 2004-09-08 10:01:16

asno
New Member
Registered: 2004-07-09
Posts: 3

Re: wnp_clean_site: Clean URL plugin for small site management

Here is what I’ve added…

A global variable called wnp_rootURL:

<pre> $wnp_rootURL = ‘/’ . $s . ‘/’; if (!empty($wnp_cat)) $wnp_rootURL .= $wnp_cat . ‘/’;
</pre>

At the end of function wnp_clean_site, and then these additional functions:

<pre>
function wnp_permlink($atts) { global $s, $thisarticle; global $wnp_art_title, $wnp_rootURL; $out = ‘<a href=”’ . $wnp_rootURL . $wnp_art_title . ‘”>’ . $thisarticle[‘title’] . ‘</a>’; if (is_array($atts)) extract($atts); if (!empty($wraptag)) return tag ($out,$wraptag); return $out;
}

function wnp_link_to_next($atts) { global $s; global $wnp_art_title, $wnp_rootURL, $wnp_artID; $thisone = fetch(‘Posted’,‘textpattern’,‘ID’,$wnp_artID); $thenext = getNeighbour($thisone,$s,’>’); $category = safe_field( ‘Category1’, ‘textpattern’, ‘url_title = “’.$thenext[‘url_title’].’”’); $out = ‘<a href=”/’ . $s . ‘/’ . $category . ‘/’ . $thenext[‘url_title’] . ‘”>’ . $thenext[‘Title’] . ‘</a>’; if (is_array($atts)) extract($atts); if (!empty($wraptag)) return tag ($out,$wraptag); return $out;
}

function wnp_link_to_prev($atts) { global $s; global $wnp_art_title, $wnp_rootURL, $wnp_artID; $thisone = fetch(‘Posted’,‘textpattern’,‘ID’,$wnp_artID); $thenext = getNeighbour($thisone,$s,’<’); $category = safe_field( ‘Category1’, ‘textpattern’, ‘url_title = “’.$thenext[‘url_title’].’”’); $out = ‘<a href=”/’ . $s . ‘/’ . $category . ‘/’ . $thenext[‘url_title’] . ‘”>’ . $thenext[‘Title’] . ‘</a>’; if (is_array($atts)) extract($atts); if (!empty($wraptag)) return tag ($out,$wraptag); return $out;
}
</pre>

Last edited by asno (2004-09-08 10:02:12)

Offline

#7 2004-09-09 18:33:23

asno
New Member
Registered: 2004-07-09
Posts: 3

Re: wnp_clean_site: Clean URL plugin for small site management

Here is the modified wnp_article which will do an article list if there is no ID present. This requires the addition of the following code in the “matching section/article_title” block of the wnp_clean_site function:
<pre>
//Ok, so that article title doesn’t exist, maybe we’re in a category? if(empty($wnp_artID)) { $wnp_cat = $match1; }
</pre>

And here is the modified wnp_article function. Its pretty basic, all you have to do is call doArticles and pass it a category if there is no article ID

<pre>
function wnp_article($atts) { global $wnp_artID, $wnp_cat; if (is_array($atts)) extract($atts); $form = (empty($form)) ? ‘default’ : $form; $listform = (empty($listform)) ? $form : $listform;

return (empty($wnp_artID)) ? doArticles(Array(‘c’=>$wnp_cat,‘form’=>$listform)) : doArticle(Array(‘id’=>$wnp_artID,‘form’=>$form)); } </pre>

Offline

Board footer

Powered by FluxBB