Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2008-05-11 00:54:38

tmq
New Member
Registered: 2005-09-10
Posts: 9

Re: Excerpting most recent excerpt on external page

oh, uh, I just fixed the blockcode. The php is still borked.

Offline

#14 2008-05-11 01:03:40

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: Excerpting most recent excerpt on external page

Ah, thought you’d made the break through, the code looked so close to perfection ;)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#15 2008-05-11 01:27:14

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Excerpting most recent excerpt on external page

uli wrote:

Esp. what did the trick Gocom maintained silence on?

I kept silence. Tell me what I’m keeping silence? LOL. You just could be silent by your self if it bugs you so much. From txp_list.php we would get something like, in example:

<?php
/* Database connection here */
function nextRow($r){
	$row = mysql_fetch_assoc($r);
	if ($row === false) mysql_free_result($r);
	return $row;
}
$q = "select * from 'textpattern' where Status = '4' order by Posted DESC limit 0, 5";
$rs = mysql_query($q);
if ($rs) {
	while ($a = nextRow($rs)){
		extract($a);
		echo $Title.$Excerpt_html;
	}
}
?>

Last edited by Gocom (2008-05-11 01:44:50)

Offline

#16 2008-05-11 01:39:58

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: Excerpting most recent excerpt on external page

tqm needs your attention, not me.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#17 2008-05-11 01:47:21

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Excerpting most recent excerpt on external page

uli wrote:

tqm needs your attention, not me.

I don’t get you, you obviously something against me or then your life just sucks :). Either way, I have already spoken and as I said, the straight answer is inside txp_list.php as I pasted there.

Offline

#18 2008-05-11 08:26:28

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Excerpting most recent excerpt on external page

Not tested, but perhaps something like this. If it doesn’t work, please report what does and does not work.


mysql_connect('localhost', $db_username, $db_password);
mysql_select_db($db_database) or die("Unable to select database");

$query = "Select Title, Excerpt_html FROM textpattern WHERE Section='article' AND Status='4' ORDER BY Posted DESC LIMIT 1"; 

extract(mysql_fetch_assoc(mysql_query($query)));

echo str_replace('%x%x', '&', htmlspecialchars(str_replace('&', '%x%x', $Title)));
echo $Excerpt_html;

PS. Gocom/Uli, please keep this on-topic.

Last edited by ruud (2008-05-11 09:23:43)

Offline

#19 2008-05-11 09:13:29

tmq
New Member
Registered: 2005-09-10
Posts: 9

Re: Excerpting most recent excerpt on external page

It’s interesting, isn’t it, how each approach seems so completely different? Thanks for the input, ruud. I’ve tried this, without success. Is there a debug mode that could be used when testing this? When run, these pages produce no result, so it’s difficult to know really what’s happening.

<?php

$db_username = 'xxx';
$db_password = 'xxx';
$db_database = 'xxx';

mysql_connect(localhost, $db_username, $db_password);
mysql_select_db($db_database) or die("Unable to select database");

$query = "Select Title, Excerpt_html FROM 'textpattern' WHERE Section='articles' AND Status='4' ORDER BY Posted DESC LIMIT 1"; 

extract(mysql_fetch_assoc(mysql_query($query)));

echo str_replace('%x%x', '&', htmlspecialchars(str_replace('&', '%x%x', $Title)));
echo $Excerpt_html;

?>

Offline

#20 2008-05-11 09:27:30

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Excerpting most recent excerpt on external page

Okay, I actually tested my code this time (fixed in my previous post). It had the following mistakes:
  • localhost should be quoted, otherwise it’s interpreted as a constant (which isn’t defined) instead of a string.
  • TXP uses a section ‘article’ instead of ‘articles’ by default, so please check to make sure which one it is.
  • In the query, I’ve removed the quotes surrounding the table name. I think if the table name needs quoting, it has to be done with backticks.
  • If you’ve set a prefix for your TXP tables, be sure to add it in the table name as used in the query.

btw, I simply looked at the error messages (on screen or in your webserver error logs) to find the problem and when it pointed towards an empty result set as returned by the query, I did some manual SQL queries (for example in PHPmyAdmin or in the command line MySQL client).

Last edited by ruud (2008-05-11 09:29:48)

Offline

#21 2008-05-11 09:47:00

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: Excerpting most recent excerpt on external page

ruud schrieb:

btw, I simply looked at the error messages (on screen or in your webserver error logs) to find the problem and when it pointed towards an empty result set as returned by the query, I did some manual SQL queries (for example in PHPmyAdmin or in the command line MySQL client).

But then again here’s me following along with interest and gratitude for being as exact as you are.
Thanks, Ruud!


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#22 2008-05-11 10:12:03

tmq
New Member
Registered: 2005-09-10
Posts: 9

Re: Excerpting most recent excerpt on external page

Awesome. This works!

It turns out that the (plural) ‘articles’ is correct for my install (though I don’t think I’ve changed that). Using phpmyadmin made everything clearer for me. Thanks for your help, ruud.

Now just to figure out how to do this without exposing the db_password in the file (define the variables in httpd.config?)

Here’s the code

<?php
//db parameters
$db_username = 'xxx';
$db_password = 'xxx';
$db_database = 'xxx';

mysql_connect('localhost', $db_username, $db_password);
mysql_select_db($db_database) or die("Unable to select database");

$query = "Select Title, Excerpt_html FROM textpattern WHERE Section='articles' AND Status='4'ORDER BY Posted DESC LIMIT 1";  

extract(mysql_fetch_assoc(mysql_query($query)));

echo str_replace('%x%x', '&', htmlspecialchars(str_replace('&', '%x%x', $Title)));
echo $Excerpt_html;

?>

Offline

#23 2008-05-11 10:49:49

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Excerpting most recent excerpt on external page

With proper permissions on that PHP file, no-one else should be able to see the password.
Visitors to your website won’t see it anyway, because it doesn’t appear in the resulting HTML code.

Offline

#24 2008-05-11 17:40:59

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,091
Website GitHub Mastodon Twitter

Re: Excerpting most recent excerpt on external page

A simpler method the txp way – no php knowledge needed

  1. Create a new section named “latest” pointing and a new template without anything except <txp:article limit="1" listform="excerpt" />
  2. Create a new article form and call it “excerpt” and within it just have <txp:excerpt />
  3. In your external page just add <?php include($DOCUMENT_ROOT . "http://yoursite.tld/latest/"); ?>
  4. Done:)

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB