Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-05-16 18:11:14

stevie
New Member
Registered: 2006-05-16
Posts: 7

include an external file

I have a 3 column site that I am trying to configure.

The first column is the latest article list (nothing unique or difficult here)
The center is for the main article list and articles (again nothing here)

The issue is the right column. Above any advertising I wish to display a block of text and urls related to the article being displayed (not in the article list).

Since there is such a tiny size limit on custom fields I can’t figure out the best approach. I thought I could just create a small html file for each article and include it via a php include but I am not sure how to accomplish this. Any ideas or alternate solutions would be most appreciated…

Thanks,
Stevie

Offline

#2 2006-05-16 19:27:50

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: include an external file

You should be able to do this with Textpattern, if I understand you correctly. When the user is on a certain article (posted to xx category), a specific set of links will be displayed. Why not have something like this:

<code>
[main column article]

[right column]
<txp:related_articles limit=“4” />
<txp:if_category name=“something”>
<txp:linklist category=“something” />
<txp:else />
[normal stuff]
</txp:if_category>
<txp:if_category name=“another”><txp:linklist category=“something” /></txp:if_category>
</code>

Use if_category to output a linklist for articles posted to the same category.

If you do want to include a file with PHP, use the following:
<code>
<txp:php>
include(“myfile.phphtml”);
</txp:php>
</code>

You may need to use your server’s document path (ex: /home/you/httpdocs/myfile.html) too. You could use if_category to include the appropriate file, or a custom field for certain ads (if_custom_field value=“1” include this file)

Oh, for ads, you might want to check out the brand new, smd_random_banner plugin too.

Last edited by deldindesign (2006-05-16 19:30:42)

Offline

#3 2006-05-16 22:52:14

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: include an external file

FAQ.


Alex

Offline

#4 2006-05-16 23:22:17

stevie
New Member
Registered: 2006-05-16
Posts: 7

Re: include an external file

I had looked at the FAQ but I didn’t want to create a form for each article… That could be thousands…

I like the idea of using a php include to include the article’s media.html file.

What would the code look like to include a file based on a path in a custom field? (ie. include( custom_field value=3.“media.html”)

Each article has a media path like this: /vhost/mysite/httpdocs/media/year/myarticle/myfile.html)

Offline

#5 2006-05-17 00:30:56

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: include an external file

Are you really sure you’re going to have completely different links for each article? It’s going to be awful to maintain multiple external files (from my experience). I really think the category idea is much easier to keep up. Regardless, you’ll end up using forms, if_category,and/or if_custom_field alot.

First, bookmark the Textbook.

Let’s pretend this is your default page template:

<code>
<html>
<head>
<title><txp:page_title /></title>
</head>
<body>
<div id=“content”>
<txp:article />
</div><!—//content—>
<div id=“links”>
<txp:output_form form=“link_mng” />
</div><!—//links—>
</body>
</html>
</code>

Form: link_mng

<code>
<txp:if_custom_field name=“article-links” val=“apples”>
<txp:php>
include(“/vhost/mysite/httpdocs/media/year/apples-article/apples.html”);
</txp:php>
</txp:if_custom_field>
[repeat for other fields]
</code>

OR

If you posted your article to the “apples” category, use:

<code>
<txp:if_category name=“apples’>
<txp:php>include(“apples.html”);</txp:php>
</txp:if_category>

[repeat for other fields]
</code>

I’m not sure if the above is what you want. Will more than one article be published to the same category? If so, include the same file (or linklist, if they’re just links). Again, it’ll be much easier in the end to use linklists. Everything will be stored in the database, so the site will be easier to back up too.

Last edited by deldindesign (2006-05-17 00:32:10)

Offline

#6 2006-05-17 01:02:11

stevie
New Member
Registered: 2006-05-16
Posts: 7

Re: include an external file

Actually they are links to .mp3 and .mov files that are specific to each article. No article will have the same links, these “media web part” html files will be entirely independant of another and once they are published, they will rarely need to be edited so this is not an issue…

All I need to do to get this to work from a form “rightside” is to find the correct syntax for something like this:

include( < txp:custom_field name=‘mediaPath’ /> );

The custom field “mediaPath” would have “/vhost/mysite/media/ < year > / < article name > /media.html” in it…

or possibly just “< year > / < article name > /”

with something like this…

include( /vhost/mysite/media/< txp:custom_field name=‘mediaPath’ />/media.html );

Last edited by stevie (2006-05-17 01:23:45)

Offline

#7 2006-05-17 01:28:47

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: include an external file

Check your admin prefs and make sure you have PHP enabled. Then:

<txp:php>

$custom_field = custom_field(array('name' => 'media_path'));

$media_path = "/vhost/mysite/media/$custom_field/media.html";

if (file_exists($media_path))
{
	include($media_path);
}

</txp:php>

:)

Offline

#8 2006-05-17 08:06:49

stevie
New Member
Registered: 2006-05-16
Posts: 7

Re: include an external file

I tried this but the $custom_field = custom_field(array(‘name’ => ‘media_path’)); line is not returning a value…

I am certain that php is on for the page template and I am in an article where it should be working…

Any ideas?

Last edited by stevie (2006-05-17 08:10:36)

Offline

#9 2006-05-17 17:48:59

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: include an external file

Okay, so you’ve put the above in your article form?

Offline

#10 2006-05-17 20:04:45

stevie
New Member
Registered: 2006-05-16
Posts: 7

Re: include an external file

It is not in the article form itself, which I am guessing is the default form. I put it in the page template within <txp:if_individual_article> tags…

Offline

#11 2006-05-17 23:14:04

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: include an external file

Okay, it does need to be in the article form because that’s the only place you can reference custom fields from.

Offline

#12 2006-05-18 04:22:21

stevie
New Member
Registered: 2006-05-16
Posts: 7

Re: include an external file

I finally got it to work… The “Full” path resides in custom_6 here (ie. /home/httpd/…/httpdocs/media/06/media.html)

bc..
<txp:if_individual_article>

<txp:php>
$id = $GLOBALS[“id”];
if(empty($id)) echo “Nothing Here…”;

$custom_field = “custom_6”;
$res_custom = safe_rows($custom_field, “textpattern”,“id=’$id’”);

$media_path = $res_custom0[$custom_field];

if (file_exists($media_path))
{ include($media_path);
}
</txp:php>

</txp:if_individual_article>

Offline

Board footer

Powered by FluxBB