I am outputting the field 'Node - Comment Count' as a link to the node itself. I have included the fields 'Node:nid' and 'Node:Link' above the comment count field and excluded them from display. I then used the replacement pattern [nid] and/or [view_node] in the 'Link path: ' box. But the view ignores ANY replacement patterns and I get an empty link: <a href="/"> I am absolutely stumped. Could this be a bug, or am I missing something?
I do have token module installed by the way.
Query
SELECT node.nid AS nid,
node.title AS node_title,
node_revisions.body AS node_revisions_body,
node_revisions.format AS node_revisions_format,
node.created AS node_created,
node_comment_statistics.comment_count AS node_comment_statistics_comment_count,
DATE_FORMAT(FROM_UNIXTIME(node.created), '%Y%m%d%H%i') AS node_created_minute
FROM node node
LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
INNER JOIN node_comment_statistics node_comment_statistics ON node.nid = node_comment_statistics.nid
WHERE (node.status <> 0) AND (node.type in ('blog'))
ORDER BY node_created_minute ASC
<?php
$view = new view;
$view->name = 'blog';
$view->description = 'Custom blog page';
$view->tag = 'default';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'nid' => array(
'label' => 'Nid',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_node' => 0,
'exclude' => 1,
'id' => 'nid',
'table' => 'node',
'field' => 'nid',
'relationship' => 'none',
),
'view_node' => array(
'label' => 'Link',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'text' => '',
'exclude' => 1,
'id' => 'view_node',
'table' => 'node',
'field' => 'view_node',
'relationship' => 'none',
),
'title' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'body' => array(
'label' => '',
'exclude' => 0,
'id' => 'body',
'table' => 'node_revisions',
'field' => 'body',
'relationship' => 'none',
),
'created' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'date_format' => 'custom',
'custom_date_format' => 'F jS Y',
'exclude' => 0,
'id' => 'created',
'table' => 'node',
'field' => 'created',
'relationship' => 'none',
),
'comment_count' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 1,
'path' => '[nid]',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'set_precision' => FALSE,
'precision' => 0,
'decimal' => '.',
'separator' => ',',
'prefix' => '',
'suffix' => ' comments',
'exclude' => 0,
'id' => 'comment_count',
'table' => 'node_comment_statistics',
'field' => 'comment_count',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'created' => array(
'order' => 'ASC',
'granularity' => 'minute',
'id' => 'created',
'table' => 'node',
'field' => 'created',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'status' => array(
'id' => 'status',
'table' => 'node',
'field' => 'status',
'operator' => '=',
'value' => '1',
'group' => 0,
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
),
'type' => array(
'operator' => 'in',
'value' => array(
'blog' => 'blog',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
'role' => array(),
'perm' => '',
));
$handler->override_option('header_format', '1');
$handler->override_option('footer_format', '1');
$handler->override_option('empty_format', '1');
$handler->override_option('use_ajax', '1');
$handler->override_option('use_pager', '0');
$handler->override_option('row_options', array(
'inline' => array(),
'separator' => '',
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('path', 'blog');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
$handler = $view->new_display('feed', 'Feed', 'feed');
$handler->override_option('title', 'Front page feed');
$handler->override_option('style_plugin', 'rss');
$handler->override_option('style_options', array(
'mission_description' => 1,
'description' => '',
));
$handler->override_option('row_plugin', 'node_rss');
$handler->override_option('row_options', array(
'item_length' => 'default',
));
$handler->override_option('path', 'rss.xml');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
$handler->override_option('displays', array(
'default' => 'default',
'page' => 'page',
));
$handler->override_option('sitename_title', '1');
?>
Comments
Comment #1
merlinofchaos commentedHmm. When I import this it works. Note that the path you're using is invalid. [nid] is not a path by itself, it should be node/[nid] -- but on my site it works.
What version of PHP are you using? There have been sporadic reports of the tokens failing to be available for replacement and I think it is PHP version related, but I haven't been able to nail down when/how that happens.
Comment #2
stevekerouac commentedThanks for looking into it Merlin, I do appreciate it. I'm on PHP 4.4.4. I have tried with node/[nid] but then it spits out: a href="node/" simply ignoring the token again. I'm glad its not something simple I missed but slightly unnerved that it works for you... Is there anything else I can test to help?
edit: have asked my hosts to move my account to a server running PHP 5... will post back here after.
Comment #3
stevekerouac commentedI can confirm that upgrading to PHP 5.2.6 has cured this problem. A few other errors have appeared but I'm fairly sure they are unrelated to this issue specifically.
I'd also just like to say thanks for all your time, effort and expertise developing this module and enabling greater freedom of information, from one little web user among millions.
Comment #4
kenorb commented#442768: Replacement pattern [nid] doesn't work on PHP4
Comment #5
MBroberg commentedI have the same issue when I exclude from display. It works with 'node/[nid]' when I uncheck the 'exclude' box.
Also the 'Node ID' field has to be before the field I am trying to 'output as link' or it won't show up as a valid replacement pattern.
Using PHP 5.2.6
Comment #6
kenorb commentedComment #7
merlinofchaos commentedWell, I just tried again, and when using exclude from display, I can make node/[nid] work as a replacement pattern just fine. I'm using PHP 5.2.6 as well. And yes, [nid] absolutely must be before the field you want to use as a replacement, to prevent infinite recursion problems. (Picture two fields, a and b. a is rewritten to [b] and b is rewritten to [a])
Comment #8
merlinofchaos commentedReturning this to duplicate. THe original issue is almost certainly the PHP4 issue.
Comment #9
couturier commentedAs an update to this issue, for Views 7.x-3.0-rc1, here is the process that worked for me.
To create "Add Comment" links on lists in Views that lead to individual nodes:
For variations on this concept, you can also link directly to the comment form itself for any node by using the following path: comment/reply/[nid]#comment-form
You can also include the comment count in the link by further configuring the "Comment count" field. Check the box "Format plural," then enter "Add Comment or View 1 Comment" under singular form and "Add Comment or View @count Comments" under plural form, or your own choice of wording.
Comment #10
samwillc commentedThanks couturier,
That was exactly what I was looking for! I wanted to replicate the teaser view but using fields instead so I could add a few extra fields. I can't figure out how to get the:
Read more
3 comments
Add new comment
...links into a list though.
Teaser outputs as:
<ul class="links inline"><li class="node-readmore first"><a href="/blog/my-second-blog-post" rel="tag" title="My second blog post">Read more<span class="element-invisible"> about My second blog post</span></a></li><li class="comment-comments"><a href="/blog/my-second-blog-post#comments" title="Jump to the first comment of this posting." property="sioc:num_replies" content="3" datatype="xsd:integer" rel="">3 comments</a></li><li class="comment-add last"><a href="/comment/reply/203#comment-form" title="Add a new comment to this page.">Add new comment</a></li></ul>My view outputs as:
<span><span><a href="/blog/my-second-blog-post">Read more</a></span></span><span><span><a href="/node/203/#comments">3 comments</a></span></span><span><span><a href="/comment/reply/203#comment-form">Add new comment</a></span></span>Not quite what I had in mind?! I wanted to be asble to use the same css I styled out the teaser with on my new view.
**EDIT** With a bit of tweaking I've managed to get it to the point where it can be styled out like a list:
with the following css to clear each post from the floated read more links above:
Works as expected although it feels odd without the items being in a list. That said, it looks like a list on the screen :)
Comment #11
shashwat purav commentedHi,
I had same issue on my site. I simple added "content: Nid" field above the excluded link and it started working. The issue was occurring because, when you add [Nid] into 'Link Path', as you have not included "Content: Nid", system does not understand what is it. So including "content: Nid" above link and excluding it from display solves the problem. cheers. :)