Creating Article Popups in Textpattern
Posted 19. februari 2006, 14:44 [Edited 20. februari 2006, 09:25]
Recently I wanted to open up the article body in an new window. On the page I had set up I exposed the title and the excerpt and then an link to where the article body was opened up in a new window. Below I will briefly cover how I did.
This is in the article form.
<h2><txp:title /></h2> <txp:excerpt /> <p><txp:dmn_popup_article_link width="595" height="550" /></p>
We also need to create a new form which we can call popup_article, in that form we place the html markup for the popup page, and where you want the article to be exposed place this tag <txp:dmn_popup_article />.
And at-least we need to put some magic to textpattern so it will understand all this. To bad I have not got the time to convert this code to a decent plugin, but so for now I only post the code, but it is quite simple to just copy paste it into a file and place it in textpatterns plugin cache dir
Alot of this code is borrowed from the way txp handles popup comments.
dmn_popup_article();
function dmn_popup_article() {
if (gps('dmn_popup_article') && is_numeric(gps('dmn_popup_article'))) {
header("Content-type: text/html; charset=utf-8");
exit(dmn_pop_article(gps('dmn_popup_article')));
}
}
The function bellow will replace the tag <txp:dmn_popup_article /> with the article title and the body.
function dmn_pop_article($id) {
$rs = safe_row("*, unix_timestamp(Posted) as uPosted",
"textpattern",
"ID='".intval($id)."' and Status in (4,5) limit 1");
if ($rs) {
extract($rs);
} else {
exit('Could not find that article.');
}
$articleOut = hed(gTxt($rs['Title']),3);
$articleOut .= $rs['Body_html'];
$out = fetch_form('popup_article');
$out = str_replace("<txp:dmn_popup_article />",$articleOut,$out);
return $out;
}
As you see I use the same technique to open up new windows as txp it self use, feel free to replace it with some external js if that feels better.
function dmn_popup_article_link($atts) {
global $thisarticle;
extract(lAtts(array(
'width' => 380,
'height' => 450,
'caption' => 'Read more'
),$atts));
return '<a href="'.hu.'?dmn_popup_article='.$thisarticle['thisid'].'" ' .
'onclick="window.open(this.href, \'popupwindow\', ' .
'\'width=' . $width . ',height=' . $height .
',scrollbars,resizable\'); ' .
'return false;">' . $caption . '</a>';
}
Is there a better way to accomplish this?
jan,
sorry I do not provide a plugin to download for this, but it is quite simple to copy paste the code into txp plugin cache dir.
Please tell if it do not work for you.
Johan,
hmm… there seems to be something wrong, but im not quite sure what it is, altought the pinging services seems to be able to read my feed, but the validator cant read it, arrrgh!
Could it be something missing on the server?
Thanks for the notice
hmm, idea is not so good:
– popupblocker – not seo friendlyHi 3dsl_Eugen, no it realy isnt seo friendly, the meaning of this article was more a pretty rough straight forward process of how you could implement support for popups, it is pretty easy to tweak the function dmn_popup_article_link to use unobtrusive javascript instead.
Thanks for your input on this.
Hi Johan,
great that your site is back again today, as I’ve been looking for exactly this solution for several weeks. So thank you for publishing this.
Too bad that I don’t get it to work, “unknown tag”. Do I have to name the file in the plugin cache especially? Any idea?
Thanks in advance.
Thank you for this .. I managed to get it working .. saved me a lot of time.
Internetaccess hemmaUpdated Styled checkboxes and radiobuttons