I am new to expression engine.
I have a channel name "news" and I have published some pages. In my template, I have used code as
{exp:channel:entries channel="news"}
<h2>{title}<h2>
{body}
{/exp:channel:entries}
But the output is I get the page title but the content doesn't shows up and i get {body} as it is on the frontend
Can anyone help me please, where I am going wrong?
Perhaps "body" is not a valid field name?
Every "channel" has a "field group" assigned to it. In the control panel look at the field group for your "News" channel. Does that field group have a field with the short name "body"
Related
I use Orchard 1.10.1. I have a CustomContentType that has a "Group" Taxonomy field . In Content-CustomContentType.Detail.cshtml alternate, I want to have a link to a certain taxonomy term. this is my code:
<a href='???'>#Model.ContentItem.CustomContentType.Group.Terms[0].Name</a>
How can I get the url to replace this '???' in above code.
Thanks in advance.
You have a few options available to you. I've just typed them all straight into the browser and Orchard is a tricky beast to navigate its model so if they blow up in your face let me know and I'll dig a bit deeper :)
Let orchard make the entire link
Looking at the TaxonomyItemLink.cshtml file you can see that you can display the link like this:
#using Orchard.Taxonomies.Models
#{
TermPart part = Model.ContentPart;
}
#Html.ItemDisplayLink(part)
So in your case you could use:
#Html.ItemDisplayLink((ContentPart)Model.ContentItem.CustomContentType.Group.Terms[0])
Just get the URL
You can use #Url.ItemDisplayUrl() to turn a routable content item into a url.
<a href="#Url.ItemDisplayUrl((ContentPart)Model.ContentItem.CustomContentType.Group.Terms[0])">
#Model.ContentItem.CustomContentType.Group.Terms[0].Name
</a>
Because it's an extension method you can't pass a dynamic so you will need to cast the type. This is why the (ContentPart) is there.
Just get the Slug
Actually, in this case the TermsPart class already has a .Slug property on it, so this might also work:
<a href="#Model.ContentItem.CustomContentType.Group.Terms[0].Slug">
#Model.ContentItem.CustomContentType.Group.Terms[0].Name
</a>
I'm not sure if the slug just contains the end bit or its full url though.
I read this from a recent answer to a question:
After enabling the extension, just use {{ twitterfeed() }} in your templates.
But, what if I only want say a contact form on one page? Putting the tag in the page's text field doesn't work. And putting it in the template would have it available on all the pages using that template. Do I have to duplicate a template to use only for the contact page? If not where do I put the contact form tag?
I went to Bolt's extension page, selected "how to use extensions" from the menu, and got this message:
No proper name for a page in the docs. Bye!
Perhaps someone at Bolt could fix the URL?
I would like to know why none of the extensions I want to use are not working. I am clearly missing a vital piece of info.
Thank you.
After enabling the extension, just use {{ twitterfeed() }} in your templates.
The Twig function {{ twitterfeed() }} belongs (generally speaking) in a Twig template file. You can use Twig in record fields, but that requires setting allowtwig: true for that Contenttype field.
But, what if I only want say a contact form on one page?
There are a few ways to do this, but the easiest way is to make a copy of your sites template file for the page's Contenttype and select that template for the 'Contact' record. The default 'pages' Contenttype that comes with Bolt has a templateselect field type that enables this.
No proper name for a page in the docs. Bye!
Fixed! Thanks for pointing it out.
I feel like there is a really simple solution to this problem. However, after trying to solve it for about 3 hours unsuccessfully, I humbly come to you.
The Basics:
A custom post type, " band ", has been created, and has several
custom fields (which were created through the Advanced Custom
Fields
plugin.)
The Question:
How would I get and display the contents (specifically custom field data) of a specific band entry (using its ID or title or slug) inside of a regular post? (see diagram below)
(source: thisnewband.com)
.
Methods to Trigger the Display of the Custom Post Type:
We have to provide the ID/title/slug so that it knows what band post's content to display
Shortcode (such as [band id="21"] ) (added inside post content)
Custom Field (custom field name band-id where you can input the ID of the band)
What I've Tried and Why It Didn't Work:
Shortcode
`[band id="21"] inserted in post editor field
Used WP_Query to query post with type=band and ID="21".
Code located in functions.php
Result: It would echo static text but would not display any post-specific content (Band Name, etc.). Also would not pull post-specific custom field data.
(also tried query_post with no luck)
Custom Field
Entered ID (21) into custom field on post editor page.
Coded it directly into the post template:
Used WP_Query and had the ID in the array pull from the custom field.
Result: Nothing good happened.
Where I Keep Running Into Trouble:
It's hard to pull the custom field data from the custom post type while inside an actual post
The Optimal Solution:
Whether it's by using a shortcode, custom field, or even a new widget, it would be easiest if one could:
Create a PHP template with the code for just how the single Band content is supposed to display. (Including the loop). Example name: band-block.php
Use get_template_part('band-block'); to echo this code (either in Post Template or Shortcode via functions.php)
Thanks for your help! Let me know if you'd like to see any of my code.
I knew you have found a solution for your problem, but for others i will give them an other solution:
You can query by ID, no problem. Look at these: http://www.advancedcustomfields.com/resources/field-types/relationship/
But you have to check in the custom field "return format" the box "Post IDs". Then it works perfectly well.
Sorry for my bad english ;)
Cheers
With some amazing help from Hobo, I was able to come up with a solution!
The main problem was with trying to query by 'ID'. No matter what we tried, it just never worked well. (It could be the way that the Advanced Custom Fields stored the ID field contents.)
What did work:
Created a custom field for the post page in which to put the Band (custom post type) post name/slug into. (Custom field was named post-band-name and created with the Advanced Custom Fields plugin.)
Placed the query code in the Post Template. (See code below)
Done.
The Solution Code
Add this loop after the normal loop...
<?php /* Display all the author's posts from the custom post type ('band') */ ?>
<?php
$authorid = get_the_author_meta( ID, $userID );
$args4=array('author'=>$authorid,'post_type'=>'band', 'numberposts'=> -1);
$cquery4=new WP_Query($args4);
if($cquery4->have_posts()):
while($cquery4->have_posts()):
$cquery4->the_post();
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<p><?php the_title();?></p>
</a>
<?
endwhile;
wp_reset_postdata();
endif;
?>
I'm trying to use the "URL title to Entry ID" plugin to feed the entry_id parameter into a Channel Entries tag, but can't figure out a way to get the ID information inserted early enough in the template parsing order.
This doesn't work - it picks up no entry ID, and so displays all entries:
{exp:channel:entries entry_id="{exp:url_title_to_entry_id parse="inward" url_title="{last_segment}"}" dynamic="no"}
{title}
{/exp:channel:entries}
Any suggestions would be much appreciated.
You can't have a function tag as a parameter to another function tag.
So either you have to pass the {exp:url_title_to_entry_id} result as an embed variable to another template that holds the channel:entries tag, or you have to use tag pairs so that one function tag, wraps the other and uses variables.
url_title_to_entry_id doesn't allow for tag pair, so either use the embed technique, or use another add-on.
BUT, you don't need the add-on at all...
{exp:channel:entries url_title="{last_segment}" dynamic="no"}
{title}
{/exp:channel:entries}
reference.
I'd also suggest added required_entry="yes" and limit="1" and then add {if no_results}...{/if} conditional inside. This will prevent it outputting all entries if it can't find a match.
I'm just learning EE and I have the following example url, http://mydomain.com/work/preview/clientname
where I want clientname to match a channel field I have setup ("client_name") and to pull in channel content only if it matches that channel field.
For example, http://mydomain.com/work/preview/google, would display channel content if the specified channel field "client_name" for a particular entry is "google".
I know how to use the following to pull in content from the channel "videos":
{exp:channel:entries channel="videos"}
{title}
{/exp:channel:entries}
...but how do I accomplish this for different url segments?
I believe what you're looking for is searching the channel entries tag by field name.
Here's an example:
{exp:channel:entries channel="videos" search:client_name="google"}
{title}
{/exp:channel:entries}
Do keep in mind though if you want to use the segment for this you'll likely have to pass the segment through an embed as a variable. You can read about this here.
Making this change works for me:
{exp:channel:entries channel="videos" dynamic="no" search:client_name="segment_2"}
{title}
{/exp:channel:entries}