Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-01-22 06:42:11

Hans
Member
From: Everywhere
Registered: 2004-03-07
Posts: 99
Website

... grab the id of the article image from within a form?

I’ve waded through all the global variable posts and articles. I know I can get article_image from $thisarticle, but I don’t want the whole tag — I only want the numerical id of the article image to use as a variable in a TXP form.

using article_image and exploding it, etc. would probably be long and hard for me, a non-PHP guru.


Lumilux – A Photoblog

Offline

#2 2006-01-22 11:50:44

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: ... grab the id of the article image from within a form?

Try this:

<txp:php>
echo $thisarticle['article_image'];
</txp:php>

As a further example employing this hackery way of extracting global variables from the Textpattern core code, I’ve added a short write-up to my site on a related issue, How to define a &raquo;Sorry, no search matches&laquo; message.

HTH,

Robert

Last edited by wet (2006-01-22 12:00:13)

Offline

#3 2006-01-22 13:40:37

Hans
Member
From: Everywhere
Registered: 2004-03-07
Posts: 99
Website

Re: ... grab the id of the article image from within a form?

…but I thought $thisarticle[‘article_image’] is the same as the output of the <txp:article_image /> tag…

Well, here’s what I’m trying right now, but it ain’t working:

<txp:php>
global $thisarticle;
$id = $thisarticle['article_image'];
$img = 'http://lumilux.org/images/'.$id.'.jpg';
$h = imagesy($img);
if($h==389) {
echo 'position: absolute; top: 422px; margin-top: 32px;';
}
</txp:php>

Last edited by Hans (2006-01-22 13:48:19)


Lumilux – A Photoblog

Offline

#4 2006-01-22 13:47:04

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: ... grab the id of the article image from within a form?

> Hans wrote:

…but I thought $thisarticle[‘article_image’] is the same as the output of the <txp:article_image /> tag…

Depends. It returns whatever you enter as an article’s image, either a numerical id or a literal URL. But: If $thisarticle['article_image'] is numeric, txp:article_image resolves it for you and thus returns an article image’s URL anyway.

That given:

  1. Put only image ids into article properties. Most image handling plugins depend on that being so, anyway.
  2. Enjoy.

Offline

#5 2006-01-22 13:51:53

Hans
Member
From: Everywhere
Registered: 2004-03-07
Posts: 99
Website

Re: ... grab the id of the article image from within a form?

All my article_images are defined by their image ids; they’re numerical.

How would txp:article_image help me? As I said in my original post, it’s of no use because it spits out the whole <img /> tag.


Lumilux – A Photoblog

Offline

#6 2006-01-22 13:57:33

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: ... grab the id of the article image from within a form?

> Hans wrote:

How would txp:article_image help me?

Not at all. I used it to illustrate as you cited the (not suitable) output of the tag in your original post.

I have tested the snippet I posted in my very first reply on a 4.0.3 installation of textpattern in which it simply returns the contents of the corresponding article’s image id.

What is the resulting contents of 'http://lumilux.org/images/'.$id.'.jpg'; from your sample code actually?

Last edited by wet (2006-01-22 13:57:50)

Offline

#7 2006-01-22 14:05:13

Hans
Member
From: Everywhere
Registered: 2004-03-07
Posts: 99
Website

Re: ... grab the id of the article image from within a form?

It appears that $thisarticle[‘article_image’] isn’t working, since it just gives me http://lumilux.org/images/.jpg.

I changed the $id to $imgid just in case there was some variable name conflict, but it wasn’t the case…

It might be worth mentioning that I’m trying to use this variable in a form besides the actual article form—on the same page, just not in the article form.

Even this doesn’t work:

<txp:if_custom_field name="wide" val="yes">position: absolute; top: 422px; margin-top: 32px;</txp:if_custom_field>

Last edited by Hans (2006-01-22 14:18:54)


Lumilux – A Photoblog

Offline

#8 2006-01-22 15:17:49

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: ... grab the id of the article image from within a form?

> Hans wrote:

It might be worth mentioning that I’m trying to use this variable in a form besides the actual article form-

So you use txp:output_form to echo the image id? That won’t work. txp:article form="foo" with foo being a form containing the php snippet will work.

Offline

#9 2006-01-22 15:42:46

Hans
Member
From: Everywhere
Registered: 2004-03-07
Posts: 99
Website

Re: ... grab the id of the article image from within a form?

So basically I need to create an article form with the PHP in it (without really using an article) for the variable to work?

Let me try that. OK, I turned my footer into an article form. The PHP still won’t work.

However, if I manually say that the image is wider than usual (in a custom field), the following works:

<txp:if_custom_field name="wide" val="yes">position: absolute; top: 422px; margin-top: 32px;</txp:if_custom_field>

Last edited by Hans (2006-01-22 15:49:25)


Lumilux – A Photoblog

Offline

#10 2006-01-23 21:57:37

Hans
Member
From: Everywhere
Registered: 2004-03-07
Posts: 99
Website

Re: ... grab the id of the article image from within a form?

OK, I’ve figured out how to get the image id the hard way… by grabbing it from the output of <txp:article_image />. Well, at least that’s what I’m trying to do with the following; but for some reason the result is always empty!

<txp:php>
$aitag = "<txp:article_image />";
list($img, $h, $w, $t) = sscanf($aitag, '<img src="%s" height="%d" width="%d" alt="%s"    />');
if($h==389) {
echo 'position:absolute; top:422px; margin-top:0px;z-index:100;';
}
</txp:php>

Lumilux – A Photoblog

Offline

#11 2006-01-24 00:55:31

Hans
Member
From: Everywhere
Registered: 2004-03-07
Posts: 99
Website

Re: ... grab the id of the article image from within a form?

YES! I was actually, um, using imagesy() totally wrong, as shown by this page. The following code works beautifully.
(Yes, I used article_id instead, since my article_ids are the same as my article_image ids.)

<txp:php>
$imgid = article_id(array());
$imgurl = 'http://lumilux.org/images/'.$imgid.'.jpg';
$img = @imagecreatefromjpeg($imgurl);
if ($img) {
 $h = imagesy($img);
	if($h==389) {
		echo 'position:absolute;top:422px;margin-top:0;z-index:100;';
	}
 ImageDestroy($img);
}
</txp:php>

Lumilux – A Photoblog

Offline

#12 2006-01-24 01:04:16

hakjoon
Member
From: Arlington, VA
Registered: 2004-07-29
Posts: 1,634
Website

Re: ... grab the id of the article image from within a form?

Have you looked the image tags in upm_img_popper? You could do <txp:upm_article_image form="myform" /> and then in myform just use <txp:upm_img_id /> to spit back the id. Although I don’t completely understand what you want to do.


Shoving is the answer – pusher robot

Offline

Board footer

Powered by FluxBB