简体   繁体   English

在 Drupal 视图参数中,如何获取节点队列中的节点总数?

[英]In a Drupal Views argument, how can I get the total number of nodes in a nodequeue?

I'm working on a site that is a database of thousands record albums and am attempting to create an "album of the day" block.我正在一个网站上工作,该网站是一个包含数千张唱片的数据库,并试图创建一个“每日专辑”块。 My solution has been to create a nodequeue of specific records, create a view that passes the current day of the year as an argument, and then uses this value to call the nodequeue item with that same numbered position.我的解决方案是创建一个特定记录的节点队列,创建一个将当年的当前日期作为参数传递的视图,然后使用该值调用具有相同编号 position 的节点队列项。 I do this by providing a "Default Argument" as PHP code in the "Nodequeue: Position" argument setting.我通过在“节点队列:位置”参数设置中提供“默认参数”作为 PHP 代码来做到这一点。 Here's the code I use:这是我使用的代码:

$nodequeueTotalNodes = 120;
$dayOfTheYear = date("z");
$nodeQueuePosition = $dayOfTheYear % $nodequeueTotalNodes;
return $nodeQueuePosition;

The above code works to my satisfaction but my problem is I have to manually change the value of $nodequeueTotalNodes every time I add or remove an item from my nodequeue.上面的代码令我满意,但我的问题是每次从节点队列中添加或删除项目时,我都必须手动更改 $nodequeueTotalNodes 的值。

Is there a way to pull the total number of nodes from my queue to replace the "120" in my code above?有没有办法从我的队列中提取节点总数来替换上面代码中的“120”?

The nodequeue_nodes table holds all the nodes in your queues. nodequeue_nodes 表包含队列中的所有节点。 Something like this should do the trick, where qid is the queue id:像这样的东西应该可以解决问题,其中 qid 是队列 ID:

$nodequeueTotalNodes = db_result(db_query('SELECT COUNT(nid) FROM {nodequeue_nodes} WHERE qid = %d', $qid));

If you're using a subqueue there's a column called sqid which you can use.如果您使用的是子队列,则可以使用一个名为 ssid 的列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM