Include post date and excerpt in a Latest news list

Hi

Is there a list anywhere of the correct syntax for the different options that can be used in a template?

I have created this to display latest news:

<Loop type=post count="{Get local=count}">
<h4>
  <a href="{Field url}" alt="{Field title}">
    <Field title />
  </a></h4>
<p><field date /></p>
<p><field excerpt /></p>
</Loop>

but only the title link works. The date and excerpt do not show so I’m guessing they are called something different in L&L (they worked in Custom Content Shortcode)?

many thanks

The docs can be found at docs.loopsandlogic.com and you’ll find a beginner’s guide there as well as explanations and examples about how every tag works. Let me know if you’ve got any questions, although it sounds like you should simply start with the beginner’s guide and work your way up from there. In particular, check out the page about syntax. The solution to your issue is probably this:

Writing tags

An easy way to distinguish L&L’s dynamic tags from HTML’s static tags is that dynamic tags are always capitalized, like <User> and <Field> , unlike static HTML tags which are in lowercase.

Hi Benjamin

Thanks for the pointer. I had already been through all the documentation you mention but I have looked again and I now realise that Field should have had an initial cap. I have changed that now:

<p><Field date /></p>
<p><Field excerpt /></p>

However, this has only sorted out the excerpt, not the post date.

I have also tried but this just displays today’s date.

Would you be able to provide me with the specific code that should be used to display the publish date of a post?

By the way, I still haven’t managed to find a list of attributes that can be used with Field. This would be so useful.

Many thanks

Hi Mariette!
I think you’re looking for <Field publish_date />. You might also want to look into the available date formatting options which include a date_format attribute that can be set on a field like so <Field publish_date date_format="F j, Y" />

Because L&L supports custom fields and fields created with tools like ACF our documentation can be a little fragmented: things are separated out by context. In this context you’re using a post loop so the field documentation can be found here on the Post Loop article.

Interesting, I can see how the current docs lack a bit of information on the page related to the Field tag. I think most people discover that tag by learning about the Loop and then seeing how the Field tag works in that context, but you’re right that if you just go straight to the page about the Field tag it’s not super clear what field names you can use.

I expanded a bit on the paragraph on that page so it now reads:

The field names available will depend on the context in which the Field tag is placed. See the Loop tag and each loop type’s reference page for a list of available fields. For example, if the Field tag is placed within a post loop or on a post page, refer to the documentation for the post loop to see the available fields. Custom fields can also be displayed using the field’s name.

Let me know if that makes more sense or if you’re still confused about how that Field tag works.

1 Like

I honestly think I do understand how the Field tag works but I just couldn’t find any reference to what the attribute should be for the post date - thankfully Julia has now revealed it is publish_date (thank you!)

Perhaps part of my problem is that the link to the documentation for ‘post loop’ doesn’t work http://docs.loopsandlogic.com/loop-post?category_id=41#fields (page not found)

Hey there, the link does not work indeed, but I think the link that Benjamin wanted to send is this one: https://docs.loopsandlogic.com/category/41
You can find the fields a bit down in the page, just after Query Parameters.
let me know if it works for you!

Thanks Emma, that is exactly what I was looking for :smiling_face:

1 Like

My bad, not sure why those links were broken. Fixed them now.

After some feedback from Emma, I’ve updated the page that explains the Field tag to add some more examples and links. Want to look that over and let me know if there’s anything you still don’t understand about how that tag works?

2 Likes

Hi Benjamin

I think the updated text helps a lot, especially with the link with the available attributes. My problem was mainly not knowing what the L&L equivalent of the CCS attribute was. Oh, and not having a cap F for Field.

Thanks again for your help with this

2 Likes

Whenever you start a new tag make sure to have a capital letter :smile: it doesn’t matter which tag you use, if statement, field, loop, they all start with a capital letter in the tag.

OK, will remember that, thank you :smiling_face:

1 Like