开发者

Add Link Field in Template in Drupal 6 with CCK

开发者 https://www.devze.com 2023-03-10 09:11 出处:网络
Good Evening, I\'m using Drupal 6, CCK Module, and the Link Field Type. All are installed and activated.

Good Evening,

I'm using Drupal 6, CCK Module, and the Link Field Type. All are installed and activated.

I created a custom content type called Slider. A user can upload an image, a title, and a teaser. I created a custom field for that slider content type as well as one called Link with the field name: "field_link_test".

I created an entry, filled in all of the data including a URL for that link field type and clicked "Save". In views-view-table--slider.tpl.php, I added:

 <a href="<?php print $node->field_link_test[0]['url'] ?>">Learn More</a>

but on the front end, everything shows except for that link. I also tried emptying the Drupal cache.

Any ideas?

Update template code below, which all works fine, except for the new link value outputs nothing.

<div id="slider">
<div class="slider-holder">
    <?php foreach($rows as $row): ?>
    <div class="slide">
        <?php print $row['field_image_fid'] ?>
        <div class="info-slide">
            <h2><?php print $row['title'] ?></h2> 
            <p><?php print strip_tags($row['teaser']) ?></p>
            开发者_如何转开发<a href="<?php print $node->field_link_test[0]['url'] ?>">Learn More</a>
        </div><!--INFO-SLIDE-->
    </div><!--SLIDE--> 
    <?php endforeach ?>
</div><!--SLIDER-HOLDER-->
<div id="control">

</div>
</div><!--SLIDER-->


The easy possibilities (which you've probably checked, but just to get them out of the way):

  • you need to allow the field to be viewable by anonymous/authenticated users in User Management - Permissions

Otherwise, it's hard to tell without some code to analyse. Could you post your entire views-view-table--slide.tpl.php and if possible, your exported view or a link to the exported view?

EDIT

Now that I've had a chance to look at your view, I've made a couple of changes that should help.

The reason your link URL isn't showing is that you're including the "Node: Link" field in your View instead of the "Content: Link (field_link_test)" field. The first one will just link back to the original node rather than your custom link. Also, I don't think you can call the $node variable from views-view-table (at least, I don't get anything when I print it. Instead, you can use the $row variable.

I have a version of your template that prints out the URL in the field "link_test" with the label "Learn More." I put the "Learn More" text in the View itself as that'll be easier to edit and works better with the Link CCK type (which by default will want to add a title you add in the node edit screen).

The view export is here: http://pastebin.me/0ed2942f6953cb00cab1bd5386058a13. You can import this back into your site, but you may want to clone your original View first to make a backup, so that if this isn't what you want, you can use your old version.

The updated tpl is:

<div id="slider">
<div class="slider-holder">
    <?php foreach($rows as $row): ?>
    <div class="slide">
        <?php print $row['field_image_fid'] ?>
        <div class="info-slide">
            <h2><?php print $row['title'] ?></h2> 
            <p><?php print strip_tags($row['teaser']) ?></p>
            <?php print $row['field_link_test_url'] ?>
            <?php //print_r($row); ?>

        </div><!--INFO-SLIDE-->
    </div><!--SLIDE--> 
    <?php endforeach ?>
</div><!--SLIDER-HOLDER-->
<div id="control">

</div>
</div><!--SLIDER-->

Let me know if you have any issues/questions.


Are you sure the template is getting picked up (add <p>heavymark</p> above the href... does it show up?)?

If above shows up, add a var_dump($node) above the anchor tag and post the output so we can get a better idea of what's there (you probably want to enable XDebug so you get better formatted output, if its not on already).


Make sure you add the link field to the view in the fields section. This should allow it to be themeable from within your template file. If you are still not seeing it, try using

print_r($rows,1);

or some variable of print_r to view all the rows that are available to be themed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号