I recently updated my node weighting patch to apply to the present Drupal CVS. It allows nodes to be ordered by an arbitrary admin-assigned weight, allowing users to:
- change the order of static nodes (if there are several) on the front page
- create "sticky" threads in the forums
- create a description/title node for your blog (a node that is listed before the others)
- create a description/title node for a taxonomy listing (a node that is listed before the others)
Node weight can be set both in the edit node form and in using admin->content.
Code changes made by the patch:
1. weight column added (mysql, pgsql, mssql, and update.php all modified appropriately)
2. weight drop-down added to add/edit node form for users with the appropriate permission
3. node index (home page) and taxonomy views now sort by weight
4. blog pages sort using weight
5. forum topic list now sorts by weight... this adds the ability to have "sticky" topics in the forums by simply assigning topics to be "stickied" a lower weight than everything else... quite useful, IMO
6. Feeds and forum blocks DO NOT sort using weight... I feel this would be inappropriate behavior.
7. In order to accomplish the weight-based sorting of forum topics, I had to add a parameter to tablesort_sql in tablesort.inc. (I needed to sort by weight before the usual metric.) This parameter defaults to a value that will not affect its current functionality.
8. In administration->content, a "weight" column has been added displaying current numerical value, along with clickable up and down arrows for each node.
9. An additional operation, called "View posts in front-page order," has been added to administration->content as well, allowing site admins to easily see the effects of their weight changes immediately.
10. A themeable function is responsible for creating the up and down arrows, so they can be customized or replaced with text links if desired.
11. Admin help text regarding node weight has been added.
Screenshots of the pages modified by the patch are available in my sandbox.
I'd appreciate any and all feedback regarding this patch, as I'm hoping that these features will find their way into the core before the code freeze.
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | node_weight-20050822.patch | 21.71 KB | tclineks |
| #15 | node_weight-20040328.patch | 22.91 KB | TDobes |
| #14 | node_weight-20040326.patch | 22.93 KB | TDobes |
| #11 | node_weight-20040303.patch | 23.83 KB | TDobes |
| #9 | node_weight-20040221.patch | 23.04 KB | TDobes |
Comments
Comment #1
moshe weitzman commentedI read this patch and like both its implementation and its functionality.
Comment #2
matt westgate commentedI find this most useful for taxonomy rendered pages, where I want to provide a brief explanation at the top for the current taxonomy term. It may also be nice to encapsulate these weighted nodes with unique CSS IDs, much like we do with blocks.
Comment #3
TDobes commentedmathias: I agree that outputting a CSS ID might be useful. However, because each theme implements its own theme_node function, this behavior is really decided in the theme.
In case we decide to set this up in the core themes, I've attached a quick patch that outputs a CSS ID of "node-weight-#" for each node, where # is the node's weight. Use of the hyphens is accepted, but in this case causes an awkward double-hyphen for negative weights. (for example, "node-weight--5" for a weight of -5) I'm not sure if this really bothers anyone or not, but I thought it'd be worthwhile to mention.
Note that this patch is an optional addition to (not a replacement for) my patch above.
Comment #4
moshe weitzman commentedREVIEW
- the functionality offerred here is terrific. this patch shows a lot of attention to detail. it is ready for commit IMO. but here are a few small improvement opportunities ...
- the 'Weight' select in the admin page looks odd because of its bold title. perhaps some css could fix override that.
- the up/down arrows on the admin/node page are wrapping to a new line (Firefox browser). some css could avoid that.
Comment #5
TDobes commented1. I assume you mean the bold title for the "node weight" dropdown when administering nodes. This is defined as bold in drupal.css (.form-item label), so this could probably be changed by CSS as well... I'm not sure how, though. Some quick googling seems to indicate that you can specify a class for a <label> tag, but I don't see a way to pass this to Drupal's form functions... If we're really bothered by this, it would warrant further investigation... I think the bold keeps this dropdown consistent with others throughout Drupal, however.
2. The up/down arrows in admin->content are meant to be on a separate line from the weight number. I did this because the display looked awkward (IMO) when they were directly next to it. If we'd like them on the same line, you can change the br in theme_node_weight_control (in node.module, line 1631) to a space. As this function is themable, it could be customized by the admin as well. For me (Linux - Firefox 20040212), the rows maintain the same height either way (with a space or a br), so I felt the interface was better this way.
Thanks for your positive comments and suggestions!
Comment #6
dries commentedI'm not sure 'node weights' are the way to go: I can think of many other ways to sort posts so maybe this is not the task of the node module, but of a specialized module (or theme) that can be replaced. Also, if it turns out node weights are the way to go, we should probably remove the static-flag from the
nodestable. I think this needs to mature a bit more before it can be committed.Comment #7
TDobes commentedHmmm... I'm not sure how I'd make a specialized module or theme modify the way core modules sort. I'd have to make a custom version of each core module in which I want modified sorting functionality. (taxonomy.module, blog.module, and forum.module, plus node.module for the front page) I'm certainly open to any suggestions as to how I could do this without needing to make a contrib version of these core modules.
As for the static flag, what would you propose should happen to nodes that are currently marked static? I'd suggest that their "promote to front page" tag should be marked to true, and they should be given a weight of -10. Thoughts?
Comment #8
moshe weitzman commentedI have to agree with tdobes about this being the best, global solution.
As for static nodes, I agree that we should set them to weight=-10 but don't touch their 'promoted to home page' bit. that is not implied by 'static'
Comment #9
TDobes commentedHere's an updated version of the patch. This version removes the "static on front page" option, and (using update.php) changes nodes whose static value was set to 1 to have a weight of -10. This patch also includes the CSS additions of the 2nd patch, and changes default/xtemplate.css such that it styles nodes whose weight is -10 as it styled static nodes. Any and all comments or suggestions are welcomed.
Comment #10
gatezone commentedIs this patch still working on current 4.4 cvs?
Is there any thing specific about applying this patch other than creating an update.php file with the patch text in the file and running it while logged in as the administrator of the site?
Has any other weighted node approach been included with 4.4? This and taxonomy/node permissions are biggies to any site I can imagine other than completely public content sites. -GZ
Comment #11
TDobes commentedgatezone: This is still a FEATURE REQUEST. Please do not set it otherwise. The patch has not landed yet, so this feature will not exist in 4.4. Hopefully, this patch or another with the same features will be in 4.5. Anyway, you should read Drupal's handbook page on diff and patch to learn how to use the patch. In particular, you'd type something like:
patch -p0 -u < node_weight-20040303.patchwhen in the Drupal directory.I've attached a new version of the patch which applies to Drupal CVS as of 20040303 (and should apply to the 4.4 RC as well). The only changes in this patch are that it (1.) works with the new updates.inc upgrade structure and (2.) updates the pushbutton xtemplate similarly to the default xtemplate.
I'd appreciate any kind words from those whom have tried the patch which might help this land in 4.5... or any suggestions as to a different method of adding the features this patch provides (if you don't like this method).
Comment #12
joe lombardo commentedI'd love the implementation chosen to be extensible enough to do some of the rankings described in this forum.
Cheers!
Comment #13
TDobes commentedjoe: Your ideas about an automatic ranking system are quite interesting. The purpose of my patch is primarily to allow admins to change the order of content... to reorder some nodes in an arbitrary fashion rather than chronologically. Therefore, it (by itself) does not provide the functions you're looking for.
However, I'm fairly certain that the features you're looking for could be accomplished as a module. If I find myself with some free time, I'll see if I can make a module to do this, as it seems like it would be useful for a lot of community sites.
Comment #14
TDobes commentedHere's yet another update to the patch just to keep it current with CVS HEAD. (post-4.4) It's been requested that I backport the patch to 4.3, so I've placed a 4.3 and 4.4 version in my sandbox.
As always, any and all suggestions or comments are appreciated. I really would like to see these features in the core for 4.5, even if they are not implemented exactly as I have set up. (I'm not giving up! ;-) )
Comment #15
TDobes commentedAs pointed out be Gerhard, CSS ID's should be unique, so we should use a class instead. This patch fixes that problem. I've updated the 4.3 and 4.4 versions as well.
Comment #16
dries commentedThe integration of the node weight drop-down menu in the node submission/edit form is rather intrusive.
What happens with book pages -- these nodes already have a weight?
Comment #17
zackp1 commentedIMO the ability to order nodes within a taxonomy term is critical to the many types of Drupal usage. For example I have a need to control the sequence of products node listings (created through the ecommerce module) when selected by product category.
I tried this patch and it works well ... thank you for your efforts and good work.
I do, however, have some reservations with your approach…
Adding a weight to each node could quickly become unmanageable...because …well…there will in most cases be too many nodes. The existence of 22 nodes or more would break the -10 to +10 edit dropdown approach. Of course the size of the dropdown could be increased, or a text box could be substituted….but my main issue centers around the unmanageability of a the ordering of a large number of nodes in this fashion.
I wonder that if this need might be better served by applying a weight to a node / taxonomy term combination, possibly by adding a weight field to the tax_node table.
IMO, increasing the granularity to the node/term level would serve to increase manageability.
After a cursory examination of the current code (pre the application of your patch) I must admit my suggestions are mostly theoretical at this point at least in terms of my willingness and/or ability to implement the change as I am suggesting. I believe the required code changes would be overly invasive to the taxonomy module and would throw me too far out of step with future releases unless it was accepted by the community.
Plus, I have my doubts that my current level of Drupal knowledge is sufficient for me to pull it off.
Also, I do understand that your patch addresses the general issue of node ordering as opposed to just ordering within a taxonomy term.
But I would like to ask if my concerns about the manageability of the current approach and the possible advantages of a more granular approach as outlined above finds any resonance with you or with other users?
Comment #18
moshe weitzman commentedThanks for taking an interest in this patch, Zackp1.
As you say, managing node weights at the term level makes little sense for many cases.
If manageability becomes a problem, someone will develop a Contrib module which sets the Weight according to some rules or other user interface. This patch is flexible enough to handle weights that range farther than -10 -> 10 and is flexible enough for other modules to set weights if they wish. I think manageability is important, but coding for it now is a premature.
Comment #19
TDobes commentedI'm taking this out of the patch queue for now... Interest has been lukewarm at best. I'll work on making a new patch at some point when I have more free time.
Comment #20
zardoz-1 commentedFWIW, I'm late to the conversation, but I am definately in need of this and would love to see it integrated into the core. I'll read up on applying patches and see if I can get it going, but it really does seem to be something of a necessity. If you aren't running a pure, slashdot-ish type of news site, you probably have content you'd like arranged in some sort of order, but also would like the flexibility of adding it in terms of a collection of stories. I just loaded the content into a new site without realizing the limitation of chronoligical ordering of stories. If I'd known of that, I would have loaded the stories differently. (Or I may have opted for another system with more flexibility.)
Comment #21
Bobum commentedI too am VERY interested in this patch. I am working with it now on a 4.4 install and having a few issues, but the concept is most needed! I hope this makes it in soon.
Comment #22
jonbob commentedApparently there's interest. This is active again.
Comment #23
nedjo+1 to introducing a weight for nodes. This is a well-considered patch.
A source of weighing issues is the hard-coding of sort order in taxonomy.module, e.g.,
Comments on some issues that have been raised:
1. This would interfere with node types (e.g., book) that already have a weight.
* Likely this could be addressed by simply removing the weight from book.module and using the new node one instead.
2. Weighing would be cumbersome where there were many nodes in a taxonomy.
* This sort of weighing is best used as an optional way of manually sorting a subset of posts--in other words, as a supplement to other default sorting.
Comment #24
stelman commentedI would love to see this for taxonomy views and forums.
Comment #25
joel_guesclin commentedThis is an interesting thread to me - I've been using taxonomy_context module to display terms with their dependent nodes (it actually uses taxonomy module functions to recover the nodes to display), and have been very perplexed by this problem:
- my site publishes articles which I normally want to publish in reverse chronological order with the newest at the top (fine: Drupal standard)
- however, I also want to bring certain articles together in a series, with the first in the series at the top (ie in chronological order), and the series are created using the taxonomy.
Using the weight solution would be a pain, because you have to modify all the articles you want in a series to change the weight. Takes a long time.
How about optionally associating sort orders with taxonomy terms? For example, for each vocabulary term I would specify the sort order for:
- created date
- sticky
- weight (have to add a weight column to node)
- title
- user id
- anything else that might seem useful
Then at the same time I would specify whether each criterion was to be sorted ASC or DESC.
Come to think of it, you could write a module along the lines of taxonomy_context which would add these settings to taxonomy terms. Then all you would need to do would be patch taxonomy.module to pass the "order by" as a parameter rather than using it fixed.
Hmmmmm.....
Comment #26
joel_guesclin commentedMy apologies... I hadn't realised I was going to change the title of the entire thread! Hope I've more or less put it back.
JG
Comment #27
thekenshow commentedThis patch is essential for my largest Drupal site, so I'm very interested in seeing it in the Drupal core. I expect it's a fair bit of work to migrating a patch like this from release to release, and that's why it's been withdrawn. Take this as my vote for getting this Ior something very much like it) implemented in Drupal.
Comment #28
tclineks commentedfwiw, I needed this functionality for a client and ported the patch to 4.6.3
had to change some things around, most notably with the node_admin_nodes -- wrote for functionality not beauty (quick dirty, possibly sloppy port)
Comment #29
Wubby commentedAny chance there is a version that patches 4.5.2? It's the only version installed by my ISP and I would really like this feature.
Comment #30
Julien PHAM commentedDoes this patch work with latest HEAD of drupal?
Thanks
Comment #31
tclineks commentedClosing, this should be fully addressed with Weight: http://drupal.org/node/35984
Comment #32
(not verified) commented