Hi,
I apologize for posting this, because it is almost certainly very simple, but I've searched high and low and could find now answers.
I'm using Contemplate in conjuction with CCK to post articles, creating a teaser field that shows up on the main page. I want to create a read more link at the bottom of each teaser.
I know this subject has been covered in a more in depth sense, but my question is, the title of the article links to the full article. What is the code that created that link, and can I just insert it in the bottom of my teaser template with the words "Read More...." instead of the title and accomplish the same thing?
If it is that easy, what is the code that would create a self-referential link to the article being submitted? Is such a thing even possible?
Thanks in advance - I'm not a super technically oriented coder so this might be very simple and I just don't understand it.
-jimi
Comments
Not exactly an answer, but a start
So if you look in your themes node.tpl.php you'll see where that is generated - its part of a $links array. On a hunch I went to node.module and searched for "read more" and found this:
If you can follow that than you can tell that the relevant part to your situation is
l(t('read more'), "node/$node->nid", array('title' => t('Read the rest of this posting.'), 'class' => 'read-more'));A quick breakdown... the l() is the drupal function for generating a link (a href="", title etc). and the t() is for "translatable". This one probably isn't as important to this application - it lets localization module translate the string.
It still needs some work but hopefully this is a start for you. Anyone else with input or more experience with drupal coding standards than I, please help....
Sam Tresler
http://www.treslerdesigns.com
Interesting...
Thanks for your help! You might be able to tell that I'm new at this...
What better way to learn...
Dive right in!!!
Sam Tresler
http://www.treslerdesigns.com
Okay....
I'm not quite sure where I'm going with this, so bear with me.
On http://drupal.org/node/78336 there's another solution of sorts using some code.
However, if I use the latter half of that code for the readmore and insert it into my teaser template through Contemplate, the link refers to the home page on which the teaser exists, rather than the place where the full article is. How can I change that?
That appears to relate to the current page path
Good. I knew there was a better templating way to do it. Just to clarify, Drupal has a module layer and a theme layer. What I showed above was more for the module layer (should work in a tempalte but I don't think it is considered best practices). Theming goes through the phptemplating engine and is considered better form to alter things at the theme layer for upgrading later.
So..
<?php print $teaser = substr($field_story_text[0]['value'], 0, 300) ?><a href="<?php print $path ?>">...readmore</a></div>I think you should be able to change:
<?php print $path ?>Which prints the current page path.with
<?php print 'node/'; ?><?php print $node->nid; ?>Which should print the relative path to the node its on...
I think - I've not done this before.
Another solution might be to see if contemplate gives you access to the $links variable -- in which case you could just...
<?php print $links; ?>Which will have thr logic built in through node.module (as referenced above posting). To decide whether a 'read more' link needs to be generated in the first place. And also allow your other modules to keep posting their links to the bottom of nodes (e-mail this to a friend, print-friendly version, etc.)As I've mentioned, I'm not an expert, just trying to help where I can, so if this doesn't work, don't spend too long trusting me... or cursing my name. Hah!
Sam Tresler
http://www.treslerdesigns.com
Thanks again
Thanks so much for your help! I'll let you know how it goes....
No luck
That appears to still link to the front page node on which the teaser resides rather than the story that the headline of the teaser links to.
I don't think contemplate gives me access to the $links variable, unfortunately.
Thanks for all your help! Don't mean to seem ungrateful...
Another way to phrase the question/issue
When I look in the Contemplate Template set up for this teaser, every field is available to me other than the Title field, which is automatically printed with a correct link to the story.
What is the code that created that link and can I duplicate it at the end of my teaser template to create a read more link?
Hmmm... OK try this...
You don't seem ungrateful at all. I'm learning on this too.
This is from the node.tpl.php file that I use with foundation.theme
<h3 class="title"><a href="<?php print $node_url; ?>" title="<?php print $title; ?>"><?php print $title; ?></a></h3>So perhaps:
<?php print $node_url; ?>I wish I had time to test these before posting them to you, but I really don't.
Sam Tresler
http://www.treslerdesigns.com
Nope...
Unfortunately, it once again pointed to the front page node.
It seems the CCK code should be the answer since the title field is spitting out the correct link. But I can't seem to find where that field is being output from the code.
Haven't give n up on you, but...
I'm swamped the next few days and anything more I'll need to install and test to see what I can do.... I'm at BarcampNYC today and tomorrow and will ask other drupal peoples ther - post back if I get an answer. Good luck.
Incidentally - you might double check the HTML from the page with the link... drupal reads url's backwards looking for a match.... It would be relevant to know what the link is really pointing to once generated. Meaning that you should check that the link is indeed pointing to the same page or if it just can't find the page it's trying to point to and strips the url back to the current page....
So, if http:/ /example.com/node/68 doesn't exist drupal will go to http:/ /exmple.com/node - so check the generated HTML to confirm that the link is pointing whereyou think it pointing.
Sam Tresler
http://www.treslerdesigns.com
Gotcha...
I checked the HTML and it links correctly.
I appreciate your persistence and continued help in the matter and totally understand your own busy schedule!
My other thought is that since there is no header info in the teaser part of Contemplate, that CCK is really generating that code and if I could only find where it was coming from I could find the code.
I haven't given up on this,
I haven't given up on this, but still no solutions. Any thoughts would be greatly appreciated (from anyone!)
Can you post a link to the site?
Just so I can take a look and perhaps see some of what is actually happening here. Thanks!
Sam Tresler
http://www.treslerdesigns.com
-------------------------------------
"A list of common problems and their solutions can be found in the Troubleshooting FAQ."
read more in cck
I tryed a bit and this line works fine for me!
<div><span class="submitted">» <a href="<?php print '?q=node/'.$nid; ?>">read more...</a><?php print $links?></span></div>Just put it at the bottom of "Teaser Template:"
cya
it works!
Thanks so much. Don't know how I missed that one in the code.
Thanks for the tip, but...
I can't seem to get this working in Teaser Template. It seems that $links is out of scope or something. I can see it in the Teaser Variable list, and $links[0] show the "add comment link" correctly, but I want to append my own list to this, and whatever I try, $links[0] is empty when I view the page.
Any insights into this?
Within the Teaser Template, I have tried: print $links; and print $links[0]; and both are empty.
My other option is to create my links and then pass them into node-content_mytype.tpl.php so that when the links are created, it already has my appended list, but I can't figure this out either.
This might be a bit terse. I can go into more detail if necessary.