I’m trying to add a php include to my RSS 2.0 feed such that the feed includes comments along with the entries. Following the suggestions on the wiki (as well as in various forum threads), I’ve added code into my rss template such that it now looks like this:
In template preferences, I’ve turned “allow php” on, and set it to parse at output. And the included template, incl_comments, looks like this:
<div><strong>{exp:weblog:entries limit="1"} {if comment_total == 0}0 Comments{/if} {if comment_total == 1}1 Comment{/if} {if comment_total > 1}{comment_total} Comments{/if} {if trackback_total == 0} and 0 Trackbacks{/if} {if trackback_total == 1} and 1 Trackback{/if} {if trackback_total > 1} and {trackback_total} Trackbacks{/if} {/exp:weblog:entries}</strong></div> <hr />{exp:comment:entries} {if comments}<em>{comment}</em> <div>Comment by {name} on on {comment_date format='%m.%d.%y'} at {comment_date format='%h.%i %A'}</div> {/if} {if trackbacks} <em><strong>{title}</strong>{content}</em> <div>Trackback from: <a href="{trackback_url}">{weblog_name}</a> ({trackback_ip}) on {trackback_date format='%m.%d.%y, %h.%i %A'}</div> {/if}{/exp:comment:entries}
Rendering the template gives me repeated iterations of the following error, where the comments ought to be:
<b>Warning</b>: Unknown(): URL file-access is disabled in the server configuration in <b>(file path snipped)/core/core.functions.php(570) : eval()'d code</b> on line <b>35</b>
I’ve attempted to work my way through the configuration settings in the admin panel, looking for something that would affect this, but I’m coming up dry. Any suggestions that you might have would be greatly appreciated!
[Updated to add: that’s supposed to be “eval()‘d” in the last code snippet above; I can’t make the open paren appear properly!]
The {comment_path} variable is going to return a URL (with http:// on the front). Many servers will not allow you to include a file through a URL because it leaves open the way for the including of naughty files onto the server. This is a setting your host has setup. Why do you not use an embed?
This is a VERY good question. I can use an embed? Just like in a regular web page template? That’s mildly embarrassing. I knew I was overlooking SOMETHING obvious.
Well, I take it you are simply using that page to display the comments for an entry or something like that? The only problem is that the {embed} tag cannot send variables (like the entry_id) to the template. However, the Snippets plugin can do stuff like this, I believe.
I think I follow this. It’s going to take some tinkering, though, and my post-Bikram brain is not cooperating. I’ll try it in the morning—thanks for the help!
<div><strong>{exp:weblog:entries entry_id="%entry_id_var%"} {if comment_total == 0}0 Comments{/if} {if comment_total == 1}1 Comment{/if} {if comment_total > 1}{comment_total} Comments{/if} {if trackback_total == 0} and 0 Trackbacks{/if} {if trackback_total == 1} and 1 Trackback{/if} {if trackback_total > 1} and {trackback_total} Trackbacks{/if} {/exp:weblog:entries}</strong></div> <hr />{exp:comment:entries} {if comments}<em>{comment}</em> <div>Posted by {name} on {comment_date format='%m.%d.%y'} at {comment_date format='%h.%i %A'}</div> {/if} {if trackbacks} <em><strong>{title}</strong>{content}</em> <div>Tracked on: <a href="{trackback_url}">{weblog_name}</a> ({trackback_ip}) on {trackback_date format='%m.%d.%y, %h.%i %A'}</div> {/if}{/exp:comment:entries}
By passing the %entry_id_var% to the snippet, I’m now able to get each entry to appear with an accurate count of the number of comments and/or trackbacks associated with it. But I can’t yet figure out how to pass a similar variable to the {exp:comment:entries} tag. Since it doesn’t take entry_id as a parameter, but rather takes its cues about what entry’s comments it should be displaying from the entry_id_path contained in its URL, I’m a little at a loss. Undoubtedly there’s something totally obvious here as well, a way to invoke the entry_id_path that will cause {exp:comments:entries} to localize, but I’m not seeing it yet…
Okay, I’ve been bashing my head up against this, and it’s simply not going to work. Because the call to incl_comments is being issued from inside a {exp:weblog:entries} tag, I don’t have access to the comment variables needed to send to the snippet in order to get it to render comments.
So, new approach, backtracking to the original approach, drawing from the wiki: I’ve checked with my hosting provider, and while allow_url_fopen is disabled due to security concerns, I can theoretically use a server-side include to call the included template. Their support materials say that if I want to make this (disabled) php call:
Fine & dandy. Except that I’m trying to use an EE variable to make the call, and I can’t come up with a way to make an EE-type URL (like http://www.example.com/index.php?/weblog/incl_comments) resolve using the local file structure.
This is getting a teeny bit frustrating. Is there no other way to build an RSS feed that includes comments with entries?
I’m so bad at server stuff - what does that document_root resolve to? From there I can help you make it work, I think. I mean, what is the exact output of that by itself?
And no, showing comments with entries on multi-entry pages isn’t supported by default, that’s why the wiki article exists.
What your host is suggesting will not work as it will be including a file while you need a processed URL. Give me a few moments and I will just figure it out and post what I find.
Unfortunately, the Snippets plugin has PHP parsed on input before it exchanges the variables it sets, so that idea is a bust. So, we’re going to have to use an all PHP solution since your host does not let you load remote files. You will have to modify the template names and the master weblog name in these two examples, but they seem to work for me:
{exp:comment:entries} {if comments}<em>{comment}</em> <div>Posted by {name} on {comment_date format='%m.%d.%y'} at {comment_date format='%h.%i %A'}</div> {/if}
{if trackbacks} <em><strong>{title}</strong>{content}</em> <div>Tracked on: <a href="{trackback_url}">{weblog_name}</a> ({trackback_ip}) on {trackback_date format='%m.%d.%y, %h.%i %A'}</div> {/if} {/exp:comment:entries}
Paul, *thank you* for all the effort you’ve put into this. Alas, I don’t have great news to report. I copied the templates you provided, changed the variables that needed changing, made sure preferences were properly set, and on load, I got this error:
XML Parsing Error: junk after document element Location: http://www.plannedobsolescence.net/index.php?/weblog/newrss/ Line Number 2, Column 1:<b>Parse error</b>: parse error, unexpected T_IF in <b>[directory path snipped]/eesys/core/core.functions.php(570) : eval()'d code</b> on line <b>39</b><br /> ^
Any ideas? I’ll absolutely understand if you’re out of them at this point. And thanks again for all the help.
Hm, seems that one of the conditionals is causing a problem. You made sure to turn off PHP parsing for the second template? And you are using the current build of EE?
It’s here. My fear is that this is going to turn out again to be a peculiarity of my hosting provider, but if you discover differently, I’ll be thrilled!