Drupal only display certain content based on location - drupal

I need to be able to only display certain content/nodes based on where a user is located in the world. For example, if the user is from the US, they should see different results than someone from Europe.
Ideally I would be able to tag each node with the region(s) that it should be displayed in and then when the content is displayed, it is filtered by these tags.
I'm also going to be using various content 'scrollers' to display content and I would like these to have different content based on location as well.
How would I best achieve this?

Use Views - and cool modules like:
Use modules like smart_ip http://drupal.org/project/smart_ip & Ip Geolocation http://drupal.org/project/ip_geoloc
Read the info on those module pages they will help you get on the right track
Basically you want to first get the location of the user, this will be stored in the session.
once you have that you can reference it any time.

I know this is an old thread, but it's one that doesn't necessarily have an easy solution in Drupal. Here's how I did it. This solution doesn't match the original question exactly, but this explains a method that could be extended to cover that scenario by extending the PHP code to compare the user's location to the taxonomy term(s) assigned to each node.
First, install IP2Country. This allows you to match an IP address to someone's country by doing a geolocation lookup.
Second, use PHP code like this to determine if the visitor's IP address matches a certain country. This example returns true if the visitor is in the US or Canada, and false if they are not.
<?php
$detectedcountry = module_invoke('ip2country','get_country',$_SERVER['REMOTE_ADDR']);
$countries = array(
'US','CA'
);
if(in_array($detectedcountry,$countries)){
return true;
}
else return false;
?>
You can use this code in various places, but you will need to enable the PHP filter module for it to work.
In my solution, I used this code in two ways:
First, I created a Panels Variant for a Node Template (could be a Taxonomy Term template as well) to return a HTTP response rather than a Panel Pane. I used this code as a selection rule, so it would return a 404 if the user was not in a country that was allowed to see that specific node type. I then created Panels variant that returned the node page for anyone who qualified based on their location.
Second, I created a Panels variant for a node type (Product, in this case) and used the same PHP code to hide certain elements on the page for those users who weren't allowed to see them because of their location. In this case, I hid the Price and Add to Cart panes on a product display page. Visitors outside the allowed countries only saw the product information, and not the ecommerce elements on the page.
As a third option, you could also use it to show/hide Drupal blocks using the same code.
Finally, I created a custom theme function so I could show/hide individual menu items depending on a person's location. In this case, I wanted to hide the Shop menu item unless you were in the permitted countries. I wrote about how to do that in more detail here: https://fiveminutelessons.com/learn-drupal-sitebuilding/show-or-hide-menu-item-drupal-7-based-users-location

Related

Category with children organization: wordpress

Good day kind crew. I haBe a issue. what I am trying to do is this: a tennis league with 5 divisions. These 5 divisions are located in everytown and those towns in states. I am using ACF and pods. On the state archive page. We would like to choose the state and then on the specific state page we would see the divisions terms. And when you click the division you see all post from that tterm. We have a custom template for the taxonomy but want to limit how many template pages we need to create. If we go with categories than we have to make a custom template for every town/division. Any suggestions on best logic for this making it easy to use on front end without losing admin organization. We set up category hiearcy but we're looking for a better way because we need to allow for user to fill out form and populate post. At this point we have decided to use categories unless someone has another option. Categories just feel sloppy on admin side with children. Thanks for your time.
I'm not sure I understand the question, and thus am not sure I'm on the right track with this answer.
I think you're looking for towns/divisions to have content that can be customized by users. There may be a more WP specific way to do this, but a simple way would be to have a db table with these elements associated with the post id, for example post_id, town_desc, town_mascot, etc. Then, in the WP template, run a query to see if custom elements exist. If not, echo some default text, otherwise echo the custom element text from the db. I think I'd also have the default text be different based upon the level, i.e. with states, divisions, and towns all different based on their level.
Your answer might lie in simply working with custom fields, perhaps with
https://wordpress.org/support/article/custom-fields/

Concrete5: index external links and show in search results of search box

In Concrete5, how can I enable external links to 1) be indexed, and 2) show up in the search results, using the search block. I guess point 2 will automatically happen when 1 works?
Unfortunately there is no way to tap into the C5 search index in any way other than via blocks on a page or page properties (custom attributes). This means you cannot add external links to the search index in C5 because the pages that are linked to are not part of your site and hence have no concrete5 blocks on them, and also you can't set custom attributes on external links (although actually there is a roundabout way to do so, via the "Page Search" dashboard page -- but I have a feeling this is a bug in the system because setting those attributes doesn't actually do anything as far as I can tell).
The concrete5 search index goes over blocks which are included in concrete5 pages and looks in their BlockController instances for indexable content.
In detail, it does these two things:
Checks which areas are searchable. The areas can be configured in
your concrete5 dashboard at Systems and Settings > SEO and
Statistics > Search Index
It goes through all blocks in these areas, and looks for the
function getSearchableContent() in your block controller.
Whatever this function returns will be indexed, and then it will
show up in the search if the MySql like search matches it or other
strings from blocks on the same page.
Look for this function, or add it if it's not there
public function getSearchableContent() {
return $this->yourTitle . ': ' . $this->yourExternalLink;
}

Views and Categories...?

it's about this page: http://veagues.com/
Hey guys,
I've made a block-view with drupal that let's me sort my videos by a certain category, in this case "funny","epic","plays", "contest"...
The problem is: When you sort it by the certain category and click on a video and continue to click the "next" button, you will go threw all videos, instead of only the videos of the category...
My Question is: How can I put a filter on the nodes when i apply another category on the bottom block?
Thanks already!
If you're using Views, you should be able to filter the main block by the same taxonomy term.
Try adding a Contextual Filter to that block too. If there's a taxonomy term ID in the URL the block gets filtered by that Term ID and if there's no result, the block shows all the videos.
EDIT -----------------------------------------------------------------------------------------
You may need to try & understand what goes on when you make a selection in Drupal.
1/ The taxonomy term page will list all the content affixed with a specific term. The term tid can be seen in the URL, unless an alias have been created. A block can retrieve that term id, whether there is an alias or not.
2/ The node page will give you access to a specific node, but any block on that page should be able to access the term id of that specific node.
If you know where you are, it becomes easier to retrieve the info you're looking for. On the other hand, you may have to reconfigure a specific page in order to add the necessary extra block...
That can be done with templates but you could also have a look at Panels.
The Panels UI makes it easier to configure the page you're looking for without having to mess with code or templates, or both.
There's a lot of free video tutorials out there, search for Views & Panels.
If you want to have a look at preprocess functions, you will definitely need to download the Devel module...
...but have a look at these sites first:
http://codekarate.com/
http://drupalize.me/
http://buildamodule.com

How to provide a button which will change my current page content to an previous page in drupal

I'm making a site wherein I want to show the current course that I'm gonna teach to my pupils.In this page there should also be links provided to my previous courses. Now when I'm done with this course I want to transfer it to a previous course or rather automatically create a link for it and get the new course content in it's place. I just think doing manually is kind of stupid. Rather I want to have a form where i can create my new course then click on make current course as previous and this course as new whenever i wish.How can I do this.Is this even possible
Pretty open question ... One way would be to work with views when showing a node.
In the view you should use a custom php field, which collects the record (nid) within the course-node table. And then create a link using the drupal path_alias function or by using node/nid ...
You could use panels-module as well. Where you have a view with the latest course, and under the latest course you have a view of a link to the latest course -1 . (I think you can set an offset in views to get the previous course) The view should accept an argument, namely the nid of the currently loaded node.
If you use this method, do check if your panels is giving the arguments to the views module.
Another way would be to use node reference as to what is the previous course (but you don't want it to be manual). The advantage of node_reference is that you don't need to enter your courses in a certain order. If you make it automatically, then the order in which you fill in the courses should be correct.
Easy man. Just create a content type called "course" and using CCK, add all the fields to capture information you want about the course.
Now you have the content. Using Views, create a simple view page displaying course content type and sort it on descending order, set it to display one item at a time and add a mini pager. That way the new course will be the first one displayed and the other ones will be behind it. You might need to customize the pager a bit ^^

How can I set the user selected value of an exposed location Views filter for the entire Drupal 6 website?

I am currently working on a website which lists the businesses as per either their location or the category to which it belongs. Check: http://frugalmillionaire.net/
Existing Functionality implemented (Views, CCK and Taxonomy):
On clicking the Primary Menu Links the Business Category are passed as an argument to the View. Hence the view displays the business listings of the specific category only. Also to implement the Find Local Coupons Block ; a filter of the same view is exposed in a block.
My client wants to give the user the option to set his/her location on the website . Once the user sets that location then upon clicking the links in the primary menu (Restaurant) should list only the restaurants which are of the location set. Similarly clicking on any of the primary menu links should display of the businesses of the location set only.
Potential ways to do it :
1)Set the value selected by the user in the exposed filter. How can this be done?
2) Using Cookies. Can I use the Drupal Cookie to somehow achieve this?
Kindly help me out .
Any help/pointers/relevant links would be deeply appreciated.
Thanks
I think you are asking three different things.
1. How do you get location information from the current user and store it?
If the user is setting and forgetting their location, make a Profile Field. The Location module might be of help. If the user just types in a location for temporary usage, save it to their session.
2. How do you theme a site based on the user's location?
hook_menu_alter() can be used to change what your primary links are doing based on user data.
3. How do you preload the business Views based on this location?
Invoke the View programmatically,
where location information (when
available) is inserted in place of
the exposed filters. Useful Views Documentation.
Set the relevant information in your
View with Arguments. Set the default
to the user's location. Because you are relying on a dynamic default, you never need to send a "real" argument to the view.

Resources