Is there a way to automatically set a weight to nodes in Drupal? I am wanting to achieve this, because I am creating a blog layout and I want the most recent articles to appear on the top of my secondary menu rather than on the bottom.
By trying to sort by a dynamically iterating weight field, you're adding complexity to something that is really quite straight forward. This scenario is best handled by sorting by the created, or updated date of the node. I mean, by definition, that will allow you to sort by the most recent article. Heck, even sorting by the node ID would be better, since you have a value that's automatically increasing for every item that's created.
A weight field should only be used when sorting needs to be empirical, like a todo list or something. If you're using a weight field because you want to adjust the sorting of an article later on, you would still get the desired result by sorting by multiple columns (i.e. weight ASC, created DESC).
Related
We are using the 2sxc module version 9.32.1 and the news-pro app version 3.1.
I am trying to make a view where I can show the items of 2 categories, but it seems I can only select one? And when I enable the function: Select more then one item, it will only show items for the first category selected.
How can I achieve this?
And I really want to connect user roles to the categories, and only show them when you are in then user role, how would I go about this?
I expect a list where I can show multiple category items.
and I expect a field with category where I can connect a user role to it.
I Sorency - it's best to put each question into a separate stack-overflow question, to keep things clean for future users who are looking for one. So I'll answer the initial question with multiple categories.
There are two ways to do this - one uses Visual Query, the other code. I will just give a general guide here:
With Visual Query https://2sxc.org/en/Learn/Visual-Query-Designer
1. First make sure you understand what it does, as I assume you haven't worked with it yet.
1. Look at how the first filter works - there you can either add more parameters (to allow multiple categories) or create a second stream with the additional filter, and then merge the results. So your query then has one list for the matches of the first parameter, and another match for the second parameter - and in the end it merges them together.
With Code you would do it in the razor file (CSHTML). There you would need to learn some LINQ and then work with the DataSource objects. This is much more technical, so I suggest you stick with the visual query for now.
In the Project Tracker template there is a feature where statistics for a certain project's items are displayed. You can filter the project items, but the statistics will only show those statistics for all the project items, i.e. the filters do not affect the statistics.
I would like to add the feature of filters affecting those statistics in a similar implementation of mine. My current solution passes the keys of those project items (affected by filters, too) to a calculated data source, which then calculates the statistics using those item keys, essentially applying the filters used in the page.
My issue is that my calculations are restricted by the query page size. For example, if I apply filters that limit the number of items to 15 records, but the page size is 10 records, I will only have statistics of those first 10 items, which is not useful. I'd need to have the statistics on all the records that are left after filtering.
One way to solve this would be to get rid of the query page size and leave it at 0. However, similarly to the Project Tracker template, I'm displaying the project items on the page in a table, and if I do that, the page becomes too heavy.
How can I circumvent the query page size? I'm thinking I could
limit the items displayed in the page by some other way than query page size (i.e. hiding items from the UI)
use a different datasource for the statistics, but in some way copying the filters used in the datasource that is displaying the project items
Both of these ways I could think of, I can't seem to implement. I don't know how I could hide items from the UI to make it less heavy, as query page size pretty much does it. I have also tried copying the filters from a datasource to a similar one, but that does not seem to work.
EDIT: I might have come up with a way to solve this myself, but I still need to implement it. Now I'm using the page size restricted Items Ds to apply the filters on, and the statistics are build from this data source. If instead, I use a non-restricted Ds called AllItems, and apply the filters on it, and then pass the item keys to a page size restricted Ds (to show the items in UI) AND to a calculated Ds (for the stats). Will make a response once I've verified it works.
I solved the issue myself.
To produce (refreshable) statistics subject to filtering but not restricted by page size, I used the following datasource structure:
In this structure, the filters practically flow to the data sources below, as they are passed the ItemKeys that fit the filter. What this completes is that my Statistics (used in piegraphs etc.) can be filtered dynamically and account for all the records that fit the filter, while the UI does not get crowded over too many records, as the data source used in UI has a query page size limitation.
I have a content type that references multiple nodes, and I need a way to sort the display of those referenced nodes.
Any ideas?
--- EDIT ---
Clarification:
I'm not using views, but rather am using my own queries.
I have a bunch of teachers (teacher content-type), and some conferences (conference content-type).
Within the conference content-type I want a node-reference field set to handle multiple teacher selections. But I need to be able to manually order them independently. What that means is that each individual conference needs to be able to sort the order of the particular teachers selected.
That's the ideal situation, but not the way I'm actually doing it.
What I'm ACTUALLY doing to jury-rig this thing is to have separate node-reference fields (teacher 1, teacher 2, teacher 3 etc.). Each node-reference field independent of the others.
It makes for a mess when it comes to creating views or composing db queries.
I know what I'm looking for is all but impossible, but I thought I'd run it by the Drupal gurus here anyway...
--- EDIT 2 ---
Further clarification:
Another way to do what I want, but is really impractical, is to create a separate nodequeue for each conference. Then you could select a handful of teachers associated with each conference and order them via the nodequeue. - That should help with visualizing the problem. But as a solution, it's even more messy (in terms of administration) than the one I'm currently using.
Also: I should mention that we're talking about 40 to 80 conferences, and 100-200 teachers. Just to get an idea of why I'm looking for a more elegant solution than the two I mentioned above.
Node reference with autocomplete widget gives you reordering capabilities when number of values set to 'unlimited'. Maybe not the most comfortable, but works.
I'm assuming you're using Views since you mentioned "displays". You can always change the order of the view fields from the Views UI but the order will be static (all items will have the same order).
If you want each item to have a potentially different order for the fields maybe you can set up a parent child relationship where the child item is ordered dynamically.
I have standard basic article content type which, amongst other things, contains an image field which is configured to contain an unlimited amount of values.
I'm now trying to create a view that lists some of the fields in this content type but I want to limit the number of images that are returned for this specific field to 3 random images in the list (or less). Is this something that can be achieved right in my view configuration or do I need to do something ninja? I'm not aware of everything that's possible php wise to "rewrite" / "filter" the results of my view but I'm confortable with anything programming related.
I'm using drupal-7 with Views 7.x-3.0-alpha1
Thanks!
AFAIK there is no way through the Views UI to randomize the selections of a grouped field.
I can see two possible ways, in theory to achieve what you want.
Use hook_views_query_alter to alter the SQL query for the view. I'm not sure Views support what you need to randomize the results, but you have the ability to alter the query that views generates, and might be able to randomize it.
Select all results, but using theming to only show the randomly selected options. This could be done in a preprocess function. Views provides several, depending on your display option, hook_views_view_unformatted might be what you need.
I have a CCK field price which the user can fill in. I would like to create a search form with dropdown price field with different ranges (such as below 100$, 100$-1000$, more than 1000$). The problem is that the user input is an integer so I cannot achieve range search using filter exposure. The user would have to specify the exact value to perform searching, but this is rather useless. Is there a way ( amodule, etc) to create ranges out of integer values so that the user is able to perform range based search?
Obviously people grab views and CCK for most solutions. But often a small module sith just a hook_menu(), a calback and a theme function will suffice.
In that callback you can perform whatever complex query you want.
Such modules, most of the time, contain less then 100 lines of PHP.
If you know PHP such a functionality might take you less then an hour to build. Whereas writing addons and behaviours for CCK and Views often costs much more.
The advantage of building views and CCK addons, is that your code is better re-usable.
The way I did it in the past was to use hook_form_alter to change that field to a select drop down range (a min and max drop down), then alter the views query if a value was provided.
The other way to do ranged facets would be to explore Apache Solr integration or Search Lucene facets. Keep in mind that its not exactly plug n play tech, though.
To sort out out your price into various categories you need to create a CCK Select list and then populate the list automatically using the Rules module. You need to also hide this select list using content permissions.
I've created a mini-case study on graphing using Rules & Views. As part of the mini case study, it shows you how to categorize the cost field using Rules -- which is precisely what you want. It also shows you how to hide the field using content permissions. Please check the below link for a video:
http://www.noparrots.com/content/mini-case-study-creating-a-bar-chart-in-drupal