ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

single entry comment form on homepage

October 12, 2007 7:31am

Subscribe [4]
  • #1 / Oct 12, 2007 7:31am

    CodeOfficer

    53 posts

    I purchased EE Personal back in July and have just gotten around to using it to create version 2 of my personal site. I’ve done 90% my templates, and the pages are looking sweet! But ... after 2 days of banging my head against the wall, i cant figure out how to achieve a specific layout I am looking for.

    My homepage does not mimic a typical blog layout. I do not want to list the 10 most recent posts, I want to list only one. I’ve done this already ... but I also want to include the comment form for this single post on this page like i would on any other single entry page.

    My homepage URL however will obviously not include the url title for the most recent post. It will look more like…

    http://www.domain.com/

    How can I achieve this?

    I have read a number of posts in the forums on this topic, everyone so far has said it can’t be done. That comment form tags dont work embedded in web entry tags, and that its near impossible to pass the entry_id from the web entries tag to the comment form tag dependably due to the way templates get rendered.

    This is not an option for me. I would really appreciate some ideas on how to pull this off. Perhaps a dynamic redirect to a real single entry page? I would love to hear you ideas. I hope I am able to find a solution, EE is very impressive so far otherwise.

    *begins begging*

  • #2 / Oct 12, 2007 10:10am

    elwed

    151 posts

    One way would be to use limit=“1” as a parameter to exp:weblog;entries. Or you can use entry_id=“whatever”, perhaps dynamically deriving a value for “whatever”. Then there’s dynamic=“off” which might help you.

    Plenty of options; what makes sense depends on the overall design.

  • #3 / Oct 12, 2007 2:37pm

    CodeOfficer

    53 posts

    I believe you misread, my apologies for not being clear enough. I’ve already tackled the code for showing the single post on the page ... using limit=“1”, orderby ... etc ... thats not a problem at the moment.

    The problem is displaying the comment form underneath the post, and on the homepage which since its not a real “single entry” page does not have the URL title or ID to go from.

    again, the url is ...

    ttp://www.domain.com/

    and NOT ..

    ttp://www.domain.com/blog/some_specific_post_title_or_id

  • #4 / Oct 12, 2007 3:22pm

    elwed

    151 posts

    If you can nest exp:comment:entries within exp:weblog:entries, all you need to do is to pass the weblog entry’s entry_id as a parameter to exp:comment:entries. And of course add all the necessary code to the index template.

    If you can’t nest, you’ll have to find a way to preserve entry_id between the two tags. I’m pretty sure that a simple assign_variable won’t work because of parsing order issues, but there’s probably a few lines of PHP code that’ll do the stashing and retrieving.

    There may be an even better way, but I can’t think of anything right now. It’s not something I’ve ever done.

  • #5 / Oct 12, 2007 3:26pm

    Lisa Wess

    20502 posts

    You might like to try Comments on Index =)

  • #6 / Oct 12, 2007 3:33pm

    CodeOfficer

    53 posts

    @markus - you’re thinking along the right lines, I tried all of those options already. The option of greatest hope is the one that Lisa mentioned.

    @lisa - I will give another try with that method, last night I had no luck with it. I could indeed set the entry ID as a php var within the weblog entries loop, but i was unable to get the comment entries tag to make use of that variable. Is there some trick to going from php back to EE?

    I did want to ask as well lisa ... what does

    “Be careful when utilizing these instructions, as this can be fairly intensive on your hosting.”

    translate to mean exactly?

  • #7 / Oct 12, 2007 3:40pm

    Lisa Wess

    20502 posts

    It means that when you’re showing multiple entries, and then showing all the comments for each entry, EE has to do a lot of work.  So if you’re showing 20 entries, and each of those entries has 20 comments, you could have a problem.

    This is something to be aware of on a case by case basis; it is, of course, always possible for someone to customize themselves into a slow-loading site.  However, you’re limiting the scope so you should be fine.  If it does appear that things slow down considerably, then a direct query might be your best option.

  • #8 / Oct 12, 2007 3:44pm

    CodeOfficer

    53 posts

    Thanks lisa! Trying it out now. I hope this is the last you hear from me on this topic 😊

  • #9 / Oct 12, 2007 3:56pm

    CodeOfficer

    53 posts

    Hmmm not working ....

    I have a blog/index template (set to allow php execution)

    {assign_variable:my_weblog_name="myblog"}
    {assign_variable:my_template_group="blog"}
    
    {exp:weblog:entries weblog="{my_weblog_name}" limit="1" orderby="date" sort="desc" disable="member_data|trackbacks"}
        <h2 class="title">{title}</h2>
        {summary}
        {body}
        <hr>
        Posted by {url_or_email_as_author} on {entry_date format='%m/%d'} at {entry_date format='%h:%i %A'}
        {if allow_comments}
        ({comment_total}) <a href="http://{url_title_path=">Comments</a> •
        {/if}
        {if allow_trackbacks}
        ({trackback_total}) <a href="http://{trackback_path=">Trackbacks</a> •
        {/if}
        <a href="http://{title_permalink={my_template_group}/index}">Permalink</a>
    
        <?php @include("{comment_path=page_elements/_comments}"); ?>
        <?php @include("{comment_path=page_elements/_comment_form}"); ?>
    {/exp:weblog:entries}

    Then i have the 2 mentioned includes. I will list just the page_elements/_comments template for now:

    {exp:comment:entries weblog="{my_weblog_name}"}
        {comment}
        Posted by {url_or_email_as_author}   on  {comment_date format='%m/%d'}  at  {comment_date format='%h:%i %A'}
        <hr>
    {/exp:comment:entries}
  • #10 / Oct 12, 2007 4:03pm

    Lisa Wess

    20502 posts

    Is {my_weblog_name} assigned on the sub-template as well?  And is PHP set to input, or output?

  • #11 / Oct 12, 2007 4:12pm

    CodeOfficer

    53 posts

    Hmm

    {my_weblog_name} is not assigned in the comments template as well. Should it be? If so, how do I make it dynamic as well?

    And PHP on blog/index is set to output

  • #12 / Oct 12, 2007 4:21pm

    Lisa Wess

    20502 posts

    Yes, you need to use those first two lines in that template to assign it. If you’re going to be using that variable in many, many templates, then you might like to look at path.php global variables in the docs.

  • #13 / Oct 12, 2007 4:26pm

    CodeOfficer

    53 posts

    hmm intersting, this works to display comments, i put it in my weblog:entries tag

    {embed="page_elements/_comments" my_weblog_name="{my_weblog_name}" my_template_group="{my_template_group}" entry_id="{entry_id}"}

    is there any reason the comment form would not work as well in this way? I suppose I will try.

    How was this method doable and I didnt have to use PHP as mentioned before.

  • #14 / Oct 12, 2007 5:18pm

    elwed

    151 posts

    Lisa, I dimly recall that wiki entry. I’m not entirely clear what the difference between the PHP @include and an embed is, but the basic idea seems to be nesting the tags. If that’s more or less equivalent, why not pass the entry_id as an embed variable and use it for the comment:entries tag?

    In the index template:

    {exp:weblog:entries ...}
    ...
    {embed="{my_template_group}/.comment_form" var_entry_id={entry_id}
    {/exp:weblog:entries}

    In .comment_form:

    {exp:comment:entries ... entry_id="{embed:var_entry_id}"}
    ...
    {/exp:comment:entries}

    If I weren’t busy prepping for a garage sale today, I’d try it out myself…

  • #15 / Oct 12, 2007 5:29pm

    Lisa Wess

    20502 posts

    The answer is simple:

    The wiki entry was created before embeds could pass variables.

    I never did use that method myself so I’m not sure where it might be hanging up at this point. =/

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases