New Post has been published on http://nzbusinessdirectory.info/webdesign/is-your-responsive-design-working-google-analytics-will-tell-you/Is Your Responsive Design Working? Google Analytics Will Tell YouBy  Jon Arne Sæterås and Luca Passani

Responsive web design has become the dominant method of developing and designing websites. It makes it easier to think “mobile first” and to create a website that is viewable on mobile devices.
In the early days of responsive web design, creating breakpoints in CSS for particular screen sizes was common, like 320 pixels for iPhone and 768 pixels for iPad, and then we tested and monitored those devices. As responsive design has evolved, we now more often start with the content and then set breakpoints when the content “breaks.” This means that you might end up with quite a few content-centric breakpoints and no particular devices or form factors on which to test your website.
However, we are just guessing that our designs will perform well with different device classes and form factors and across different interaction models. We need to continually monitor a design’s performance with real traffic.
Content-centric breakpoints are definitely the way to go, but they also mean that monitoring your website to identify when it breaks is more important. This information, when easily accessible, provides hints on what types of devices and form factors to test further.
Google Analytics has some great multi-device features1 built in; however, with responsive design, we are really designing for form factors, not for devices. In this article, we’ll demonstrate how WURFL.js2 and Google Analytics can work together to show performance metrics across form factors. No more guessing.
Why Form Factor?
Speeding up and optimizing the user experience for a particular device or family of devices is always easier. In reality, though, creating a device-specific experience3 for all types of devices is not feasible, given that the diversity of web-enabled devices will just continue to grow. However, every device has a particular form factor. Luke Wroblewski4, author of Mobile First5, outlines three categories to identify device experiences6:
usage or posture,
input method,
output or screen.
Because devices vary between these categories, we get different form factors. Hence, treating form factor as the primary dimension through which to monitor a responsive website makes sense. This will indicate which type of device to test for usability.
The examples in this article all use WURFL.js, including the form factors provided by it, which are:
desktop,
app,
tablet,
smartphone,
feature phone,
smart TV,
robot,
other non-mobile,
other mobile.
Feeding Data To Google Analytics
The first step is to put WURFL.js on the pages that you want to track. Simply paste this line of code into your markup:
<script type="text/javascript" src="//wurfl.io/wurfl.js"></script>

This will create a global WURFL object that you can access through JavaScript:
console.log(WURFL.form_factor);

Now that the script tag is in place, the only other thing to do is add the highlighted lines of code to Google Analytics’ tracking code:
/* Google Analytics' standard tracking code */
_gaq.push(['_setAccount', 'UA-99999999-1']);
_gaq.push(['_setDomainName', example.com']);
_gaq.push(['_trackPageview']);

/* Tell Google Analytics to log WURFL.js' data */
 _gaq.push(['_setCustomVar',	1,'complete_device_name',WURFL.complete_device_name,1]);
 _gaq.push(['_setCustomVar',	2,'form_factor',WURFL.form_factor,1]);
 _gaq.push(['_setCustomVar',	3,'is_mobile',WURFL.is_mobile,1]);

/* The rest of Analytics' standard tracking code */
(function() 
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
)();

Or, if you have updated to Google Analytics’ new “Universal Analytics7“, you would add this:
/* Google Analytics' new universal tracking code */
(function(i,s,o,g,r,a,m)function(),i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m))(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-99999999-1, 'auto');

/* Define the custom dimensions */
ga('send', 'pageview', 
  'dimension1': WURFL.complete_device_name,
  'dimension2': WURFL.form_factor,
  'dimension3': WURFL.is_mobile
);


Further, if you are using GA Universal Analytics, you must remember to define the custom dimensions. You do that by clicking Admin → Custom Definitions → Custom Dimensions.
8For Universal Analytics you need to define the custom dimensions in the Admin section. (Large preview9)Analyzing The Data In Google Analytics
Now that the data is in Google Analytics, we need to make it available for inspection. We can use custom variables in Analytics in a number of ways, the most obvious being to look in the menu on the left and click Audience → Custom → Custom Variables:
10“Custom Variables” report. (Large version11)If you are are using Universal Analytics, you’ll have the custom dimensions available as any other dimension in all reports in GA:
12Accessing custom dimensions. (Large preview13)Already, we’re getting a pretty good picture of how form factors behave differently. The best metrics to focus on will obviously depend on your website, but in general, pay attention to bounce rate and pages per visit.
Big Picture With Dashboard Widgets
With dashboards14 in Google Analytics, we get a high-level overview of the most important metrics. This is a good place to monitor how your website performs across form factors. Once again, bounce rate and page impressions per visit are good metrics to start with. The purpose of the dashboard widgets is to alert you and to visualize how your website’s performance changes for certain form factors.
Let’s create a few widgets to display the status of different form factors. First, create a pie-chart widget that shows how much your website is being used by different form factors.
15Widget displaying form factors. (Large version16)In the Dashboard, click Add Widget, select Pie, then the Sessions metric, and group it by the form factor custom variable. Note that the label in the green drop-down list is Custom Variables, not the actual name. In our example, the form factor variable is in the second slot, but make sure to choose the right slot if you’ve implemented it in a different order. Again, if you have converted to Universal analytics, the procedure is similar, but in stead of selecting custom variables, you simply add the name of your custom dimension as you would with any other dimension.
Next, create a few widgets to display visits and bounce rates17 per form factor. The widgets will indicate whether changes to the website have had a positive or negative impact. Obviously, you want higher visits and a lower bounce rate.
18Creating a “form factor” widget. (Larger version19)Create this widget by adding a filter to the standard metrics. Choose a timeline diagram and filter the data with your custom variable where you have stored the form factor. Create one widget for each of the form factors that you want to monitor:
20“Form factor” widgets in the dashboard. (Large version21)You might find that some form factors disappear in the statistics for global bounce rates because the data set is now bigger (as in the example above). As indicated by the red arrows, something dramatic has happened with smartphones and feature phones. Specifically, some changes were made to the landing page to increase traffic from tablets, and the changes clearly had a negative impact on traffic from smartphones and feature phones. Identifying the reason for the drop in traffic requires more fine-grained Analytics reports, and the drop might not have been easy to spot without having monitored form factors.
Form Factor Segments
Any custom variable that you put into Google Analytics is, of course, available in most reports as filters or dimensions, so tweaking them to your needs is quite easy. Another way to keep form factors at the top of mind is to put them in segments22 by creating conditions. Here is one segment per form factor that you’ll want to track:
23Configure a segment. If you’re using Universal Analytics, you must use your custom dimensions rather than the custom variables. (Large version24)The same, but in Universal Analytics:
25(Large preview26)Google Analytics will show these segments in most of its standard reports as separate dimensions in charts and tables:
27Segments chart. (Large version28)You can make “form factor” a dimension in most reports. As mentioned, bounce rate and general engagement are key metrics to follow, but goals and conversion rate are obviously interesting, too. You might find the need to create new goals or at least review your funnel for certain form factors.
After monitoring form factors for a while, you might conclude that you need to offer different user experiences for one or more form factors. Furthermore, you might need to tweak goals, funnels and advertising campaigns to account for differences in usage per form factor or device type.
We have used Google Analytics here, but WURFL.js is, of course, compatible with other analytics tools, as long as custom variables like the ones above are allowed.
Conclusion
In this article, we have looked at how performance per form factor is a key metric for monitoring a website and how WURFL.js and Google Analytics help to visualize this data. Once you put WURFL.js’ data into Analytics, it will be available in most standard reports as filters or dimensions, so tweaking the reports to your needs is quite straightforward. And the dashboard widgets will give you a high-level overview of their status. Also, bounce rate and page impressions per visit are key metrics, at least to start; so, defining form factors as segments will give you nice visualizations in most standard reports.
As a next step, look into conversions and goals in Google Analytics to see how to integrate and monitor form factors, which will vary according to the website’s function and purpose. To give you a head start, we have made a template that you can install29 in your Google Analytics dashboard (This template uses custom variables, not custom dimensions). Just follow the instructions to assign an Analytics property, which will then appear under Dashboards → Private.
(al, ml, il)
Footnotes
1 http://www.smashingmagazine.com/2014/03/03/how-to-use-analytics-to-build-a-smarter-mobile-website/
2 http://wurfl.io
3 https://developers.facebook.com/blog/post/2012/01/24/device-experiences—responsive-design/
4 http://www.lukew.com/
5 http://www.lukew.com/resources/mobile_first.asp
6 https://developers.facebook.com/blog/post/2012/01/24/device-experiences—responsive-design/
7 https://support.google.com/analytics/answer/2790010?hl=en
8 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomdim-large-opt.png
9 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomdim-large-opt.png
10 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image01-large-opt.png
11 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image01-large-opt.png
12 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAUIcustomdim-large-opt.png
13 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAUIcustomdim-large-opt.png
14 https://support.google.com/analytics/answer/1068216?hl=en
15 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image05-large-opt.png
16 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image05-large-opt.png
17 https://support.google.com/analytics/answer/1009409?hl=en
18 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image00-large-opt.png
19 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image00-large-opt.png
20 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image04-large-opt.png
21 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image04-large-opt.png
22 https://support.google.com/analytics/topic/3123779?hl=en&ref_topic=1727148
23 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image03-large-opt.png
24 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image03-large-opt.png
25 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomin2-large-opt.png
26 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomin2-large-opt.png
27 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image02-large-opt.png
28 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image02-large-opt.png
29 https://www.google.com/analytics/web/template?uid=gUP6PNubRZ6qlqhq4M2g2Q
The post Is Your Responsive Design Working? Google Analytics Will Tell You appeared first on Smashing Magazine.
Source: Smashing Magazine
    

New Post has been published on http://nzbusinessdirectory.info/webdesign/is-your-responsive-design-working-google-analytics-will-tell-you/

Is Your Responsive Design Working? Google Analytics Will Tell You

By Jon Arne Sæterås and Luca Passani

GAcustomdim-preview-opt

Responsive web design has become the dominant method of developing and designing websites. It makes it easier to think “mobile first” and to create a website that is viewable on mobile devices.

In the early days of responsive web design, creating breakpoints in CSS for particular screen sizes was common, like 320 pixels for iPhone and 768 pixels for iPad, and then we tested and monitored those devices. As responsive design has evolved, we now more often start with the content and then set breakpoints when the content “breaks.” This means that you might end up with quite a few content-centric breakpoints and no particular devices or form factors on which to test your website.

However, we are just guessing that our designs will perform well with different device classes and form factors and across different interaction models. We need to continually monitor a design’s performance with real traffic.

Content-centric breakpoints are definitely the way to go, but they also mean that monitoring your website to identify when it breaks is more important. This information, when easily accessible, provides hints on what types of devices and form factors to test further.

Google Analytics has some great multi-device features1 built in; however, with responsive design, we are really designing for form factors, not for devices. In this article, we’ll demonstrate how WURFL.js2 and Google Analytics can work together to show performance metrics across form factors. No more guessing.

Why Form Factor?

Speeding up and optimizing the user experience for a particular device or family of devices is always easier. In reality, though, creating a device-specific experience3 for all types of devices is not feasible, given that the diversity of web-enabled devices will just continue to grow. However, every device has a particular form factor. Luke Wroblewski4, author of Mobile First5, outlines three categories to identify device experiences6:

  • usage or posture,
  • input method,
  • output or screen.

Because devices vary between these categories, we get different form factors. Hence, treating form factor as the primary dimension through which to monitor a responsive website makes sense. This will indicate which type of device to test for usability.

The examples in this article all use WURFL.js, including the form factors provided by it, which are:

  • desktop,
  • app,
  • tablet,
  • smartphone,
  • feature phone,
  • smart TV,
  • robot,
  • other non-mobile,
  • other mobile.

Feeding Data To Google Analytics

The first step is to put WURFL.js on the pages that you want to track. Simply paste this line of code into your markup:

<script type="text/javascript" src="//wurfl.io/wurfl.js"></script>

This will create a global WURFL object that you can access through JavaScript:

console.log(WURFL.form_factor);

Now that the script tag is in place, the only other thing to do is add the highlighted lines of code to Google Analytics’ tracking code:

/* Google Analytics' standard tracking code */
_gaq.push(['_setAccount', 'UA-99999999-1']);
_gaq.push(['_setDomainName', example.com']);
_gaq.push(['_trackPageview']);

/* Tell Google Analytics to log WURFL.js' data */
 _gaq.push(['_setCustomVar',	1,'complete_device_name',WURFL.complete_device_name,1]);
 _gaq.push(['_setCustomVar',	2,'form_factor',WURFL.form_factor,1]);
 _gaq.push(['_setCustomVar',	3,'is_mobile',WURFL.is_mobile,1]);

/* The rest of Analytics' standard tracking code */
(function() 
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
)();

Or, if you have updated to Google Analytics’ new “Universal Analytics7, you would add this:

/* Google Analytics' new universal tracking code */
(function(i,s,o,g,r,a,m)function(),i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m))(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-99999999-1, 'auto');

/* Define the custom dimensions */
ga('send', 'pageview', 
  'dimension1': WURFL.complete_device_name,
  'dimension2': WURFL.form_factor,
  'dimension3': WURFL.is_mobile
);

Further, if you are using GA Universal Analytics, you must remember to define the custom dimensions. You do that by clicking AdminCustom DefinitionsCustom Dimensions.

8
For Universal Analytics you need to define the custom dimensions in the Admin section. (Large preview9)

Analyzing The Data In Google Analytics

Now that the data is in Google Analytics, we need to make it available for inspection. We can use custom variables in Analytics in a number of ways, the most obvious being to look in the menu on the left and click AudienceCustomCustom Variables:

10
“Custom Variables” report. (Large version11)

If you are are using Universal Analytics, you’ll have the custom dimensions available as any other dimension in all reports in GA:

GAUIcustomdim-preview-opt12
Accessing custom dimensions. (Large preview13)

Already, we’re getting a pretty good picture of how form factors behave differently. The best metrics to focus on will obviously depend on your website, but in general, pay attention to bounce rate and pages per visit.

Big Picture With Dashboard Widgets

With dashboards14 in Google Analytics, we get a high-level overview of the most important metrics. This is a good place to monitor how your website performs across form factors. Once again, bounce rate and page impressions per visit are good metrics to start with. The purpose of the dashboard widgets is to alert you and to visualize how your website’s performance changes for certain form factors.

Let’s create a few widgets to display the status of different form factors. First, create a pie-chart widget that shows how much your website is being used by different form factors.

Widget displaying form factors15
Widget displaying form factors. (Large version16)

In the Dashboard, click Add Widget, select Pie, then the Sessions metric, and group it by the form factor custom variable. Note that the label in the green drop-down list is Custom Variables, not the actual name. In our example, the form factor variable is in the second slot, but make sure to choose the right slot if you’ve implemented it in a different order. Again, if you have converted to Universal analytics, the procedure is similar, but in stead of selecting custom variables, you simply add the name of your custom dimension as you would with any other dimension.

Next, create a few widgets to display visits and bounce rates17 per form factor. The widgets will indicate whether changes to the website have had a positive or negative impact. Obviously, you want higher visits and a lower bounce rate.

Creating a “form factor” widget18
Creating a “form factor” widget. (Larger version19)

Create this widget by adding a filter to the standard metrics. Choose a timeline diagram and filter the data with your custom variable where you have stored the form factor. Create one widget for each of the form factors that you want to monitor:

“Form factor” widgets in the dashboard20
“Form factor” widgets in the dashboard. (Large version21)

You might find that some form factors disappear in the statistics for global bounce rates because the data set is now bigger (as in the example above). As indicated by the red arrows, something dramatic has happened with smartphones and feature phones. Specifically, some changes were made to the landing page to increase traffic from tablets, and the changes clearly had a negative impact on traffic from smartphones and feature phones. Identifying the reason for the drop in traffic requires more fine-grained Analytics reports, and the drop might not have been easy to spot without having monitored form factors.

Form Factor Segments

Any custom variable that you put into Google Analytics is, of course, available in most reports as filters or dimensions, so tweaking them to your needs is quite easy. Another way to keep form factors at the top of mind is to put them in segments22 by creating conditions. Here is one segment per form factor that you’ll want to track:

Configure a segment23
Configure a segment. If you’re using Universal Analytics, you must use your custom dimensions rather than the custom variables. (Large version24)

The same, but in Universal Analytics:

GAcustomin2-preview-opt25
(Large preview26)

Google Analytics will show these segments in most of its standard reports as separate dimensions in charts and tables:

Segments chart27
Segments chart. (Large version28)

You can make “form factor” a dimension in most reports. As mentioned, bounce rate and general engagement are key metrics to follow, but goals and conversion rate are obviously interesting, too. You might find the need to create new goals or at least review your funnel for certain form factors.

After monitoring form factors for a while, you might conclude that you need to offer different user experiences for one or more form factors. Furthermore, you might need to tweak goals, funnels and advertising campaigns to account for differences in usage per form factor or device type.

We have used Google Analytics here, but WURFL.js is, of course, compatible with other analytics tools, as long as custom variables like the ones above are allowed.

Conclusion

In this article, we have looked at how performance per form factor is a key metric for monitoring a website and how WURFL.js and Google Analytics help to visualize this data. Once you put WURFL.js’ data into Analytics, it will be available in most standard reports as filters or dimensions, so tweaking the reports to your needs is quite straightforward. And the dashboard widgets will give you a high-level overview of their status. Also, bounce rate and page impressions per visit are key metrics, at least to start; so, defining form factors as segments will give you nice visualizations in most standard reports.

As a next step, look into conversions and goals in Google Analytics to see how to integrate and monitor form factors, which will vary according to the website’s function and purpose. To give you a head start, we have made a template that you can install29 in your Google Analytics dashboard (This template uses custom variables, not custom dimensions). Just follow the instructions to assign an Analytics property, which will then appear under DashboardsPrivate.

(al, ml, il)

Footnotes

  1. 1 http://www.smashingmagazine.com/2014/03/03/how-to-use-analytics-to-build-a-smarter-mobile-website/
  2. 2 http://wurfl.io
  3. 3 https://developers.facebook.com/blog/post/2012/01/24/device-experiences—responsive-design/
  4. 4 http://www.lukew.com/
  5. 5 http://www.lukew.com/resources/mobile_first.asp
  6. 6 https://developers.facebook.com/blog/post/2012/01/24/device-experiences—responsive-design/
  7. 7 https://support.google.com/analytics/answer/2790010?hl=en
  8. 8 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomdim-large-opt.png
  9. 9 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomdim-large-opt.png
  10. 10 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image01-large-opt.png
  11. 11 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image01-large-opt.png
  12. 12 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAUIcustomdim-large-opt.png
  13. 13 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAUIcustomdim-large-opt.png
  14. 14 https://support.google.com/analytics/answer/1068216?hl=en
  15. 15 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image05-large-opt.png
  16. 16 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image05-large-opt.png
  17. 17 https://support.google.com/analytics/answer/1009409?hl=en
  18. 18 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image00-large-opt.png
  19. 19 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image00-large-opt.png
  20. 20 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image04-large-opt.png
  21. 21 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image04-large-opt.png
  22. 22 https://support.google.com/analytics/topic/3123779?hl=en&ref_topic=1727148
  23. 23 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image03-large-opt.png
  24. 24 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image03-large-opt.png
  25. 25 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomin2-large-opt.png
  26. 26 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomin2-large-opt.png
  27. 27 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image02-large-opt.png
  28. 28 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image02-large-opt.png
  29. 29 https://www.google.com/analytics/web/template?uid=gUP6PNubRZ6qlqhq4M2g2Q

The post Is Your Responsive Design Working? Google Analytics Will Tell You appeared first on Smashing Magazine.

Source: Smashing Magazine

    

New Post has been published on http://freesourcecode.info/is-your-responsive-design-working-google-analytics-will-tell-you/Is Your Responsive Design Working? Google Analytics Will Tell YouBy  Jon Arne Sæterås and Luca Passani

Responsive Web design has become the dominant method of developing and designing websites. It makes it easier to think “mobile first” and to create a website that is viewable on mobile devices.
In the early days of responsive Web design, creating breakpoints in CSS for particular screen sizes was common, like 320 pixels for iPhone and 768 pixels for iPad, and then we tested and monitored those devices. As responsive design has evolved, we now more often start with the content and then set breakpoints when the content “breaks.” This means that you might end up with quite a few content-centric breakpoints and no particular devices or form factors on which to test your website.
However, we are just guessing that our designs will perform well with different device classes and form factors and across different interaction models. We need to continually monitor a design’s performance with real traffic.
Content-centric breakpoints are definitely the way to go, but they also mean that monitoring your website to identify when it breaks is more important. This information, when easily accessible, provides hints on what types of devices and form factors to test further.
Google Analytics has some great multi-device features1 built in; however, with responsive design, we are really designing for form factors, not for devices. In this article, we’ll demonstrate how WURFL.js2 and Google Analytics can work together to show performance metrics across form factors. No more guessing.
Why Form Factor?
Speeding up and optimizing the user experience for a particular device or family of devices is always easier. In reality, though, creating a device-specific experience3 for all types of devices is not feasible, given that the diversity of Web-enabled devices will just continue to grow. However, every device has a particular form factor. Luke Wroblewski4, author of Mobile First5, outlines three categories to identify device experiences6:
usage or posture,
input method,
output or screen.
Because devices vary between these categories, we get different form factors. Hence, treating form factor as the primary dimension through which to monitor a responsive website makes sense. This will indicate which type of device to test for usability.
The examples in this article all use WURFL.js, including the form factors provided by it, which are:
desktop,
app,
tablet,
smartphone,
feature phone,
smart TV,
robot,
other non-mobile,
other mobile.
Feeding Data To Google Analytics
The first step is to put WURFL.js on the pages that you want to track. Simply paste this line of code into your markup:
&lt;script type="text/javascript" src="//wurfl.io/wurfl.js"&gt;&lt;/script&gt;

This will create a global WURFL object that you can access through JavaScript:
console.log(WURFL.form_factor);

Now that the script tag is in place, the only other thing to do is add the highlighted lines of code to Google Analytics’ tracking code:
/* Google Analytics' standard tracking code */
_gaq.push(['_setAccount', 'UA-99999999-1']);
_gaq.push(['_setDomainName', example.com']);
_gaq.push(['_trackPageview']);

/* Tell Google Analytics to log WURFL.js' data */
 _gaq.push(['_setCustomVar',	1,'complete_device_name',WURFL.complete_device_name,1]);
 _gaq.push(['_setCustomVar',	2,'form_factor',WURFL.form_factor,1]);
 _gaq.push(['_setCustomVar',	3,'is_mobile',WURFL.is_mobile,1]);

/* The rest of Analytics' standard tracking code */
(function() 
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
)();

Or, if you have updated to Google Analytics’ new “Universal Analytics7“, you would add this:
/* Google Analytics' new universal tracking code */
(function(i,s,o,g,r,a,m)i['GoogleAnalyticsObject']=r;i[r]=i[r])(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-99999999-1, 'auto');

/* Define the custom dimensions */
ga('send', 'pageview', 
  'dimension1': WURFL.complete_device_name,
  'dimension2': WURFL.form_factor,
  'dimension3': WURFL.is_mobile
);


Further, if you are using GA Universal Analytics, you must remember to define the custom dimensions. You do that by clicking Admin → Custom Definitions → Custom Dimensions.
8For Universal Analytics you need to define the custom dimensions in the Admin section. (Large preview9)Analyzing The Data In Google Analytics
Now that the data is in Google Analytics, we need to make it available for inspection. We can use custom variables in Analytics in a number of ways, the most obvious being to look in the menu on the left and click Audience → Custom → Custom Variables:
10“Custom Variables” report. (Large version11)If you are are using Universal Analytics, you’ll have the custom dimensions available as any other dimension in all reports in GA:
12Accessing custom dimensions. (Large preview13)Already, we’re getting a pretty good picture of how form factors behave differently. The best metrics to focus on will obviously depend on your website, but in general, pay attention to bounce rate and pages per visit.
Big Picture With Dashboard Widgets
With dashboards14 in Google Analytics, we get a high-level overview of the most important metrics. This is a good place to monitor how your website performs across form factors. Once again, bounce rate and page impressions per visit are good metrics to start with. The purpose of the dashboard widgets is to alert you and to visualize how your website’s performance changes for certain form factors.
Let’s create a few widgets to display the status of different form factors. First, create a pie-chart widget that shows how much your website is being used by different form factors.
15Widget displaying form factors. (Large version16)In the Dashboard, click Add Widget, select Pie, then the Sessions metric, and group it by the form factor custom variable. Note that the label in the green drop-down list is Custom Variables, not the actual name. In our example, the form factor variable is in the second slot, but make sure to choose the right slot if you’ve implemented it in a different order. Again, if you have converted to Universal analytics, the procedure is similar, but in stead of selecting custom variables, you simply add the name of your custom dimension as you would with any other dimension.
Next, create a few widgets to display visits and bounce rates17 per form factor. The widgets will indicate whether changes to the website have had a positive or negative impact. Obviously, you want higher visits and a lower bounce rate.
18Creating a “form factor” widget. (Larger version19)Create this widget by adding a filter to the standard metrics. Choose a timeline diagram and filter the data with your custom variable where you have stored the form factor. Create one widget for each of the form factors that you want to monitor:
20“Form factor” widgets in the dashboard. (Large version21)You might find that some form factors disappear in the statistics for global bounce rates because the data set is now bigger (as in the example above). As indicated by the red arrows, something dramatic has happened with smartphones and feature phones. Specifically, some changes were made to the landing page to increase traffic from tablets, and the changes clearly had a negative impact on traffic from smartphones and feature phones. Identifying the reason for the drop in traffic requires more fine-grained Analytics reports, and the drop might not have been easy to spot without having monitored form factors.
Form Factor Segments
Any custom variable that you put into Google Analytics is, of course, available in most reports as filters or dimensions, so tweaking them to your needs is quite easy. Another way to keep form factors at the top of mind is to put them in segments22 by creating conditions. Here is one segment per form factor that you’ll want to track:
23Configure a segment. If you’re using Universal Analytics, you must use your custom dimensions rather than the custom variables. (Large version24)The same, but in Universal Analytics:
25(Large preview26)Google Analytics will show these segments in most of its standard reports as separate dimensions in charts and tables:
27Segments chart. (Large version28)You can make “form factor” a dimension in most reports. As mentioned, bounce rate and general engagement are key metrics to follow, but goals and conversion rate are obviously interesting, too. You might find the need to create new goals or at least review your funnel for certain form factors.
After monitoring form factors for a while, you might conclude that you need to offer different user experiences for one or more form factors. Furthermore, you might need to tweak goals, funnels and advertising campaigns to account for differences in usage per form factor or device type.
We have used Google Analytics here, but WURFL.js is, of course, compatible with other analytics tools, as long as custom variables like the ones above are allowed.
Conclusion
In this article, we have looked at how performance per form factor is a key metric for monitoring a website and how WURFL.js and Google Analytics help to visualize this data. Once you put WURFL.js’ data into Analytics, it will be available in most standard reports as filters or dimensions, so tweaking the reports to your needs is quite straightforward. And the dashboard widgets will give you a high-level overview of their status. Also, bounce rate and page impressions per visit are key metrics, at least to start; so, defining form factors as segments will give you nice visualizations in most standard reports.
As a next step, look into conversions and goals in Google Analytics to see how to integrate and monitor form factors, which will vary according to the website’s function and purpose. To give you a head start, we have made a template that you can install29 in your Google Analytics dashboard (This template uses custom variables, not custom dimensions). Just follow the instructions to assign an Analytics property, which will then appear under Dashboards → Private.
(al, ml, il)
Footnotes
1 http://www.smashingmagazine.com/2014/03/03/how-to-use-analytics-to-build-a-smarter-mobile-website/
2 http://wurfl.io
3 https://developers.facebook.com/blog/post/2012/01/24/device-experiences—responsive-design/
4 http://www.lukew.com/
5 http://www.lukew.com/resources/mobile_first.asp
6 https://developers.facebook.com/blog/post/2012/01/24/device-experiences—responsive-design/
7 https://support.google.com/analytics/answer/2790010?hl=en
8 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomdim-large-opt.png
9 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomdim-large-opt.png
10 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image01-large-opt.png
11 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image01-large-opt.png
12 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAUIcustomdim-large-opt.png
13 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAUIcustomdim-large-opt.png
14 https://support.google.com/analytics/answer/1068216?hl=en
15 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image05-large-opt.png
16 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image05-large-opt.png
17 https://support.google.com/analytics/answer/1009409?hl=en
18 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image00-large-opt.png
19 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image00-large-opt.png
20 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image04-large-opt.png
21 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image04-large-opt.png
22 https://support.google.com/analytics/topic/3123779?hl=en&amp;ref_topic=1727148
23 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image03-large-opt.png
24 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image03-large-opt.png
25 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomin2-large-opt.png
26 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomin2-large-opt.png
27 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image02-large-opt.png
28 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image02-large-opt.png
29 https://www.google.com/analytics/web/template?uid=gUP6PNubRZ6qlqhq4M2g2Q
The post Is Your Responsive Design Working? Google Analytics Will Tell You appeared first on Smashing Magazine.
Source: Smashing Magazine
    

New Post has been published on http://freesourcecode.info/is-your-responsive-design-working-google-analytics-will-tell-you/

Is Your Responsive Design Working? Google Analytics Will Tell You

By Jon Arne Sæterås and Luca Passani

GAcustomdim-preview-opt

Responsive Web design has become the dominant method of developing and designing websites. It makes it easier to think “mobile first” and to create a website that is viewable on mobile devices.

In the early days of responsive Web design, creating breakpoints in CSS for particular screen sizes was common, like 320 pixels for iPhone and 768 pixels for iPad, and then we tested and monitored those devices. As responsive design has evolved, we now more often start with the content and then set breakpoints when the content “breaks.” This means that you might end up with quite a few content-centric breakpoints and no particular devices or form factors on which to test your website.

However, we are just guessing that our designs will perform well with different device classes and form factors and across different interaction models. We need to continually monitor a design’s performance with real traffic.

Content-centric breakpoints are definitely the way to go, but they also mean that monitoring your website to identify when it breaks is more important. This information, when easily accessible, provides hints on what types of devices and form factors to test further.

Google Analytics has some great multi-device features1 built in; however, with responsive design, we are really designing for form factors, not for devices. In this article, we’ll demonstrate how WURFL.js2 and Google Analytics can work together to show performance metrics across form factors. No more guessing.

Why Form Factor?

Speeding up and optimizing the user experience for a particular device or family of devices is always easier. In reality, though, creating a device-specific experience3 for all types of devices is not feasible, given that the diversity of Web-enabled devices will just continue to grow. However, every device has a particular form factor. Luke Wroblewski4, author of Mobile First5, outlines three categories to identify device experiences6:

  • usage or posture,
  • input method,
  • output or screen.

Because devices vary between these categories, we get different form factors. Hence, treating form factor as the primary dimension through which to monitor a responsive website makes sense. This will indicate which type of device to test for usability.

The examples in this article all use WURFL.js, including the form factors provided by it, which are:

  • desktop,
  • app,
  • tablet,
  • smartphone,
  • feature phone,
  • smart TV,
  • robot,
  • other non-mobile,
  • other mobile.

Feeding Data To Google Analytics

The first step is to put WURFL.js on the pages that you want to track. Simply paste this line of code into your markup:

<script type="text/javascript" src="//wurfl.io/wurfl.js"></script>

This will create a global WURFL object that you can access through JavaScript:

console.log(WURFL.form_factor);

Now that the script tag is in place, the only other thing to do is add the highlighted lines of code to Google Analytics’ tracking code:

/* Google Analytics' standard tracking code */
_gaq.push(['_setAccount', 'UA-99999999-1']);
_gaq.push(['_setDomainName', example.com']);
_gaq.push(['_trackPageview']);

/* Tell Google Analytics to log WURFL.js' data */
 _gaq.push(['_setCustomVar',	1,'complete_device_name',WURFL.complete_device_name,1]);
 _gaq.push(['_setCustomVar',	2,'form_factor',WURFL.form_factor,1]);
 _gaq.push(['_setCustomVar',	3,'is_mobile',WURFL.is_mobile,1]);

/* The rest of Analytics' standard tracking code */
(function() 
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
)();

Or, if you have updated to Google Analytics’ new “Universal Analytics7, you would add this:

/* Google Analytics' new universal tracking code */
(function(i,s,o,g,r,a,m)i['GoogleAnalyticsObject']=r;i[r]=i[r])(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-99999999-1, 'auto');

/* Define the custom dimensions */
ga('send', 'pageview', 
  'dimension1': WURFL.complete_device_name,
  'dimension2': WURFL.form_factor,
  'dimension3': WURFL.is_mobile
);

Further, if you are using GA Universal Analytics, you must remember to define the custom dimensions. You do that by clicking AdminCustom DefinitionsCustom Dimensions.

8
For Universal Analytics you need to define the custom dimensions in the Admin section. (Large preview9)

Analyzing The Data In Google Analytics

Now that the data is in Google Analytics, we need to make it available for inspection. We can use custom variables in Analytics in a number of ways, the most obvious being to look in the menu on the left and click AudienceCustomCustom Variables:

10
“Custom Variables” report. (Large version11)

If you are are using Universal Analytics, you’ll have the custom dimensions available as any other dimension in all reports in GA:

GAUIcustomdim-preview-opt12
Accessing custom dimensions. (Large preview13)

Already, we’re getting a pretty good picture of how form factors behave differently. The best metrics to focus on will obviously depend on your website, but in general, pay attention to bounce rate and pages per visit.

Big Picture With Dashboard Widgets

With dashboards14 in Google Analytics, we get a high-level overview of the most important metrics. This is a good place to monitor how your website performs across form factors. Once again, bounce rate and page impressions per visit are good metrics to start with. The purpose of the dashboard widgets is to alert you and to visualize how your website’s performance changes for certain form factors.

Let’s create a few widgets to display the status of different form factors. First, create a pie-chart widget that shows how much your website is being used by different form factors.

Widget displaying form factors15
Widget displaying form factors. (Large version16)

In the Dashboard, click Add Widget, select Pie, then the Sessions metric, and group it by the form factor custom variable. Note that the label in the green drop-down list is Custom Variables, not the actual name. In our example, the form factor variable is in the second slot, but make sure to choose the right slot if you’ve implemented it in a different order. Again, if you have converted to Universal analytics, the procedure is similar, but in stead of selecting custom variables, you simply add the name of your custom dimension as you would with any other dimension.

Next, create a few widgets to display visits and bounce rates17 per form factor. The widgets will indicate whether changes to the website have had a positive or negative impact. Obviously, you want higher visits and a lower bounce rate.

Creating a “form factor” widget18
Creating a “form factor” widget. (Larger version19)

Create this widget by adding a filter to the standard metrics. Choose a timeline diagram and filter the data with your custom variable where you have stored the form factor. Create one widget for each of the form factors that you want to monitor:

“Form factor” widgets in the dashboard20
“Form factor” widgets in the dashboard. (Large version21)

You might find that some form factors disappear in the statistics for global bounce rates because the data set is now bigger (as in the example above). As indicated by the red arrows, something dramatic has happened with smartphones and feature phones. Specifically, some changes were made to the landing page to increase traffic from tablets, and the changes clearly had a negative impact on traffic from smartphones and feature phones. Identifying the reason for the drop in traffic requires more fine-grained Analytics reports, and the drop might not have been easy to spot without having monitored form factors.

Form Factor Segments

Any custom variable that you put into Google Analytics is, of course, available in most reports as filters or dimensions, so tweaking them to your needs is quite easy. Another way to keep form factors at the top of mind is to put them in segments22 by creating conditions. Here is one segment per form factor that you’ll want to track:

Configure a segment23
Configure a segment. If you’re using Universal Analytics, you must use your custom dimensions rather than the custom variables. (Large version24)

The same, but in Universal Analytics:

GAcustomin2-preview-opt25
(Large preview26)

Google Analytics will show these segments in most of its standard reports as separate dimensions in charts and tables:

Segments chart27
Segments chart. (Large version28)

You can make “form factor” a dimension in most reports. As mentioned, bounce rate and general engagement are key metrics to follow, but goals and conversion rate are obviously interesting, too. You might find the need to create new goals or at least review your funnel for certain form factors.

After monitoring form factors for a while, you might conclude that you need to offer different user experiences for one or more form factors. Furthermore, you might need to tweak goals, funnels and advertising campaigns to account for differences in usage per form factor or device type.

We have used Google Analytics here, but WURFL.js is, of course, compatible with other analytics tools, as long as custom variables like the ones above are allowed.

Conclusion

In this article, we have looked at how performance per form factor is a key metric for monitoring a website and how WURFL.js and Google Analytics help to visualize this data. Once you put WURFL.js’ data into Analytics, it will be available in most standard reports as filters or dimensions, so tweaking the reports to your needs is quite straightforward. And the dashboard widgets will give you a high-level overview of their status. Also, bounce rate and page impressions per visit are key metrics, at least to start; so, defining form factors as segments will give you nice visualizations in most standard reports.

As a next step, look into conversions and goals in Google Analytics to see how to integrate and monitor form factors, which will vary according to the website’s function and purpose. To give you a head start, we have made a template that you can install29 in your Google Analytics dashboard (This template uses custom variables, not custom dimensions). Just follow the instructions to assign an Analytics property, which will then appear under DashboardsPrivate.

(al, ml, il)

Footnotes

  1. 1 http://www.smashingmagazine.com/2014/03/03/how-to-use-analytics-to-build-a-smarter-mobile-website/
  2. 2 http://wurfl.io
  3. 3 https://developers.facebook.com/blog/post/2012/01/24/device-experiences—responsive-design/
  4. 4 http://www.lukew.com/
  5. 5 http://www.lukew.com/resources/mobile_first.asp
  6. 6 https://developers.facebook.com/blog/post/2012/01/24/device-experiences—responsive-design/
  7. 7 https://support.google.com/analytics/answer/2790010?hl=en
  8. 8 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomdim-large-opt.png
  9. 9 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomdim-large-opt.png
  10. 10 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image01-large-opt.png
  11. 11 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image01-large-opt.png
  12. 12 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAUIcustomdim-large-opt.png
  13. 13 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAUIcustomdim-large-opt.png
  14. 14 https://support.google.com/analytics/answer/1068216?hl=en
  15. 15 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image05-large-opt.png
  16. 16 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image05-large-opt.png
  17. 17 https://support.google.com/analytics/answer/1009409?hl=en
  18. 18 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image00-large-opt.png
  19. 19 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image00-large-opt.png
  20. 20 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image04-large-opt.png
  21. 21 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image04-large-opt.png
  22. 22 https://support.google.com/analytics/topic/3123779?hl=en&ref_topic=1727148
  23. 23 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image03-large-opt.png
  24. 24 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image03-large-opt.png
  25. 25 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomin2-large-opt.png
  26. 26 http://www.smashingmagazine.com/wp-content/uploads/2014/07/GAcustomin2-large-opt.png
  27. 27 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image02-large-opt.png
  28. 28 http://www.smashingmagazine.com/wp-content/uploads/2014/05/image02-large-opt.png
  29. 29 https://www.google.com/analytics/web/template?uid=gUP6PNubRZ6qlqhq4M2g2Q

The post Is Your Responsive Design Working? Google Analytics Will Tell You appeared first on Smashing Magazine.

Source: Smashing Magazine

    

New Post has been published on http://nzbusinessdirectory.info/webdesign/customizing-wordpress-archives-for-categories-tags-and-other-taxonomies/Customizing WordPress Archives For Categories, Tags And Other TaxonomiesBy  Josh Pollock

Most WordPress users are familiar with tags and categories and with how to use them to organize their blog posts. If you use custom post types in WordPress, you might need to organize them like categories and tags. Categories and tags are examples of taxonomies, and WordPress allows you to create as many custom taxonomies as you want. These custom taxonomies operate like categories or tags, but are separate.
In this tutorial, we’ll explain custom taxonomies and how to create them. We’ll also go over which template files in a WordPress theme control the archives of built-in and custom taxonomies, and some advanced techniques for customizing the behavior of taxonomy archives.
Terminology
Before continuing, let’s get our terminology straight. A taxonomy is a WordPress content type, used primarily to organize content of any other content type. The two taxonomies everyone is familiar with are built in: categories and tags. We tend to call an individual posting of a tag a “tag,” but to be precise, we should refer to it as a “term” in the “tag” taxonomy. We pretty much always refer to items in a custom taxonomy as “terms.”
Categories and tags represent the two types of taxonomies: hierarchical and non-hierarchical. Like categories, hierarchical taxonomies can have parent-child relationships between terms in the taxonomy. For example, you might have on your blog a “films” category that has several child categories, with names like “foreign” and “domestic.” Custom taxonomies may also be hierarchical, like categories, or non-hierarchical, like tags.
A small part of the “WordPress Template Hierarchy”. (Source1)The archive of a taxonomy is the list of posts in a taxonomy that is automatically generated by WordPress. For example, this would be the page you see when you click on a category link and see all posts in that category. We’ll go over how to change the behavior of these pages and learn which template files generate them.
How Tag, Category and Custom Taxonomy Archives Work
For every category, tag and custom taxonomy, WordPress automatically generates an archive that lists each post associated with that taxonomy, in reverse chronological order. The system works really well if you organize your blog posts with categories and tags. If you have a complex system of organizing custom post types with custom taxonomies, then it might not be ideal. We’ll go over the many ways to modify these archives.
The first step to customizing is to know which files in your theme are used to display the archive. Different themes have different template files, but all themes have an index.php template. The index.php template is used to display all content, unless a template exists higher up in the hierarchy. WordPress’ template hierarchy is the system that dictates which template file is used to display which content. We’ll briefly go over the template hierarchy for categories, tags and custom taxonomies. If you’d like to learn more, these resources are highly recommended:
“Template Hierarchy2,” WordPress Codex
“Template Hierarchy3,” Chip Bennett
A flow chart
The WordPress Template Hierarchy: A Mini Resource4, Rami Abraham and Michelle Schulp
An interactive chart
Reveal Template5, Scott Reilly
A WordPress plugin
Most themes have an archive.php template, which is used for category and tag archives, as well as date and author archives. You can add a template file to handle category and tag archives separately. These templates would be named category.php or tag.php, respectively. You could also create templates for specific tags or categories, using the ID or slug of the category or tag. For example, a tag with the ID of 7 would use tag-7.php, if it exists, rather than tag.php or archive.php. A tag with the slug of “avocado” would be displayed using the tag-avocado.php template.
One tricky thing to keep in mind is that a template named after a slug will override a template named after an ID number. So, if a tag with the slug of “avocado” had an ID of 7, then tag-avocado.php would override tag-7.php, if it exists.
The template hierarchy for custom taxonomies is a little different, because there are templates for all taxonomies, for specific taxonomies and for specific terms in a specific taxonomy. So, imagine that you have two taxonomies, “fruits” and “vegetables,” and the “fruits” taxonomy has two terms, “apples” and “oranges,” while “vegetables” has two terms, “carrots” and “celery.” Let’s add three templates to our website’s theme: taxonomy.php, taxonomy-fruits.php and taxonomy-vegetables-carrots.php.
For the terms in the “fruits” taxonomy, all archives would be generated using taxonomy-fruits.php because no term-specific template exists. On the other hand, the term “carrots” in the “vegetables” taxonomy’s archives would be generated using taxonomy-vegetables-carrots.php. Because no taxonomy-vegetables.php template exists, all other terms in “vegetables” would be generated using taxonomy.php.
Using Conditional Tags
While you can add any of the custom templates listed above to create a totally unique view for any category, tag, custom taxonomy or custom taxonomy term, sometimes all you want to do is make one or two little changes. In fact, try to avoid creating a lot of templates because you will need to adjust each one when you make overall changes to the basic HTML markup that you use in each template in the theme. Unless I need a template that is radically different from the theme’s archive.php, I tend to stick to adding conditional changes to archive.php.
WordPress provides conditional functions to determine whether a category, tag or custom taxonomy is being displayed. To determine whether a category archive is being shown, you can use is_category() for categories, is_tag() for tags and is_tax() for custom taxonomies. The is_tag() and is_category() functions can also test for specific categories or tags by slug or ID. For example:
&lt;?php
    if ( is_tag() ) 
        echo "True for any tag!";
    
    if ( is_tag( 'jedis' ) ) 
        echo "True for the tag whose slug is jedi";
    
    if ( is_tag( array( 'jedi', 'sith' ) ) ) 
        echo "True for tags whose slug is jedi or sith";
    
    if ( is_tag( 7 ) ) 
        echo "You can also use tag IDs. This is true for tag ID 7";
    
?&gt;

For custom taxonomies, the is_tax() function can be used to check whether any taxonomy (not including categories and tags), a specific taxonomy or a specific term in a taxonomy is being shown. For example:
&lt;?php
    if ( is_tax() ) 
        echo "True for any custom taxonomy.";
    
    if ( is_tax( 'vegetable' ) ) 
        echo "True for any term in the vegetable taxonomy.";
    
    if ( is_tax( 'vegetable', 'celery' ) ) 
        echo "True only for the term celery, in the vegetable taxonomy.";
    
?&gt;

Creating Custom Taxonomies
Adding a custom taxonomy can be done in one of three ways: coding it manually according to the instructions in the Codex, which I don’t recommend; generating the code using GenerateWP6; or using a plugin for custom content types, such as Pods7 or Types8. Plugins for custom content types enable you to create custom taxonomies and custom post types in WordPress’ back end without having to write any code. Using one is the easiest way to add a custom taxonomy and to get a framework for working with custom content types.
If you opt for one of the first two options, rather than a plugin, then you will need to add the code either to your theme’s functions.php file or to a custom plugin. I strongly recommend creating a custom plugin, rather than adding the code to functions.php. Even if you’ve never created a plugin before, I urge you to do it. While adding the code to your theme’s functions.php will work, when you switch themes (say, because you want to use a new theme or to troubleshoot a problem), the taxonomy will no longer work.
Whether you write your custom taxonomy code by following the directions in the Codex or by generating it with GenerateWP, just paste it in a text file and add one line of code before it and you’ll have a plugin. Upload it and install it as you would any other plugin.
The only line you need to create a custom plugin is /* Plugin name: Custom Taxonomy */.
Below is a plugin to register a custom taxonomy named “vegetables,” which I created using GenerateWP because it’s significantly easier and way less likely to contain errors than doing it manually:
&lt;?php
    /* Plugin Name: Veggie Taxonomy */
    if ( ! function_exists( 'slug_veggies_tax' ) ) 

    // Register Custom Taxonomy
    function slug_veggies_tax() 

    $labels = array(
    'name'                      	=&gt; _x( 'Vegetables', 'Taxonomy General Name', 'text_domain' ),
    'singular_name'              	=&gt; _x( 'Vegetable', 'Taxonomy Singular Name', 'text_domain' ),
    'menu_name'                  	=&gt; __( 'Taxonomy', 'text_domain' ),
    'all_Veggies'                   =&gt; __( 'All Veggies', 'text_domain' ),
    'parent_Veggie'                 =&gt; __( 'Parent Veggie', 'text_domain' ),
    'parent_Veggie_colon'           =&gt; __( 'Parent Veggie:', 'text_domain' ),
    'new_Veggie_name'               =&gt; __( 'New Veggie name', 'text_domain' ),
    'add_new_Veggie'                =&gt; __( 'Add new Veggie', 'text_domain' ),
    'edit_Veggie'                   =&gt; __( 'Edit Veggie', 'text_domain' ),
    'update_Veggie'                 =&gt; __( 'Update Veggie', 'text_domain' ),
    'separate_Veggies_with_commas'  =&gt; __( 'Separate Veggies with commas', 'text_domain' ),
    'search_Veggies'                =&gt; __( 'Search Veggies', 'text_domain' ),
    'add_or_remove_Veggies'         =&gt; __( 'Add or remove Veggies', 'text_domain' ),
    'choose_from_most_used'         =&gt; __( 'Choose from the most used Veggies', 'text_domain' ),
    'not_found'                     =&gt; __( 'Not Found', 'text_domain' ),
    );
    $args = array(
    'labels'                     =&gt; $labels,
    'hierarchical'               =&gt; false,
    'public'                     =&gt; true,
    'show_ui'                    =&gt; true,
    'show_admin_column'          =&gt; true,
    'show_in_nav_menus'          =&gt; true,
    'show_tagcloud'              =&gt; false,
    );
    register_taxonomy( 'vegetable', array( 'post' ), $args );

    

    // Hook into the 'init' action
    add_action( 'init', 'slug_veggies_tax', 0 );

    
?&gt;

By the way, I created this code using GenerateWP in less than two minutes! The service is great, and manually writing code that this website can automatically generate for you makes no sense. To make the process even easier, you can use the plugin Pluginception9 to create a blank plugin for you and then paste the code from GenerateWP into it using WordPress’ plugin editor.
Using WP_Query With Custom Taxonomies
Once you have added a custom taxonomy, you might want to query for posts with terms in that taxonomy. To do this, we can use taxonomy queries with WP_QUERY.
Taxonomy queries can be very simple or complicated. The simplest query would be for all posts with a certain term. For example, if you had a post type named “jedi” and an associated custom taxonomy named “level,” then you could get all Jedi masters like this:
&lt;?php
    $args = array(
        'post_type' =&gt; 'jedi',
        'level' =&gt; 'master'
    );
    $query = new WP_Query( $args );
?&gt;

If you added a second custom taxonomy named “era,” then you could find all Jedi masters of the Old Republic like this:
&lt;?php
    $args = array(
        'post_type' =&gt; 'jedi',
        'level' =&gt; 'master',
        'era' =&gt; 'old-republic',
    );
    $query = new WP_Query( $args );
?&gt;

We can also do more complicated comparisons, using a full tax_query. The tax_query argument enables us to search by ID instead of slug (as we did before) and to search for more than one term. It also enables us to combine multiple taxonomy queries and to set the relationship between the two. In addition, we can even use SQL operators such as NOT IN to exclude terms.
The possibilities are endless. Explore the “Taxonomy Parameters10” section of the Codex page for “Class Reference/WP_Query” for complete information. The snippet below searches our “jedi” post type for Jedi knights and masters who are not from the Old Republic era:
&lt;?php
    $args = array(
        'post_type' =&gt; 'jedi',
        'tax_query' =&gt; array(
        'relation' =&gt; 'AND',
            array(
                'taxonomy' =&gt; 'level',
                'field' =&gt; 'slug',
                'terms' =&gt; array( 'master', 'knight' )
            ),
            array(
                'taxonomy' =&gt; 'era',
                'field' =&gt; 'slug',
                'terms' =&gt; array( 'old-republic' ),
                'operator' =&gt; 'NOT IN'
                )
        )
    );
    $query = new WP_Query( $args );
?&gt;

Customizing Taxonomy Archives
So far, we have covered how taxonomies, tags and categories work by default, as well as how to create custom taxonomies. If any of this default behavior doesn’t fit your needs, you can always modify it. We’ll go over some ways to modify WordPress’ built-in functionality for those of you who use WordPress less as a blogging platform and more as a content management system, which often requires custom taxonomies.
Hello pre_get_posts
Before any posts are outputted by the WordPress loop, WordPress automatically retrieves the posts for the user according to the page they are on, using the WP_QUERY class. For example, in the main blog index, it gets the most recent posts. In a taxonomy archive, it gets the most recent posts in that taxonomy.
To change that query, you can use the pre_get_posts filter before WordPress gets any posts. This filter exposes the query object after it is set but before it is used to actually get any posts. This means that you can modify the query using the class methods before the main WordPress loop is run. If that sounds confusing, don’t worry — the next few sections of this article give practical examples of how this works.
Adding Custom Post Types to Category or Tag Archives
A great use of modifying the WP_QUERY object using pre_get_posts is to add posts from a custom post type to the category archive. By default, custom post types are not included in this query. If we were constructing arguments to be passed to WP_Query and wanted to include both regular posts and posts in the custom post type “jedi,” then our argument would look like this:
&lt;?php
    $args = array( 'post_type' =&gt;
        array(
            'post',
            'jedi'
        )
    );
?&gt;

In the callback for our pre_get_posts filter, we need to pass a similar argument. The problem is that the WP_QUERY object already exists, so we can’t pass an argument to it like we do when creating an instance of the class. Instead, we use the set() class method, which allows us to change any of the arguments after the class has been created.
In the snippet below, we use set() to change the post_type argument from the default value, which is post, to an array of post types, including posts and our custom post type “jedi.” Note that we are using the conditional tag is_category() so that the change happens only when category archives are being displayed.
&lt;?php
    add_filter( 'pre_get_posts', 'slug_cpt_category_archives' );
    function slug_cpt_category_archives( $query ) 
    if ( is_category() &amp;&amp; is_main_query()  )  
        $query-&gt;set( 'post_type',
            array(
                'post',
                'jedi'
            )
        );
    

    return $query;

    
?&gt;

This function’s $query parameter is the WP_QUERY object before it is used to populate the main loop. Because a page may include multiple loops, such as those used by widgets, we use the conditional function is_main_query() to ensure that this affects only the main loop and not any secondary loops on the page, such as those used by widgets.
Making Category or Hierarchical Taxonomy Archives Hierarchical
By default, the archives for categories and other hierarchical taxonomies act like any other taxonomy archive: they show all posts in that category or with that taxonomy term. To show only parent terms and exclude child terms, you would use the pre_get_posts filter again.
Just like when creating your own WP_QUERY for posts in a taxonomy, the main loop’s WP_QUERY uses the tax_query arguments to get posts by taxonomy. The tax_query has an include_children argument, which by default is set to 1 or true. By changing it to 0 or false, we can prevent posts with a child term from being included in the archive:
&lt;?php
    add_action( 'pre_get_posts', 'slug_cpt_category_archives' );
    function slug_cpt_category_archives( $query ) 
        if ( is_tax( 'TAXONOMY NAME') )  
            $tax_query = $query-&gt;tax_query-&gt;queries;
            $tax_query['include_children'] = 0;
            $query-&gt;set( 'tax_query', $tax_query );
        

    
?&gt;

The result sounds desirable but has several major shortcomings. That’s OK, because if we address those flaws, we’ll have taken the first step to creating something very cool.
The first and biggest problem is that the result is not an archive page that shows the child terms; it’s still a post with the parent term. The other problem is that we don’t have a good way to navigate to the child term archives.
A good way to deal with this is to combine the pre_get_post filter above with a modification to the template that shows the category or taxonomy. We discussed earlier how to determine which template is used to output category or custom taxonomy archives. Also, keep in mind that you can always wrap your changes in conditional tags, such as is_category() or is_tax(), but that can become unwieldy quickly; so, making a copy of your archive.php and removing any unneeded code probably makes more sense.
The first step is to wrap the entire thing in a check to see whether the current taxonomy term has children. If it does not, then we do not want to output anything. To do this, we use get_term_children(), which will return an empty array if the current term has no children and which we can test for with !empty().
To make this work for any taxonomy that might be displayed, we need to get the current taxonomy and taxonomy term from the query_vars array of the global $wp_query object. The taxonomy’s slug is contained in the taxonomy key, and the term’s slug is in the tax key.
To use get_term_children(), we must have the term’s ID. The ID is not in query_vars, but we can pass the slug to  get_term_by() to get it.
Here is how we get all of the information that we need into variables:
&lt;?php
    global $wp_query;
    $taxonomy = $wp_query-&gt;query_vars['taxonomy'];
    $term = $wp_query-&gt;query_vars['tax'];
    $term_id = get_term_by( 'slug', $term, $taxonomy );
    $term_id = $term_id-&gt;term_id;
    $terms = get_term_children( $term_id, $taxonomy );
?&gt;

Now we will continue only if $terms isn’t an empty array. To see whether it is empty in our check, first we will repopulate the terms using get_terms(). This is necessary because get_term_children returns only an array of IDs, and we need IDs and names, both of which are in the object returned by get_terms(). We can loop through this object, outputting the name as a link. The link can be generated by passing the term’s ID to get_term_link().
Here is the complete code:
&lt;?php
    global $wp_query;
    $taxonomy = $wp_query-&gt;query_vars['taxonomy'];
    $term = $wp_query-&gt;query_vars['tax'];
    $term_id = get_term_by( 'slug', $term, $taxonomy );
    $term_id = $term_id-&gt;term_id;
    $terms = get_term_children( $term_id, $taxonomy );
    if ( !empty( $terms ) ) {
    $terms = get_terms( $taxonomy, array( 'child_of' =&gt; $term_id ) );
    echo '&lt;ul class="child-term-list"&gt;';
    foreach ( $terms as $term ) 
    echo '&lt;li&gt;&lt;a href="'.$term-&gt;term_id.'"&gt;'.$term-&gt;name.'&lt;/a&gt;&lt;/li&gt;';
    

    echo '&lt;/ul&gt;';

?&gt;

Creating A Custom Landing Page For Taxonomy Archives
If your hierarchical taxonomy has no terms in the parent term, then the regular taxonomy archive system will be of no use to you. You really want to show taxonomy links instead.
In this case, a good option is to create a custom landing page for the term. We’ll use query_vars again to determine whether the user is on the first page of a taxonomy archive; if so, we will use the taxonomy_archive filter to include a separate template, like this:
&lt;?php
    add_filter( 'taxonomy_archive ', 'slug_tax_page_one' );
    function slug_tax_page_one( $template ) 
        if ( is_tax( 'TAXONOMY_NAME' ) ) 
             global $wp_query;
             $page = $wp_query-&gt;query_vars['paged'];
            if ( $page = 0 ) 
                $template = get_stylesheet_directory(). '/taxonomy-page-one.php';
            
        

        return $template;

    
?&gt;

This callback first checks that the user is in the taxonomy that we want to target. We can target all taxonomies by changing this to just is_tax(). Then, it gets the current page using the query_var named paged, and if the user is on the first page, then it returns the address for the new template file. If not, it returns the default template file.
What you put in that template file is up to you. You can create a list of terms using the code shown above. You can use it to output any content, really — for example, more information about the taxonomy term or links to specific posts.
Taking Control
With a bit of work, WordPress’ basic architecture, which still reflects its origins as a blogging platform, can be customized to fit almost any website or Web app. Using custom taxonomies to organize your content and doing it in a way that suits your needs will be an important step in many of your WordPress projects. Hopefully, this post has brought you a step closer to getting the most out of this powerful aspect of WordPress.
(dp, al, il)
Footnotes
1 http://wphierarchy.com/
2 https://codex.wordpress.org/Template_Hierarchy
3 http://www.chipbennett.net/themes/template-hierarchy/
4 http://wphierarchy.com/
5 https://wordpress.org/plugins/reveal-template/
6 http://generatewp.com/
7 http://pods.io
8 http://wp-types.com/home/types-manage-post-types-taxonomy-and-custom-fields/
9 https://wordpress.org/plugins/pluginception/
10 http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
The post Customizing WordPress Archives For Categories, Tags And Other Taxonomies appeared first on Smashing Magazine.
Source: Smashing Magazine
    

New Post has been published on http://nzbusinessdirectory.info/webdesign/customizing-wordpress-archives-for-categories-tags-and-other-taxonomies/

Customizing WordPress Archives For Categories, Tags And Other Taxonomies

By Josh Pollock

wordpress-categories-taxonomies-opt

Most WordPress users are familiar with tags and categories and with how to use them to organize their blog posts. If you use custom post types in WordPress, you might need to organize them like categories and tags. Categories and tags are examples of taxonomies, and WordPress allows you to create as many custom taxonomies as you want. These custom taxonomies operate like categories or tags, but are separate.

In this tutorial, we’ll explain custom taxonomies and how to create them. We’ll also go over which template files in a WordPress theme control the archives of built-in and custom taxonomies, and some advanced techniques for customizing the behavior of taxonomy archives.

Terminology

Before continuing, let’s get our terminology straight. A taxonomy is a WordPress content type, used primarily to organize content of any other content type. The two taxonomies everyone is familiar with are built in: categories and tags. We tend to call an individual posting of a tag a “tag,” but to be precise, we should refer to it as a “term” in the “tag” taxonomy. We pretty much always refer to items in a custom taxonomy as “terms.”

Categories and tags represent the two types of taxonomies: hierarchical and non-hierarchical. Like categories, hierarchical taxonomies can have parent-child relationships between terms in the taxonomy. For example, you might have on your blog a “films” category that has several child categories, with names like “foreign” and “domestic.” Custom taxonomies may also be hierarchical, like categories, or non-hierarchical, like tags.

A small part of the “WordPress Template Hierarchy”. (Source1)

The archive of a taxonomy is the list of posts in a taxonomy that is automatically generated by WordPress. For example, this would be the page you see when you click on a category link and see all posts in that category. We’ll go over how to change the behavior of these pages and learn which template files generate them.

How Tag, Category and Custom Taxonomy Archives Work

For every category, tag and custom taxonomy, WordPress automatically generates an archive that lists each post associated with that taxonomy, in reverse chronological order. The system works really well if you organize your blog posts with categories and tags. If you have a complex system of organizing custom post types with custom taxonomies, then it might not be ideal. We’ll go over the many ways to modify these archives.

The first step to customizing is to know which files in your theme are used to display the archive. Different themes have different template files, but all themes have an index.php template. The index.php template is used to display all content, unless a template exists higher up in the hierarchy. WordPress’ template hierarchy is the system that dictates which template file is used to display which content. We’ll briefly go over the template hierarchy for categories, tags and custom taxonomies. If you’d like to learn more, these resources are highly recommended:

Most themes have an archive.php template, which is used for category and tag archives, as well as date and author archives. You can add a template file to handle category and tag archives separately. These templates would be named category.php or tag.php, respectively. You could also create templates for specific tags or categories, using the ID or slug of the category or tag. For example, a tag with the ID of 7 would use tag-7.php, if it exists, rather than tag.php or archive.php. A tag with the slug of “avocado” would be displayed using the tag-avocado.php template.

One tricky thing to keep in mind is that a template named after a slug will override a template named after an ID number. So, if a tag with the slug of “avocado” had an ID of 7, then tag-avocado.php would override tag-7.php, if it exists.

The template hierarchy for custom taxonomies is a little different, because there are templates for all taxonomies, for specific taxonomies and for specific terms in a specific taxonomy. So, imagine that you have two taxonomies, “fruits” and “vegetables,” and the “fruits” taxonomy has two terms, “apples” and “oranges,” while “vegetables” has two terms, “carrots” and “celery.” Let’s add three templates to our website’s theme: taxonomy.php, taxonomy-fruits.php and taxonomy-vegetables-carrots.php.

For the terms in the “fruits” taxonomy, all archives would be generated using taxonomy-fruits.php because no term-specific template exists. On the other hand, the term “carrots” in the “vegetables” taxonomy’s archives would be generated using taxonomy-vegetables-carrots.php. Because no taxonomy-vegetables.php template exists, all other terms in “vegetables” would be generated using taxonomy.php.

Using Conditional Tags

While you can add any of the custom templates listed above to create a totally unique view for any category, tag, custom taxonomy or custom taxonomy term, sometimes all you want to do is make one or two little changes. In fact, try to avoid creating a lot of templates because you will need to adjust each one when you make overall changes to the basic HTML markup that you use in each template in the theme. Unless I need a template that is radically different from the theme’s archive.php, I tend to stick to adding conditional changes to archive.php.

WordPress provides conditional functions to determine whether a category, tag or custom taxonomy is being displayed. To determine whether a category archive is being shown, you can use is_category() for categories, is_tag() for tags and is_tax() for custom taxonomies. The is_tag() and is_category() functions can also test for specific categories or tags by slug or ID. For example:

<?php
    if ( is_tag() ) 
        echo "True for any tag!";
    
    if ( is_tag( 'jedis' ) ) 
        echo "True for the tag whose slug is jedi";
    
    if ( is_tag( array( 'jedi', 'sith' ) ) ) 
        echo "True for tags whose slug is jedi or sith";
    
    if ( is_tag( 7 ) ) 
        echo "You can also use tag IDs. This is true for tag ID 7";
    
?>

For custom taxonomies, the is_tax() function can be used to check whether any taxonomy (not including categories and tags), a specific taxonomy or a specific term in a taxonomy is being shown. For example:

<?php
    if ( is_tax() ) 
        echo "True for any custom taxonomy.";
    
    if ( is_tax( 'vegetable' ) ) 
        echo "True for any term in the vegetable taxonomy.";
    
    if ( is_tax( 'vegetable', 'celery' ) ) 
        echo "True only for the term celery, in the vegetable taxonomy.";
    
?>

Creating Custom Taxonomies

Adding a custom taxonomy can be done in one of three ways: coding it manually according to the instructions in the Codex, which I don’t recommend; generating the code using GenerateWP6; or using a plugin for custom content types, such as Pods7 or Types8. Plugins for custom content types enable you to create custom taxonomies and custom post types in WordPress’ back end without having to write any code. Using one is the easiest way to add a custom taxonomy and to get a framework for working with custom content types.

If you opt for one of the first two options, rather than a plugin, then you will need to add the code either to your theme’s functions.php file or to a custom plugin. I strongly recommend creating a custom plugin, rather than adding the code to functions.php. Even if you’ve never created a plugin before, I urge you to do it. While adding the code to your theme’s functions.php will work, when you switch themes (say, because you want to use a new theme or to troubleshoot a problem), the taxonomy will no longer work.

Whether you write your custom taxonomy code by following the directions in the Codex or by generating it with GenerateWP, just paste it in a text file and add one line of code before it and you’ll have a plugin. Upload it and install it as you would any other plugin.

The only line you need to create a custom plugin is /* Plugin name: Custom Taxonomy */.

Below is a plugin to register a custom taxonomy named “vegetables,” which I created using GenerateWP because it’s significantly easier and way less likely to contain errors than doing it manually:

<?php
    /* Plugin Name: Veggie Taxonomy */
    if ( ! function_exists( 'slug_veggies_tax' ) ) 

    // Register Custom Taxonomy
    function slug_veggies_tax() 

    $labels = array(
    'name'                      	=> _x( 'Vegetables', 'Taxonomy General Name', 'text_domain' ),
    'singular_name'              	=> _x( 'Vegetable', 'Taxonomy Singular Name', 'text_domain' ),
    'menu_name'                  	=> __( 'Taxonomy', 'text_domain' ),
    'all_Veggies'                   => __( 'All Veggies', 'text_domain' ),
    'parent_Veggie'                 => __( 'Parent Veggie', 'text_domain' ),
    'parent_Veggie_colon'           => __( 'Parent Veggie:', 'text_domain' ),
    'new_Veggie_name'               => __( 'New Veggie name', 'text_domain' ),
    'add_new_Veggie'                => __( 'Add new Veggie', 'text_domain' ),
    'edit_Veggie'                   => __( 'Edit Veggie', 'text_domain' ),
    'update_Veggie'                 => __( 'Update Veggie', 'text_domain' ),
    'separate_Veggies_with_commas'  => __( 'Separate Veggies with commas', 'text_domain' ),
    'search_Veggies'                => __( 'Search Veggies', 'text_domain' ),
    'add_or_remove_Veggies'         => __( 'Add or remove Veggies', 'text_domain' ),
    'choose_from_most_used'         => __( 'Choose from the most used Veggies', 'text_domain' ),
    'not_found'                     => __( 'Not Found', 'text_domain' ),
    );
    $args = array(
    'labels'                     => $labels,
    'hierarchical'               => false,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
    'show_tagcloud'              => false,
    );
    register_taxonomy( 'vegetable', array( 'post' ), $args );

    

    // Hook into the 'init' action
    add_action( 'init', 'slug_veggies_tax', 0 );

    
?>

By the way, I created this code using GenerateWP in less than two minutes! The service is great, and manually writing code that this website can automatically generate for you makes no sense. To make the process even easier, you can use the plugin Pluginception9 to create a blank plugin for you and then paste the code from GenerateWP into it using WordPress’ plugin editor.

Using WP_Query With Custom Taxonomies

Once you have added a custom taxonomy, you might want to query for posts with terms in that taxonomy. To do this, we can use taxonomy queries with WP_QUERY.

Taxonomy queries can be very simple or complicated. The simplest query would be for all posts with a certain term. For example, if you had a post type named “jedi” and an associated custom taxonomy named “level,” then you could get all Jedi masters like this:

<?php
    $args = array(
        'post_type' => 'jedi',
        'level' => 'master'
    );
    $query = new WP_Query( $args );
?>

If you added a second custom taxonomy named “era,” then you could find all Jedi masters of the Old Republic like this:

<?php
    $args = array(
        'post_type' => 'jedi',
        'level' => 'master',
        'era' => 'old-republic',
    );
    $query = new WP_Query( $args );
?>

We can also do more complicated comparisons, using a full tax_query. The tax_query argument enables us to search by ID instead of slug (as we did before) and to search for more than one term. It also enables us to combine multiple taxonomy queries and to set the relationship between the two. In addition, we can even use SQL operators such as NOT IN to exclude terms.

The possibilities are endless. Explore the “Taxonomy Parameters10” section of the Codex page for “Class Reference/WP_Query” for complete information. The snippet below searches our “jedi” post type for Jedi knights and masters who are not from the Old Republic era:

<?php
    $args = array(
        'post_type' => 'jedi',
        'tax_query' => array(
        'relation' => 'AND',
            array(
                'taxonomy' => 'level',
                'field' => 'slug',
                'terms' => array( 'master', 'knight' )
            ),
            array(
                'taxonomy' => 'era',
                'field' => 'slug',
                'terms' => array( 'old-republic' ),
                'operator' => 'NOT IN'
                )
        )
    );
    $query = new WP_Query( $args );
?>

Customizing Taxonomy Archives

So far, we have covered how taxonomies, tags and categories work by default, as well as how to create custom taxonomies. If any of this default behavior doesn’t fit your needs, you can always modify it. We’ll go over some ways to modify WordPress’ built-in functionality for those of you who use WordPress less as a blogging platform and more as a content management system, which often requires custom taxonomies.

Hello pre_get_posts

Before any posts are outputted by the WordPress loop, WordPress automatically retrieves the posts for the user according to the page they are on, using the WP_QUERY class. For example, in the main blog index, it gets the most recent posts. In a taxonomy archive, it gets the most recent posts in that taxonomy.

To change that query, you can use the pre_get_posts filter before WordPress gets any posts. This filter exposes the query object after it is set but before it is used to actually get any posts. This means that you can modify the query using the class methods before the main WordPress loop is run. If that sounds confusing, don’t worry — the next few sections of this article give practical examples of how this works.

Adding Custom Post Types to Category or Tag Archives

A great use of modifying the WP_QUERY object using pre_get_posts is to add posts from a custom post type to the category archive. By default, custom post types are not included in this query. If we were constructing arguments to be passed to WP_Query and wanted to include both regular posts and posts in the custom post type “jedi,” then our argument would look like this:

<?php
    $args = array( 'post_type' =>
        array(
            'post',
            'jedi'
        )
    );
?>

In the callback for our pre_get_posts filter, we need to pass a similar argument. The problem is that the WP_QUERY object already exists, so we can’t pass an argument to it like we do when creating an instance of the class. Instead, we use the set() class method, which allows us to change any of the arguments after the class has been created.

In the snippet below, we use set() to change the post_type argument from the default value, which is post, to an array of post types, including posts and our custom post type “jedi.” Note that we are using the conditional tag is_category() so that the change happens only when category archives are being displayed.

<?php
    add_filter( 'pre_get_posts', 'slug_cpt_category_archives' );
    function slug_cpt_category_archives( $query ) 
    if ( is_category() && is_main_query()  )  
        $query->set( 'post_type',
            array(
                'post',
                'jedi'
            )
        );
    

    return $query;

    
?>

This function’s $query parameter is the WP_QUERY object before it is used to populate the main loop. Because a page may include multiple loops, such as those used by widgets, we use the conditional function is_main_query() to ensure that this affects only the main loop and not any secondary loops on the page, such as those used by widgets.

Making Category or Hierarchical Taxonomy Archives Hierarchical

By default, the archives for categories and other hierarchical taxonomies act like any other taxonomy archive: they show all posts in that category or with that taxonomy term. To show only parent terms and exclude child terms, you would use the pre_get_posts filter again.

Just like when creating your own WP_QUERY for posts in a taxonomy, the main loop’s WP_QUERY uses the tax_query arguments to get posts by taxonomy. The tax_query has an include_children argument, which by default is set to 1 or true. By changing it to 0 or false, we can prevent posts with a child term from being included in the archive:

<?php
    add_action( 'pre_get_posts', 'slug_cpt_category_archives' );
    function slug_cpt_category_archives( $query ) 
        if ( is_tax( 'TAXONOMY NAME') )  
            $tax_query = $query->tax_query->queries;
            $tax_query['include_children'] = 0;
            $query->set( 'tax_query', $tax_query );
        

    
?>

The result sounds desirable but has several major shortcomings. That’s OK, because if we address those flaws, we’ll have taken the first step to creating something very cool.

The first and biggest problem is that the result is not an archive page that shows the child terms; it’s still a post with the parent term. The other problem is that we don’t have a good way to navigate to the child term archives.

A good way to deal with this is to combine the pre_get_post filter above with a modification to the template that shows the category or taxonomy. We discussed earlier how to determine which template is used to output category or custom taxonomy archives. Also, keep in mind that you can always wrap your changes in conditional tags, such as is_category() or is_tax(), but that can become unwieldy quickly; so, making a copy of your archive.php and removing any unneeded code probably makes more sense.

The first step is to wrap the entire thing in a check to see whether the current taxonomy term has children. If it does not, then we do not want to output anything. To do this, we use get_term_children(), which will return an empty array if the current term has no children and which we can test for with !empty().

To make this work for any taxonomy that might be displayed, we need to get the current taxonomy and taxonomy term from the query_vars array of the global $wp_query object. The taxonomy’s slug is contained in the taxonomy key, and the term’s slug is in the tax key.

To use get_term_children(), we must have the term’s ID. The ID is not in query_vars, but we can pass the slug to get_term_by() to get it.

Here is how we get all of the information that we need into variables:

<?php
    global $wp_query;
    $taxonomy = $wp_query->query_vars['taxonomy'];
    $term = $wp_query->query_vars['tax'];
    $term_id = get_term_by( 'slug', $term, $taxonomy );
    $term_id = $term_id->term_id;
    $terms = get_term_children( $term_id, $taxonomy );
?>

Now we will continue only if $terms isn’t an empty array. To see whether it is empty in our check, first we will repopulate the terms using get_terms(). This is necessary because get_term_children returns only an array of IDs, and we need IDs and names, both of which are in the object returned by get_terms(). We can loop through this object, outputting the name as a link. The link can be generated by passing the term’s ID to get_term_link().

Here is the complete code:

<?php
    global $wp_query;
    $taxonomy = $wp_query->query_vars['taxonomy'];
    $term = $wp_query->query_vars['tax'];
    $term_id = get_term_by( 'slug', $term, $taxonomy );
    $term_id = $term_id->term_id;
    $terms = get_term_children( $term_id, $taxonomy );
    if ( !empty( $terms ) ) {
    $terms = get_terms( $taxonomy, array( 'child_of' => $term_id ) );
    echo '<ul class="child-term-list">';
    foreach ( $terms as $term ) 
    echo '<li><a href="'.$term->term_id.'">'.$term->name.'</a></li>';
    

    echo '</ul>';

?>

Creating A Custom Landing Page For Taxonomy Archives

If your hierarchical taxonomy has no terms in the parent term, then the regular taxonomy archive system will be of no use to you. You really want to show taxonomy links instead.

In this case, a good option is to create a custom landing page for the term. We’ll use query_vars again to determine whether the user is on the first page of a taxonomy archive; if so, we will use the taxonomy_archive filter to include a separate template, like this:

<?php
    add_filter( 'taxonomy_archive ', 'slug_tax_page_one' );
    function slug_tax_page_one( $template ) 
        if ( is_tax( 'TAXONOMY_NAME' ) ) 
             global $wp_query;
             $page = $wp_query->query_vars['paged'];
            if ( $page = 0 ) 
                $template = get_stylesheet_directory(). '/taxonomy-page-one.php';
            
        

        return $template;

    
?>

This callback first checks that the user is in the taxonomy that we want to target. We can target all taxonomies by changing this to just is_tax(). Then, it gets the current page using the query_var named paged, and if the user is on the first page, then it returns the address for the new template file. If not, it returns the default template file.

What you put in that template file is up to you. You can create a list of terms using the code shown above. You can use it to output any content, really — for example, more information about the taxonomy term or links to specific posts.

Taking Control

With a bit of work, WordPress’ basic architecture, which still reflects its origins as a blogging platform, can be customized to fit almost any website or Web app. Using custom taxonomies to organize your content and doing it in a way that suits your needs will be an important step in many of your WordPress projects. Hopefully, this post has brought you a step closer to getting the most out of this powerful aspect of WordPress.

(dp, al, il)

Footnotes

  1. 1 http://wphierarchy.com/
  2. 2 https://codex.wordpress.org/Template_Hierarchy
  3. 3 http://www.chipbennett.net/themes/template-hierarchy/
  4. 4 http://wphierarchy.com/
  5. 5 https://wordpress.org/plugins/reveal-template/
  6. 6 http://generatewp.com/
  7. 7 http://pods.io
  8. 8 http://wp-types.com/home/types-manage-post-types-taxonomy-and-custom-fields/
  9. 9 https://wordpress.org/plugins/pluginception/
  10. 10 http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

The post Customizing WordPress Archives For Categories, Tags And Other Taxonomies appeared first on Smashing Magazine.

Source: Smashing Magazine

    

New Post has been published on http://freesourcecode.info/customizing-wordpress-archives-for-categories-terms-and-other-taxonomies/Customizing WordPress Archives For Categories, Terms And Other TaxonomiesBy  Josh Pollock

Most WordPress users are familiar with tags and categories and with how to use them to organize their blog posts. If you use custom post types in WordPress, you might need to organize them like categories and tags. Categories and tags are examples of taxonomies, and WordPress allows you to create as many custom taxonomies as you want. These custom taxonomies operate like categories or tags, but are separate.
In this tutorial, we’ll explain custom taxonomies and how to create them. We’ll also go over which template files in a WordPress theme control the archives of built-in and custom taxonomies, and some advanced techniques for customizing the behavior of taxonomy archives.
Terminology
Before continuing, let’s get our terminology straight. A taxonomy is a WordPress content type, used primarily to organize content of any other content type. The two taxonomies everyone is familiar with are built in: categories and tags. We tend to call an individual posting of a tag a “tag,” but to be precise, we should refer to it as a “term” in the “tag” taxonomy. We pretty much always refer to items in a custom taxonomy as “terms.”
Categories and tags represent the two types of taxonomies: hierarchical and non-hierarchical. Like categories, hierarchical taxonomies can have parent-child relationships between terms in the taxonomy. For example, you might have on your blog a “films” category that has several child categories, with names like “foreign” and “domestic.” Custom taxonomies may also be hierarchical, like categories, or non-hierarchical, like tags.
A small part of the “WordPress Template Hierarchy”. (Source1)The archive of a taxonomy is the list of posts in a taxonomy that is automatically generated by WordPress. For example, this would be the page you see when you click on a category link and see all posts in that category. We’ll go over how to change the behavior of these pages and learn which template files generate them.
How Tag, Category and Custom Taxonomy Archives Work
For every category, tag and custom taxonomy, WordPress automatically generates an archive that lists each post associated with that taxonomy, in reverse chronological order. The system works really well if you organize your blog posts with categories and tags. If you have a complex system of organizing custom post types with custom taxonomies, then it might not be ideal. We’ll go over the many ways to modify these archives.
The first step to customizing is to know which files in your theme are used to display the archive. Different themes have different template files, but all themes have an index.php template. The index.php template is used to display all content, unless a template exists higher up in the hierarchy. WordPress’ template hierarchy is the system that dictates which template file is used to display which content. We’ll briefly go over the template hierarchy for categories, tags and custom taxonomies. If you’d like to learn more, these resources are highly recommended:
“Template Hierarchy2,” WordPress Codex
“Template Hierarchy3,” Chip Bennett
A flow chart
The WordPress Template Hierarchy: A Mini Resource4, Rami Abraham and Michelle Schulp
An interactive chart
Reveal Template5, Scott Reilly
A WordPress plugin
Most themes have an archive.php template, which is used for category and tag archives, as well as date and author archives. You can add a template file to handle category and tag archives separately. These templates would be named category.php or tag.php, respectively. You could also create templates for specific tags or categories, using the ID or slug of the category or tag. For example, a tag with the ID of 7 would use tag-7.php, if it exists, rather than tag.php or archive.php. A tag with the slug of “avocado” would be displayed using the tag-avocado.php template.
One tricky thing to keep in mind is that a template named after a slug will override a template named after an ID number. So, if a tag with the slug of “avocado” had an ID of 7, then tag-avocado.php would override tag-7.php, if it exists.
The template hierarchy for custom taxonomies is a little different, because there are templates for all taxonomies, for specific taxonomies and for specific terms in a specific taxonomy. So, imagine that you have two taxonomies, “fruits” and “vegetables,” and the “fruits” taxonomy has two terms, “apples” and “oranges,” while “vegetables” has two terms, “carrots” and “celery.” Let’s add three templates to our website’s theme: taxonomy.php, taxonomy-fruits.php and taxonomy-vegetables-carrots.php.
For the terms in the “fruits” taxonomy, all archives would be generated using taxonomy-fruits.php because no term-specific template exists. On the other hand, the term “carrots” in the “vegetables” taxonomy’s archives would be generated using taxonomy-vegetables-carrots.php. Because no taxonomy-vegetables.php template exists, all other terms in “vegetables” would be generated using taxonomy.php.
Using Conditional Tags
While you can add any of the custom templates listed above to create a totally unique view for any category, tag, custom taxonomy or custom taxonomy term, sometimes all you want to do is make one or two little changes. In fact, try to avoid creating a lot of templates because you will need to adjust each one when you make overall changes to the basic HTML markup that you use in each template in the theme. Unless I need a template that is radically different from the theme’s archive.php, I tend to stick to adding conditional changes to archive.php.
WordPress provides conditional functions to determine whether a category, tag or custom taxonomy is being displayed. To determine whether a category archive is being shown, you can use is_category() for categories, is_tag() for tags and is_tax() for custom taxonomies. The is_tag() and is_category() functions can also test for specific categories or tags by slug or ID. For example:
&lt;?php
    if ( is_tag() ) 
        echo "True for any tag!";
    
    if ( is_tag( 'jedis' ) ) 
        echo "True for the tag whose slug is jedi";
    
    if ( is_tag( array( 'jedi', 'sith' ) ) ) 
        echo "True for tags whose slug is jedi or sith";
    
    if ( is_tag( 7 ) ) 
        echo "You can also use tag IDs. This is true for tag ID 7";
    
?&gt;

For custom taxonomies, the is_tax() function can be used to check whether any taxonomy (not including categories and tags), a specific taxonomy or a specific term in a taxonomy is being shown. For example:
&lt;?php
    if ( is_tax() ) 
        echo "True for any custom taxonomy.";
    
    if ( is_tax( 'vegetable' ) ) 
        echo "True for any term in the vegetable taxonomy.";
    
    if ( is_tax( 'vegetable', 'celery' ) ) 
        echo "True only for the term celery, in the vegetable taxonomy.";
    
?&gt;

Creating Custom Taxonomies
Adding a custom taxonomy can be done in one of three ways: coding it manually according to the instructions in the Codex, which I don’t recommend; generating the code using GenerateWP6; or using a plugin for custom content types, such as Pods7 or Types8. Plugins for custom content types enable you to create custom taxonomies and custom post types in WordPress’ back end without having to write any code. Using one is the easiest way to add a custom taxonomy and to get a framework for working with custom content types.
If you opt for one of the first two options, rather than a plugin, then you will need to add the code either to your theme’s functions.php file or to a custom plugin. I strongly recommend creating a custom plugin, rather than adding the code to functions.php. Even if you’ve never created a plugin before, I urge you to do it. While adding the code to your theme’s functions.php will work, when you switch themes (say, because you want to use a new theme or to troubleshoot a problem), the taxonomy will no longer work.
Whether you write your custom taxonomy code by following the directions in the Codex or by generating it with GenerateWP, just paste it in a text file and add one line of code before it and you’ll have a plugin. Upload it and install it as you would any other plugin.
The only line you need to create a custom plugin is /* Plugin name: Custom Taxonomy */.
Below is a plugin to register a custom taxonomy named “vegetables,” which I created using GenerateWP because it’s significantly easier and way less likely to contain errors than doing it manually:
&lt;?php
    /* Plugin Name: Veggie Taxonomy */
    if ( ! function_exists( 'slug_veggies_tax' ) ) 

    // Register Custom Taxonomy
    function slug_veggies_tax() 

    $labels = array(
    'name'                      	=&gt; _x( 'Vegetables', 'Taxonomy General Name', 'text_domain' ),
    'singular_name'              	=&gt; _x( 'Vegetable', 'Taxonomy Singular Name', 'text_domain' ),
    'menu_name'                  	=&gt; __( 'Taxonomy', 'text_domain' ),
    'all_Veggies'                   =&gt; __( 'All Veggies', 'text_domain' ),
    'parent_Veggie'                 =&gt; __( 'Parent Veggie', 'text_domain' ),
    'parent_Veggie_colon'           =&gt; __( 'Parent Veggie:', 'text_domain' ),
    'new_Veggie_name'               =&gt; __( 'New Veggie name', 'text_domain' ),
    'add_new_Veggie'                =&gt; __( 'Add new Veggie', 'text_domain' ),
    'edit_Veggie'                   =&gt; __( 'Edit Veggie', 'text_domain' ),
    'update_Veggie'                 =&gt; __( 'Update Veggie', 'text_domain' ),
    'separate_Veggies_with_commas'  =&gt; __( 'Separate Veggies with commas', 'text_domain' ),
    'search_Veggies'                =&gt; __( 'Search Veggies', 'text_domain' ),
    'add_or_remove_Veggies'         =&gt; __( 'Add or remove Veggies', 'text_domain' ),
    'choose_from_most_used'         =&gt; __( 'Choose from the most used Veggies', 'text_domain' ),
    'not_found'                     =&gt; __( 'Not Found', 'text_domain' ),
    );
    $args = array(
    'labels'                     =&gt; $labels,
    'hierarchical'               =&gt; false,
    'public'                     =&gt; true,
    'show_ui'                    =&gt; true,
    'show_admin_column'          =&gt; true,
    'show_in_nav_menus'          =&gt; true,
    'show_tagcloud'              =&gt; false,
    );
    register_taxonomy( 'vegetable', array( 'post' ), $args );

    

    // Hook into the 'init' action
    add_action( 'init', 'slug_veggies_tax', 0 );

    
?&gt;

By the way, I created this code using GenerateWP in less than two minutes! The service is great, and manually writing code that this website can automatically generate for you makes no sense. To make the process even easier, you can use the plugin Pluginception9 to create a blank plugin for you and then paste the code from GenerateWP into it using WordPress’ plugin editor.
Using WP_Query With Custom Taxonomies
Once you have added a custom taxonomy, you might want to query for posts with terms in that taxonomy. To do this, we can use taxonomy queries with WP_QUERY.
Taxonomy queries can be very simple or complicated. The simplest query would be for all posts with a certain term. For example, if you had a post type named “jedi” and an associated custom taxonomy named “level,” then you could get all Jedi masters like this:
&lt;?php
    $args = array(
        'post_type' =&gt; 'jedi',
        'level' =&gt; 'master'
    );
    $query = new WP_Query( $args );
?&gt;

If you added a second custom taxonomy named “era,” then you could find all Jedi masters of the Old Republic like this:
&lt;?php
    $args = array(
        'post_type' =&gt; 'jedi',
        'level' =&gt; 'master',
        'era' =&gt; 'old-republic',
    );
    $query = new WP_Query( $args );
?&gt;

We can also do more complicated comparisons, using a full tax_query. The tax_query argument enables us to search by ID instead of slug (as we did before) and to search for more than one term. It also enables us to combine multiple taxonomy queries and to set the relationship between the two. In addition, we can even use SQL operators such as NOT IN to exclude terms.
The possibilities are endless. Explore the “Taxonomy Parameters10” section of the Codex page for “Class Reference/WP_Query” for complete information. The snippet below searches our “jedi” post type for Jedi knights and masters who are not from the Old Republic era:
&lt;?php
    $args = array(
        'post_type' =&gt; 'jedi',
        'tax_query' =&gt; array(
        'relation' =&gt; 'AND',
            array(
                'taxonomy' =&gt; 'level',
                'field' =&gt; 'slug',
                'terms' =&gt; array( 'master', 'knight' )
            ),
            array(
                'taxonomy' =&gt; 'era',
                'field' =&gt; 'slug',
                'terms' =&gt; array( 'old-republic' ),
                'operator' =&gt; 'NOT IN'
                )
        )
    );
    $query = new WP_Query( $args );
?&gt;

Customizing Taxonomy Archives
So far, we have covered how taxonomies, tags and categories work by default, as well as how to create custom taxonomies. If any of this default behavior doesn’t fit your needs, you can always modify it. We’ll go over some ways to modify WordPress’ built-in functionality for those of you who use WordPress less as a blogging platform and more as a content management system, which often requires custom taxonomies.
Hello pre_get_posts
Before any posts are outputted by the WordPress loop, WordPress automatically retrieves the posts for the user according to the page they are on, using the WP_QUERY class. For example, in the main blog index, it gets the most recent posts. In a taxonomy archive, it gets the most recent posts in that taxonomy.
To change that query, you can use the pre_get_posts filter before WordPress gets any posts. This filter exposes the query object after it is set but before it is used to actually get any posts. This means that you can modify the query using the class methods before the main WordPress loop is run. If that sounds confusing, don’t worry — the next few sections of this article give practical examples of how this works.
Adding Custom Post Types to Category or Tag Archives
A great use of modifying the WP_QUERY object using pre_get_posts is to add posts from a custom post type to the category archive. By default, custom post types are not included in this query. If we were constructing arguments to be passed to WP_Query and wanted to include both regular posts and posts in the custom post type “jedi,” then our argument would look like this:
&lt;?php
    $args = array( 'post_type' =&gt;
        array(
            'post',
            'jedi'
        )
    );
?&gt;

In the callback for our pre_get_posts filter, we need to pass a similar argument. The problem is that the WP_QUERY object already exists, so we can’t pass an argument to it like we do when creating an instance of the class. Instead, we use the set() class method, which allows us to change any of the arguments after the class has been created.
In the snippet below, we use set() to change the post_type argument from the default value, which is post, to an array of post types, including posts and our custom post type “jedi.” Note that we are using the conditional tag is_category() so that the change happens only when category archives are being displayed.
&lt;?php
    add_filter( 'pre_get_posts', 'slug_cpt_category_archives' );
    function slug_cpt_category_archives( $query ) 
    if ( is_category() &amp;&amp; is_main_query()  )  
        $query-&gt;set( 'post_type',
            array(
                'post',
                'jedi'
            )
        );
    

    return $query;

    
?&gt;

This function’s $query parameter is the WP_QUERY object before it is used to populate the main loop. Because a page may include multiple loops, such as those used by widgets, we use the conditional function is_main_query() to ensure that this affects only the main loop and not any secondary loops on the page, such as those used by widgets.
Making Category or Hierarchical Taxonomy Archives Hierarchical
By default, the archives for categories and other hierarchical taxonomies act like any other taxonomy archive: they show all posts in that category or with that taxonomy term. To show only parent terms and exclude child terms, you would use the pre_get_posts filter again.
Just like when creating your own WP_QUERY for posts in a taxonomy, the main loop’s WP_QUERY uses the tax_query arguments to get posts by taxonomy. The tax_query has an include_children argument, which by default is set to 1 or true. By changing it to 0 or false, we can prevent posts with a child term from being included in the archive:
&lt;?php
    add_action( 'pre_get_posts', 'slug_cpt_category_archives' );
    function slug_cpt_category_archives( $query ) 
        if ( is_tax( 'TAXONOMY NAME') )  
            $tax_query = $query-&gt;tax_query-&gt;queries;
            $tax_query['include_children'] = 0;
            $query-&gt;set( 'tax_query', $tax_query );
        

    
?&gt;

The result sounds desirable but has several major shortcomings. That’s OK, because if we address those flaws, we’ll have taken the first step to creating something very cool.
The first and biggest problem is that the result is not an archive page that shows the child terms; it’s still a post with the parent term. The other problem is that we don’t have a good way to navigate to the child term archives.
A good way to deal with this is to combine the pre_get_post filter above with a modification to the template that shows the category or taxonomy. We discussed earlier how to determine which template is used to output category or custom taxonomy archives. Also, keep in mind that you can always wrap your changes in conditional tags, such as is_category() or is_tax(), but that can become unwieldy quickly; so, making a copy of your archive.php and removing any unneeded code probably makes more sense.
The first step is to wrap the entire thing in a check to see whether the current taxonomy term has children. If it does not, then we do not want to output anything. To do this, we use get_term_children(), which will return an empty array if the current term has no children and which we can test for with !empty().
To make this work for any taxonomy that might be displayed, we need to get the current taxonomy and taxonomy term from the query_vars array of the global $wp_query object. The taxonomy’s slug is contained in the taxonomy key, and the term’s slug is in the tax key.
To use get_term_children(), we must have the term’s ID. The ID is not in query_vars, but we can pass the slug to  get_term_by() to get it.
Here is how we get all of the information that we need into variables:
&lt;?php
    global $wp_query;
    $taxonomy = $wp_query-&gt;query_vars['taxonomy'];
    $term = $wp_query-&gt;query_vars['tax'];
    $term_id = get_term_by( 'slug', $term, $taxonomy );
    $term_id = $term_id-&gt;term_id;
    $terms = get_term_children( $term_id, $taxonomy );
?&gt;

Now we will continue only if $terms isn’t an empty array. To see whether it is empty in our check, first we will repopulate the terms using get_terms(). This is necessary because get_term_children returns only an array of IDs, and we need IDs and names, both of which are in the object returned by get_terms(). We can loop through this object, outputting the name as a link. The link can be generated by passing the term’s ID to get_term_link().
Here is the complete code:
&lt;?php
    global $wp_query;
    $taxonomy = $wp_query-&gt;query_vars['taxonomy'];
    $term = $wp_query-&gt;query_vars['tax'];
    $term_id = get_term_by( 'slug', $term, $taxonomy );
    $term_id = $term_id-&gt;term_id;
    $terms = get_term_children( $term_id, $taxonomy );
    if ( !empty( $terms ) ) {
    $terms = get_terms( $taxonomy, array( 'child_of' =&gt; $term_id ) );
    echo '&lt;ul class="child-term-list"&gt;';
    foreach ( $terms as $term ) 
    echo '&lt;li&gt;&lt;a href="'.$term-&gt;term_id.'"&gt;'.$term-&gt;name.'&lt;/a&gt;&lt;/li&gt;';
    

    echo '&lt;/ul&gt;';

?&gt;

Creating A Custom Landing Page For Taxonomy Archives
If your hierarchical taxonomy has no terms in the parent term, then the regular taxonomy archive system will be of no use to you. You really want to show taxonomy links instead.
In this case, a good option is to create a custom landing page for the term. We’ll use query_vars again to determine whether the user is on the first page of a taxonomy archive; if so, we will use the taxonomy_archive filter to include a separate template, like this:
&lt;?php
    add_filter( 'taxonomy_archive ', 'slug_tax_page_one' );
    function slug_tax_page_one( $template ) 
        if ( is_tax( 'TAXONOMY_NAME' ) ) 
             global $wp_query;
             $page = $wp_query-&gt;query_vars['paged'];
            if ( $page = 0 ) 
                $template = get_stylesheet_directory(). '/taxonomy-page-one.php';
            
        

        return $template;

    
?&gt;

This callback first checks that the user is in the taxonomy that we want to target. We can target all taxonomies by changing this to just is_tax(). Then, it gets the current page using the query_var named paged, and if the user is on the first page, then it returns the address for the new template file. If not, it returns the default template file.
What you put in that template file is up to you. You can create a list of terms using the code shown above. You can use it to output any content, really — for example, more information about the taxonomy term or links to specific posts.
Taking Control
With a bit of work, WordPress’ basic architecture, which still reflects its origins as a blogging platform, can be customized to fit almost any website or Web app. Using custom taxonomies to organize your content and doing it in a way that suits your needs will be an important step in many of your WordPress projects. Hopefully, this post has brought you a step closer to getting the most out of this powerful aspect of WordPress.
(dp, al, il)
Footnotes
1 http://wphierarchy.com/
2 https://codex.wordpress.org/Template_Hierarchy
3 http://www.chipbennett.net/themes/template-hierarchy/
4 http://wphierarchy.com/
5 https://wordpress.org/plugins/reveal-template/
6 http://generatewp.com/
7 http://pods.io
8 http://wp-types.com/home/types-manage-post-types-taxonomy-and-custom-fields/
9 https://wordpress.org/plugins/pluginception/
10 http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
The post Customizing WordPress Archives For Categories, Terms And Other Taxonomies appeared first on Smashing Magazine.
Source: Smashing Magazine
    

New Post has been published on http://freesourcecode.info/customizing-wordpress-archives-for-categories-terms-and-other-taxonomies/

Customizing WordPress Archives For Categories, Terms And Other Taxonomies

By Josh Pollock

wordpress-categories-taxonomies-opt

Most WordPress users are familiar with tags and categories and with how to use them to organize their blog posts. If you use custom post types in WordPress, you might need to organize them like categories and tags. Categories and tags are examples of taxonomies, and WordPress allows you to create as many custom taxonomies as you want. These custom taxonomies operate like categories or tags, but are separate.

In this tutorial, we’ll explain custom taxonomies and how to create them. We’ll also go over which template files in a WordPress theme control the archives of built-in and custom taxonomies, and some advanced techniques for customizing the behavior of taxonomy archives.

Terminology

Before continuing, let’s get our terminology straight. A taxonomy is a WordPress content type, used primarily to organize content of any other content type. The two taxonomies everyone is familiar with are built in: categories and tags. We tend to call an individual posting of a tag a “tag,” but to be precise, we should refer to it as a “term” in the “tag” taxonomy. We pretty much always refer to items in a custom taxonomy as “terms.”

Categories and tags represent the two types of taxonomies: hierarchical and non-hierarchical. Like categories, hierarchical taxonomies can have parent-child relationships between terms in the taxonomy. For example, you might have on your blog a “films” category that has several child categories, with names like “foreign” and “domestic.” Custom taxonomies may also be hierarchical, like categories, or non-hierarchical, like tags.

A small part of the “WordPress Template Hierarchy”. (Source1)

The archive of a taxonomy is the list of posts in a taxonomy that is automatically generated by WordPress. For example, this would be the page you see when you click on a category link and see all posts in that category. We’ll go over how to change the behavior of these pages and learn which template files generate them.

How Tag, Category and Custom Taxonomy Archives Work

For every category, tag and custom taxonomy, WordPress automatically generates an archive that lists each post associated with that taxonomy, in reverse chronological order. The system works really well if you organize your blog posts with categories and tags. If you have a complex system of organizing custom post types with custom taxonomies, then it might not be ideal. We’ll go over the many ways to modify these archives.

The first step to customizing is to know which files in your theme are used to display the archive. Different themes have different template files, but all themes have an index.php template. The index.php template is used to display all content, unless a template exists higher up in the hierarchy. WordPress’ template hierarchy is the system that dictates which template file is used to display which content. We’ll briefly go over the template hierarchy for categories, tags and custom taxonomies. If you’d like to learn more, these resources are highly recommended:

Most themes have an archive.php template, which is used for category and tag archives, as well as date and author archives. You can add a template file to handle category and tag archives separately. These templates would be named category.php or tag.php, respectively. You could also create templates for specific tags or categories, using the ID or slug of the category or tag. For example, a tag with the ID of 7 would use tag-7.php, if it exists, rather than tag.php or archive.php. A tag with the slug of “avocado” would be displayed using the tag-avocado.php template.

One tricky thing to keep in mind is that a template named after a slug will override a template named after an ID number. So, if a tag with the slug of “avocado” had an ID of 7, then tag-avocado.php would override tag-7.php, if it exists.

The template hierarchy for custom taxonomies is a little different, because there are templates for all taxonomies, for specific taxonomies and for specific terms in a specific taxonomy. So, imagine that you have two taxonomies, “fruits” and “vegetables,” and the “fruits” taxonomy has two terms, “apples” and “oranges,” while “vegetables” has two terms, “carrots” and “celery.” Let’s add three templates to our website’s theme: taxonomy.php, taxonomy-fruits.php and taxonomy-vegetables-carrots.php.

For the terms in the “fruits” taxonomy, all archives would be generated using taxonomy-fruits.php because no term-specific template exists. On the other hand, the term “carrots” in the “vegetables” taxonomy’s archives would be generated using taxonomy-vegetables-carrots.php. Because no taxonomy-vegetables.php template exists, all other terms in “vegetables” would be generated using taxonomy.php.

Using Conditional Tags

While you can add any of the custom templates listed above to create a totally unique view for any category, tag, custom taxonomy or custom taxonomy term, sometimes all you want to do is make one or two little changes. In fact, try to avoid creating a lot of templates because you will need to adjust each one when you make overall changes to the basic HTML markup that you use in each template in the theme. Unless I need a template that is radically different from the theme’s archive.php, I tend to stick to adding conditional changes to archive.php.

WordPress provides conditional functions to determine whether a category, tag or custom taxonomy is being displayed. To determine whether a category archive is being shown, you can use is_category() for categories, is_tag() for tags and is_tax() for custom taxonomies. The is_tag() and is_category() functions can also test for specific categories or tags by slug or ID. For example:

<?php
    if ( is_tag() ) 
        echo "True for any tag!";
    
    if ( is_tag( 'jedis' ) ) 
        echo "True for the tag whose slug is jedi";
    
    if ( is_tag( array( 'jedi', 'sith' ) ) ) 
        echo "True for tags whose slug is jedi or sith";
    
    if ( is_tag( 7 ) ) 
        echo "You can also use tag IDs. This is true for tag ID 7";
    
?>

For custom taxonomies, the is_tax() function can be used to check whether any taxonomy (not including categories and tags), a specific taxonomy or a specific term in a taxonomy is being shown. For example:

<?php
    if ( is_tax() ) 
        echo "True for any custom taxonomy.";
    
    if ( is_tax( 'vegetable' ) ) 
        echo "True for any term in the vegetable taxonomy.";
    
    if ( is_tax( 'vegetable', 'celery' ) ) 
        echo "True only for the term celery, in the vegetable taxonomy.";
    
?>

Creating Custom Taxonomies

Adding a custom taxonomy can be done in one of three ways: coding it manually according to the instructions in the Codex, which I don’t recommend; generating the code using GenerateWP6; or using a plugin for custom content types, such as Pods7 or Types8. Plugins for custom content types enable you to create custom taxonomies and custom post types in WordPress’ back end without having to write any code. Using one is the easiest way to add a custom taxonomy and to get a framework for working with custom content types.

If you opt for one of the first two options, rather than a plugin, then you will need to add the code either to your theme’s functions.php file or to a custom plugin. I strongly recommend creating a custom plugin, rather than adding the code to functions.php. Even if you’ve never created a plugin before, I urge you to do it. While adding the code to your theme’s functions.php will work, when you switch themes (say, because you want to use a new theme or to troubleshoot a problem), the taxonomy will no longer work.

Whether you write your custom taxonomy code by following the directions in the Codex or by generating it with GenerateWP, just paste it in a text file and add one line of code before it and you’ll have a plugin. Upload it and install it as you would any other plugin.

The only line you need to create a custom plugin is /* Plugin name: Custom Taxonomy */.

Below is a plugin to register a custom taxonomy named “vegetables,” which I created using GenerateWP because it’s significantly easier and way less likely to contain errors than doing it manually:

<?php
    /* Plugin Name: Veggie Taxonomy */
    if ( ! function_exists( 'slug_veggies_tax' ) ) 

    // Register Custom Taxonomy
    function slug_veggies_tax() 

    $labels = array(
    'name'                      	=> _x( 'Vegetables', 'Taxonomy General Name', 'text_domain' ),
    'singular_name'              	=> _x( 'Vegetable', 'Taxonomy Singular Name', 'text_domain' ),
    'menu_name'                  	=> __( 'Taxonomy', 'text_domain' ),
    'all_Veggies'                   => __( 'All Veggies', 'text_domain' ),
    'parent_Veggie'                 => __( 'Parent Veggie', 'text_domain' ),
    'parent_Veggie_colon'           => __( 'Parent Veggie:', 'text_domain' ),
    'new_Veggie_name'               => __( 'New Veggie name', 'text_domain' ),
    'add_new_Veggie'                => __( 'Add new Veggie', 'text_domain' ),
    'edit_Veggie'                   => __( 'Edit Veggie', 'text_domain' ),
    'update_Veggie'                 => __( 'Update Veggie', 'text_domain' ),
    'separate_Veggies_with_commas'  => __( 'Separate Veggies with commas', 'text_domain' ),
    'search_Veggies'                => __( 'Search Veggies', 'text_domain' ),
    'add_or_remove_Veggies'         => __( 'Add or remove Veggies', 'text_domain' ),
    'choose_from_most_used'         => __( 'Choose from the most used Veggies', 'text_domain' ),
    'not_found'                     => __( 'Not Found', 'text_domain' ),
    );
    $args = array(
    'labels'                     => $labels,
    'hierarchical'               => false,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
    'show_tagcloud'              => false,
    );
    register_taxonomy( 'vegetable', array( 'post' ), $args );

    

    // Hook into the 'init' action
    add_action( 'init', 'slug_veggies_tax', 0 );

    
?>

By the way, I created this code using GenerateWP in less than two minutes! The service is great, and manually writing code that this website can automatically generate for you makes no sense. To make the process even easier, you can use the plugin Pluginception9 to create a blank plugin for you and then paste the code from GenerateWP into it using WordPress’ plugin editor.

Using WP_Query With Custom Taxonomies

Once you have added a custom taxonomy, you might want to query for posts with terms in that taxonomy. To do this, we can use taxonomy queries with WP_QUERY.

Taxonomy queries can be very simple or complicated. The simplest query would be for all posts with a certain term. For example, if you had a post type named “jedi” and an associated custom taxonomy named “level,” then you could get all Jedi masters like this:

<?php
    $args = array(
        'post_type' => 'jedi',
        'level' => 'master'
    );
    $query = new WP_Query( $args );
?>

If you added a second custom taxonomy named “era,” then you could find all Jedi masters of the Old Republic like this:

<?php
    $args = array(
        'post_type' => 'jedi',
        'level' => 'master',
        'era' => 'old-republic',
    );
    $query = new WP_Query( $args );
?>

We can also do more complicated comparisons, using a full tax_query. The tax_query argument enables us to search by ID instead of slug (as we did before) and to search for more than one term. It also enables us to combine multiple taxonomy queries and to set the relationship between the two. In addition, we can even use SQL operators such as NOT IN to exclude terms.

The possibilities are endless. Explore the “Taxonomy Parameters10” section of the Codex page for “Class Reference/WP_Query” for complete information. The snippet below searches our “jedi” post type for Jedi knights and masters who are not from the Old Republic era:

<?php
    $args = array(
        'post_type' => 'jedi',
        'tax_query' => array(
        'relation' => 'AND',
            array(
                'taxonomy' => 'level',
                'field' => 'slug',
                'terms' => array( 'master', 'knight' )
            ),
            array(
                'taxonomy' => 'era',
                'field' => 'slug',
                'terms' => array( 'old-republic' ),
                'operator' => 'NOT IN'
                )
        )
    );
    $query = new WP_Query( $args );
?>

Customizing Taxonomy Archives

So far, we have covered how taxonomies, tags and categories work by default, as well as how to create custom taxonomies. If any of this default behavior doesn’t fit your needs, you can always modify it. We’ll go over some ways to modify WordPress’ built-in functionality for those of you who use WordPress less as a blogging platform and more as a content management system, which often requires custom taxonomies.

Hello pre_get_posts

Before any posts are outputted by the WordPress loop, WordPress automatically retrieves the posts for the user according to the page they are on, using the WP_QUERY class. For example, in the main blog index, it gets the most recent posts. In a taxonomy archive, it gets the most recent posts in that taxonomy.

To change that query, you can use the pre_get_posts filter before WordPress gets any posts. This filter exposes the query object after it is set but before it is used to actually get any posts. This means that you can modify the query using the class methods before the main WordPress loop is run. If that sounds confusing, don’t worry — the next few sections of this article give practical examples of how this works.

Adding Custom Post Types to Category or Tag Archives

A great use of modifying the WP_QUERY object using pre_get_posts is to add posts from a custom post type to the category archive. By default, custom post types are not included in this query. If we were constructing arguments to be passed to WP_Query and wanted to include both regular posts and posts in the custom post type “jedi,” then our argument would look like this:

<?php
    $args = array( 'post_type' =>
        array(
            'post',
            'jedi'
        )
    );
?>

In the callback for our pre_get_posts filter, we need to pass a similar argument. The problem is that the WP_QUERY object already exists, so we can’t pass an argument to it like we do when creating an instance of the class. Instead, we use the set() class method, which allows us to change any of the arguments after the class has been created.

In the snippet below, we use set() to change the post_type argument from the default value, which is post, to an array of post types, including posts and our custom post type “jedi.” Note that we are using the conditional tag is_category() so that the change happens only when category archives are being displayed.

<?php
    add_filter( 'pre_get_posts', 'slug_cpt_category_archives' );
    function slug_cpt_category_archives( $query ) 
    if ( is_category() && is_main_query()  )  
        $query->set( 'post_type',
            array(
                'post',
                'jedi'
            )
        );
    

    return $query;

    
?>

This function’s $query parameter is the WP_QUERY object before it is used to populate the main loop. Because a page may include multiple loops, such as those used by widgets, we use the conditional function is_main_query() to ensure that this affects only the main loop and not any secondary loops on the page, such as those used by widgets.

Making Category or Hierarchical Taxonomy Archives Hierarchical

By default, the archives for categories and other hierarchical taxonomies act like any other taxonomy archive: they show all posts in that category or with that taxonomy term. To show only parent terms and exclude child terms, you would use the pre_get_posts filter again.

Just like when creating your own WP_QUERY for posts in a taxonomy, the main loop’s WP_QUERY uses the tax_query arguments to get posts by taxonomy. The tax_query has an include_children argument, which by default is set to 1 or true. By changing it to 0 or false, we can prevent posts with a child term from being included in the archive:

<?php
    add_action( 'pre_get_posts', 'slug_cpt_category_archives' );
    function slug_cpt_category_archives( $query ) 
        if ( is_tax( 'TAXONOMY NAME') )  
            $tax_query = $query->tax_query->queries;
            $tax_query['include_children'] = 0;
            $query->set( 'tax_query', $tax_query );
        

    
?>

The result sounds desirable but has several major shortcomings. That’s OK, because if we address those flaws, we’ll have taken the first step to creating something very cool.

The first and biggest problem is that the result is not an archive page that shows the child terms; it’s still a post with the parent term. The other problem is that we don’t have a good way to navigate to the child term archives.

A good way to deal with this is to combine the pre_get_post filter above with a modification to the template that shows the category or taxonomy. We discussed earlier how to determine which template is used to output category or custom taxonomy archives. Also, keep in mind that you can always wrap your changes in conditional tags, such as is_category() or is_tax(), but that can become unwieldy quickly; so, making a copy of your archive.php and removing any unneeded code probably makes more sense.

The first step is to wrap the entire thing in a check to see whether the current taxonomy term has children. If it does not, then we do not want to output anything. To do this, we use get_term_children(), which will return an empty array if the current term has no children and which we can test for with !empty().

To make this work for any taxonomy that might be displayed, we need to get the current taxonomy and taxonomy term from the query_vars array of the global $wp_query object. The taxonomy’s slug is contained in the taxonomy key, and the term’s slug is in the tax key.

To use get_term_children(), we must have the term’s ID. The ID is not in query_vars, but we can pass the slug to get_term_by() to get it.

Here is how we get all of the information that we need into variables:

<?php
    global $wp_query;
    $taxonomy = $wp_query->query_vars['taxonomy'];
    $term = $wp_query->query_vars['tax'];
    $term_id = get_term_by( 'slug', $term, $taxonomy );
    $term_id = $term_id->term_id;
    $terms = get_term_children( $term_id, $taxonomy );
?>

Now we will continue only if $terms isn’t an empty array. To see whether it is empty in our check, first we will repopulate the terms using get_terms(). This is necessary because get_term_children returns only an array of IDs, and we need IDs and names, both of which are in the object returned by get_terms(). We can loop through this object, outputting the name as a link. The link can be generated by passing the term’s ID to get_term_link().

Here is the complete code:

<?php
    global $wp_query;
    $taxonomy = $wp_query->query_vars['taxonomy'];
    $term = $wp_query->query_vars['tax'];
    $term_id = get_term_by( 'slug', $term, $taxonomy );
    $term_id = $term_id->term_id;
    $terms = get_term_children( $term_id, $taxonomy );
    if ( !empty( $terms ) ) {
    $terms = get_terms( $taxonomy, array( 'child_of' => $term_id ) );
    echo '<ul class="child-term-list">';
    foreach ( $terms as $term ) 
    echo '<li><a href="'.$term->term_id.'">'.$term->name.'</a></li>';
    

    echo '</ul>';

?>

Creating A Custom Landing Page For Taxonomy Archives

If your hierarchical taxonomy has no terms in the parent term, then the regular taxonomy archive system will be of no use to you. You really want to show taxonomy links instead.

In this case, a good option is to create a custom landing page for the term. We’ll use query_vars again to determine whether the user is on the first page of a taxonomy archive; if so, we will use the taxonomy_archive filter to include a separate template, like this:

<?php
    add_filter( 'taxonomy_archive ', 'slug_tax_page_one' );
    function slug_tax_page_one( $template ) 
        if ( is_tax( 'TAXONOMY_NAME' ) ) 
             global $wp_query;
             $page = $wp_query->query_vars['paged'];
            if ( $page = 0 ) 
                $template = get_stylesheet_directory(). '/taxonomy-page-one.php';
            
        

        return $template;

    
?>

This callback first checks that the user is in the taxonomy that we want to target. We can target all taxonomies by changing this to just is_tax(). Then, it gets the current page using the query_var named paged, and if the user is on the first page, then it returns the address for the new template file. If not, it returns the default template file.

What you put in that template file is up to you. You can create a list of terms using the code shown above. You can use it to output any content, really — for example, more information about the taxonomy term or links to specific posts.

Taking Control

With a bit of work, WordPress’ basic architecture, which still reflects its origins as a blogging platform, can be customized to fit almost any website or Web app. Using custom taxonomies to organize your content and doing it in a way that suits your needs will be an important step in many of your WordPress projects. Hopefully, this post has brought you a step closer to getting the most out of this powerful aspect of WordPress.

(dp, al, il)

Footnotes

  1. 1 http://wphierarchy.com/
  2. 2 https://codex.wordpress.org/Template_Hierarchy
  3. 3 http://www.chipbennett.net/themes/template-hierarchy/
  4. 4 http://wphierarchy.com/
  5. 5 https://wordpress.org/plugins/reveal-template/
  6. 6 http://generatewp.com/
  7. 7 http://pods.io
  8. 8 http://wp-types.com/home/types-manage-post-types-taxonomy-and-custom-fields/
  9. 9 https://wordpress.org/plugins/pluginception/
  10. 10 http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

The post Customizing WordPress Archives For Categories, Terms And Other Taxonomies appeared first on Smashing Magazine.

Source: Smashing Magazine

    

New Post has been published on http://nzbusinessdirectory.info/webdesign/google-updates-adwords-again/Google Updates AdWords AgainEarlier this month saw the decision by Google AdWords to take down the close variants option, which caused a lot of ripples in the digital marketing community. However, the latest decision that Google made to its AdWords platform may make up for that because they recently announced the addition of a feature that gives back more control to the user over their automatic bidding platform – the ability to select which type of conversion drives it.
Source: Web Design Deals
    

New Post has been published on http://nzbusinessdirectory.info/webdesign/google-updates-adwords-again/

Google Updates AdWords Again

Earlier this month saw the decision by Google AdWords to take down the close variants option, which caused a lot of ripples in the digital marketing community. However, the latest decision that Google made to its AdWords platform may make up for that because they recently announced the addition of a feature that gives back more control to the user over their automatic bidding platform – the ability to select which type of conversion drives it.

Source: Web Design Deals

    

New Post has been published on http://nzbusinessdirectory.info/webdesign/a-quick-tour-of-wordpress-4-0/A Quick Tour Of WordPress 4.0By  Daniel Pataki

Today, WordPress has released the first release candidate1 (RC) for the upcoming 4.0 version. According to the official version numbering2, WordPress 4.0 is no more or less significant than 3.9 was or 4.1 will be. That being said, a new major release is always a cause for excitement! Let’s take a look at the new features the good guys at WordPress have been working on for us.
Installation Language
Since I’ve always used WordPress in English, it took me a while to realize how important internationalization is. 29% of all WordPress.com installations3 use a non-English language which is huge and not that far from over a quarter of all installations. Version 4.0 makes it much easier to get WordPress to speak your language. In fact, the first installation screen asks you to choose your native tongue. Nice!
This is a big step up from either having to download in your own language, or grabbing language files manually and modifying the config.
Embed Previews For URLs
Embedding content into posts has also become a much nicer process. One of my irks with the visual editor used to be that it wasn’t visual enough. Not that long ago, you just got a grey box in place of a gallery or other media/embed items. The “Smith” release took care of galleries and 4.0 is taking care of a host of other items. If you paste a YouTube URL in text mode, it will render as a video in visual mode. How handy is that?
I find this a lot more pleasing to work with — I see exactly what I’m going to get. The media modal’s insert from the URL feature is getting the same upgrade. As soon as you’ve entered a URL, the video will load — playable and all! The good news is that it works with all the services you’d expect, from Vimeo to Twitter, Hulu and Flickr. Scott Taylor (who is a core contributor working on this) has kindly gathered some test URLs. I recommend checking out Trac ticket4 to find out more in this regard.
Media Section Grid
The media section now has a grid view by default. This isn’t a groundbreaking coding feat by any measure, but it does introduce a sleeker UI which is perhaps a glimpse of what is coming up in the future.
While this is a minor change, it does give you a way better overview of your media files than the default view of 20 images in a list.
Plugin Discovery And Installation
In my opinion, the plugin “Add New” page got a much needed makeover. The top navigation looks a lot like the new navigation in the media section — another indication of a slightly more modern interface creeping into the system. Plugins in the list view are displayed in a much more visual fashion, and it looks like it’s time for developers to start making thumbnails! While the plugin details screen could use a makeover as well, I’m sure this is a work in progress and will be explored further.
Better Post Editing
One feature I’m particularly happy with is how the editor height has been changed to use screen real estate better. Mark Jaquith painted a great picture5 of the problem:
“The post editor feels like it has been relegated to a box of medium importance on the edit/compose screen.”

This one is a bit difficult to capture in a screenshot, so here’s a quick video of it in action:

UI Improvements For Widget Customization
It’s great that widgets have been included in the theme customizer. Usually, if you had more than five to six widgets, things became a bit too crowded. Fortunately, the new WP version has now put all widgets into a sub-section of the customization screen. This essentially minimizes them when not needed — a welcome UI improvement for sure!
Join The Fun
As always, the latest development versions can be tried out pretty easily. By installing the WordPress Beta Tester6 plugin you can update to the latest beta builds or nightlies and play around with the brand new features.
If you happen to find any bugs, you can add them to the WordPress Trac7 and you can even fix them and contribute to the core! WordPress is a community project, and every little bit helps!
Conclusion
While I agree that WordPress 4.0 isn’t the same leap as 3.0 was, I disagree with this being a problem. Instead of adding more and more features, the team is consolidating existing features and working hard to bring us a better user experience.
The features above will actually affect how I use the day-to-day features of WordPress in a positive way. While I may not be able to post from my Google Glass (partly because I don’t have one), the ability to use WordPress better is far more important.
(il)

Footnotes
1 http://wordpress.org/news/2014/08/wordpress-4-0-release-candidate/
2 http://make.wordpress.org/core/handbook/how-the-release-cycle-works/version-numbering/
3 http://en.wordpress.com/stats/
4 https://core.trac.wordpress.org/ticket/28195#trac-change-15-1401220623215447
5 https://core.trac.wordpress.org/ticket/28328
6 https://wordpress.org/plugins/wordpress-beta-tester/
7 https://core.trac.wordpress.org/
The post A Quick Tour Of WordPress 4.0 appeared first on Smashing Magazine.
Source: Smashing Magazine
    

New Post has been published on http://nzbusinessdirectory.info/webdesign/a-quick-tour-of-wordpress-4-0/

A Quick Tour Of WordPress 4.0

By Daniel Pataki

language-selector-opt

Today, WordPress has released the first release candidate1 (RC) for the upcoming 4.0 version. According to the official version numbering2, WordPress 4.0 is no more or less significant than 3.9 was or 4.1 will be. That being said, a new major release is always a cause for excitement! Let’s take a look at the new features the good guys at WordPress have been working on for us.

Installation Language

Since I’ve always used WordPress in English, it took me a while to realize how important internationalization is. 29% of all WordPress.com installations3 use a non-English language which is huge and not that far from over a quarter of all installations. Version 4.0 makes it much easier to get WordPress to speak your language. In fact, the first installation screen asks you to choose your native tongue. Nice!

This is a big step up from either having to download in your own language, or grabbing language files manually and modifying the config.

Embed Previews For URLs

Embedding content into posts has also become a much nicer process. One of my irks with the visual editor used to be that it wasn’t visual enough. Not that long ago, you just got a grey box in place of a gallery or other media/embed items. The “Smith” release took care of galleries and 4.0 is taking care of a host of other items. If you paste a YouTube URL in text mode, it will render as a video in visual mode. How handy is that?

embedding-urls-opt

I find this a lot more pleasing to work with — I see exactly what I’m going to get. The media modal’s insert from the URL feature is getting the same upgrade. As soon as you’ve entered a URL, the video will load — playable and all! The good news is that it works with all the services you’d expect, from Vimeo to Twitter, Hulu and Flickr. Scott Taylor (who is a core contributor working on this) has kindly gathered some test URLs. I recommend checking out Trac ticket4 to find out more in this regard.

Media Section Grid

The media section now has a grid view by default. This isn’t a groundbreaking coding feat by any measure, but it does introduce a sleeker UI which is perhaps a glimpse of what is coming up in the future.

media-grid-opt

While this is a minor change, it does give you a way better overview of your media files than the default view of 20 images in a list.

Plugin Discovery And Installation

In my opinion, the plugin “Add New” page got a much needed makeover. The top navigation looks a lot like the new navigation in the media section — another indication of a slightly more modern interface creeping into the system. Plugins in the list view are displayed in a much more visual fashion, and it looks like it’s time for developers to start making thumbnails! While the plugin details screen could use a makeover as well, I’m sure this is a work in progress and will be explored further.

Jetpack-Plugin-opt

Better Post Editing

One feature I’m particularly happy with is how the editor height has been changed to use screen real estate better. Mark Jaquith painted a great picture5 of the problem:

“The post editor feels like it has been relegated to a box of medium importance on the edit/compose screen.”

This one is a bit difficult to capture in a screenshot, so here’s a quick video of it in action:

UI Improvements For Widget Customization

It’s great that widgets have been included in the theme customizer. Usually, if you had more than five to six widgets, things became a bit too crowded. Fortunately, the new WP version has now put all widgets into a sub-section of the customization screen. This essentially minimizes them when not needed — a welcome UI improvement for sure!

Widgets-in-Customizer-opt

Join The Fun

As always, the latest development versions can be tried out pretty easily. By installing the WordPress Beta Tester6 plugin you can update to the latest beta builds or nightlies and play around with the brand new features.

If you happen to find any bugs, you can add them to the WordPress Trac7 and you can even fix them and contribute to the core! WordPress is a community project, and every little bit helps!

Conclusion

While I agree that WordPress 4.0 isn’t the same leap as 3.0 was, I disagree with this being a problem. Instead of adding more and more features, the team is consolidating existing features and working hard to bring us a better user experience.

The features above will actually affect how I use the day-to-day features of WordPress in a positive way. While I may not be able to post from my Google Glass (partly because I don’t have one), the ability to use WordPress better is far more important.

(il)

Footnotes

  1. 1 http://wordpress.org/news/2014/08/wordpress-4-0-release-candidate/
  2. 2 http://make.wordpress.org/core/handbook/how-the-release-cycle-works/version-numbering/
  3. 3 http://en.wordpress.com/stats/
  4. 4 https://core.trac.wordpress.org/ticket/28195#trac-change-15-1401220623215447
  5. 5 https://core.trac.wordpress.org/ticket/28328
  6. 6 https://wordpress.org/plugins/wordpress-beta-tester/
  7. 7 https://core.trac.wordpress.org/

The post A Quick Tour Of WordPress 4.0 appeared first on Smashing Magazine.

Source: Smashing Magazine

    

New Post has been published on http://freesourcecode.info/a-quick-tour-of-wordpress-4-0/A Quick Tour Of WordPress 4.0By  Daniel Pataki

Today, WordPress has released the first release candidate1 (RC) for the upcoming 4.0 version. According to the official version numbering2, WordPress 4.0 is no more or less significant than 3.9 was or 4.1 will be. That being said, a new major release is always a cause for excitement! Let’s take a look at the new features the good guys at WordPress have been working on for us.
Installation Language
Since I’ve always used WordPress in English, it took me a while to realize how important internationalization is. 29% of all WordPress.com installations3 use a non-English language which is huge and not that far from over a quarter of all installations. Version 4.0 makes it much easier to get WordPress to speak your language. In fact, the first installation screen asks you to choose your native tongue. Nice!
This is a big step up from either having to download in your own language, or grabbing language files manually and modifying the config.
Embed Previews For URLs
Embedding content into posts has also become a much nicer process. One of my irks with the visual editor used to be that it wasn’t visual enough. Not that long ago, you just got a grey box in place of a gallery or other media/embed items. The “Smith” release took care of galleries and 4.0 is taking care of a host of other items. If you paste a YouTube URL in text mode, it will render as a video in visual mode. How handy is that?
I find this a lot more pleasing to work with — I see exactly what I’m going to get. The media modal’s insert from the URL feature is getting the same upgrade. As soon as you’ve entered a URL, the video will load — playable and all! The good news is that it works with all the services you’d expect, from Vimeo to Twitter, Hulu and Flickr. Scott Taylor (who is a core contributor working on this) has kindly gathered some test URLs. I recommend checking out Trac ticket4 to find out more in this regard.
Media Section Grid
The media section now has a grid view by default. This isn’t a groundbreaking coding feat by any measure, but it does introduce a sleeker UI which is perhaps a glimpse of what is coming up in the future.
While this is a minor change, it does give you a way better overview of your media files than the default view of 20 images in a list.
Plugin Discovery And Installation
In my opinion, the plugin “Add New” page got a much needed makeover. The top navigation looks a lot like the new navigation in the media section — another indication of a slightly more modern interface creeping into the system. Plugins in the list view are displayed in a much more visual fashion, and it looks like it’s time for developers to start making thumbnails! While the plugin details screen could use a makeover as well, I’m sure this is a work in progress and will be explored further.
Better Post Editing
One feature I’m particularly happy with is how the editor height has been changed to use screen real estate better. Mark Jaquith painted a great picture5 of the problem:
“The post editor feels like it has been relegated to a box of medium importance on the edit/compose screen.”

This one is a bit difficult to capture in a screenshot, so here’s a quick video of it in action:

UI Improvements For Widget Customization
It’s great that widgets have been included in the theme customizer. Usually, if you had more than five to six widgets, things became a bit too crowded. Fortunately, the new WP version has now put all widgets into a sub-section of the customization screen. This essentially minimizes them when not needed — a welcome UI improvement for sure!
Join The Fun
As always, the latest development versions can be tried out pretty easily. By installing the WordPress Beta Tester6 plugin you can update to the latest beta builds or nightlies and play around with the brand new features.
If you happen to find any bugs, you can add them to the WordPress Trac7 and you can even fix them and contribute to the core! WordPress is a community project, and every little bit helps!
Conclusion
While I agree that WordPress 4.0 isn’t the same leap as 3.0 was, I disagree with this being a problem. Instead of adding more and more features, the team is consolidating existing features and working hard to bring us a better user experience.
The features above will actually affect how I use the day-to-day features of WordPress in a positive way. While I may not be able to post from my Google Glass (partly because I don’t have one), the ability to use WordPress better is far more important.
(il)

Footnotes
1 http://wordpress.org/news/2014/08/wordpress-4-0-release-candidate/
2 http://make.wordpress.org/core/handbook/how-the-release-cycle-works/version-numbering/
3 http://en.wordpress.com/stats/
4 https://core.trac.wordpress.org/ticket/28195#trac-change-15-1401220623215447
5 https://core.trac.wordpress.org/ticket/28328
6 https://wordpress.org/plugins/wordpress-beta-tester/
7 https://core.trac.wordpress.org/
The post A Quick Tour Of WordPress 4.0 appeared first on Smashing Magazine.
Source: Smashing Magazine
    

New Post has been published on http://freesourcecode.info/a-quick-tour-of-wordpress-4-0/

A Quick Tour Of WordPress 4.0

By Daniel Pataki

language-selector-opt

Today, WordPress has released the first release candidate1 (RC) for the upcoming 4.0 version. According to the official version numbering2, WordPress 4.0 is no more or less significant than 3.9 was or 4.1 will be. That being said, a new major release is always a cause for excitement! Let’s take a look at the new features the good guys at WordPress have been working on for us.

Installation Language

Since I’ve always used WordPress in English, it took me a while to realize how important internationalization is. 29% of all WordPress.com installations3 use a non-English language which is huge and not that far from over a quarter of all installations. Version 4.0 makes it much easier to get WordPress to speak your language. In fact, the first installation screen asks you to choose your native tongue. Nice!

This is a big step up from either having to download in your own language, or grabbing language files manually and modifying the config.

Embed Previews For URLs

Embedding content into posts has also become a much nicer process. One of my irks with the visual editor used to be that it wasn’t visual enough. Not that long ago, you just got a grey box in place of a gallery or other media/embed items. The “Smith” release took care of galleries and 4.0 is taking care of a host of other items. If you paste a YouTube URL in text mode, it will render as a video in visual mode. How handy is that?

embedding-urls-opt

I find this a lot more pleasing to work with — I see exactly what I’m going to get. The media modal’s insert from the URL feature is getting the same upgrade. As soon as you’ve entered a URL, the video will load — playable and all! The good news is that it works with all the services you’d expect, from Vimeo to Twitter, Hulu and Flickr. Scott Taylor (who is a core contributor working on this) has kindly gathered some test URLs. I recommend checking out Trac ticket4 to find out more in this regard.

Media Section Grid

The media section now has a grid view by default. This isn’t a groundbreaking coding feat by any measure, but it does introduce a sleeker UI which is perhaps a glimpse of what is coming up in the future.

media-grid-opt

While this is a minor change, it does give you a way better overview of your media files than the default view of 20 images in a list.

Plugin Discovery And Installation

In my opinion, the plugin “Add New” page got a much needed makeover. The top navigation looks a lot like the new navigation in the media section — another indication of a slightly more modern interface creeping into the system. Plugins in the list view are displayed in a much more visual fashion, and it looks like it’s time for developers to start making thumbnails! While the plugin details screen could use a makeover as well, I’m sure this is a work in progress and will be explored further.

Jetpack-Plugin-opt

Better Post Editing

One feature I’m particularly happy with is how the editor height has been changed to use screen real estate better. Mark Jaquith painted a great picture5 of the problem:

“The post editor feels like it has been relegated to a box of medium importance on the edit/compose screen.”

This one is a bit difficult to capture in a screenshot, so here’s a quick video of it in action:

UI Improvements For Widget Customization

It’s great that widgets have been included in the theme customizer. Usually, if you had more than five to six widgets, things became a bit too crowded. Fortunately, the new WP version has now put all widgets into a sub-section of the customization screen. This essentially minimizes them when not needed — a welcome UI improvement for sure!

Widgets-in-Customizer-opt

Join The Fun

As always, the latest development versions can be tried out pretty easily. By installing the WordPress Beta Tester6 plugin you can update to the latest beta builds or nightlies and play around with the brand new features.

If you happen to find any bugs, you can add them to the WordPress Trac7 and you can even fix them and contribute to the core! WordPress is a community project, and every little bit helps!

Conclusion

While I agree that WordPress 4.0 isn’t the same leap as 3.0 was, I disagree with this being a problem. Instead of adding more and more features, the team is consolidating existing features and working hard to bring us a better user experience.

The features above will actually affect how I use the day-to-day features of WordPress in a positive way. While I may not be able to post from my Google Glass (partly because I don’t have one), the ability to use WordPress better is far more important.

(il)

Footnotes

  1. 1 http://wordpress.org/news/2014/08/wordpress-4-0-release-candidate/
  2. 2 http://make.wordpress.org/core/handbook/how-the-release-cycle-works/version-numbering/
  3. 3 http://en.wordpress.com/stats/
  4. 4 https://core.trac.wordpress.org/ticket/28195#trac-change-15-1401220623215447
  5. 5 https://core.trac.wordpress.org/ticket/28328
  6. 6 https://wordpress.org/plugins/wordpress-beta-tester/
  7. 7 https://core.trac.wordpress.org/

The post A Quick Tour Of WordPress 4.0 appeared first on Smashing Magazine.

Source: Smashing Magazine

    

New Post has been published on http://freesourcecode.info/google-updates-adwords-again/Google Updates AdWords AgainEarlier this month saw the decision by Google AdWords to take down the close variants option, which caused a lot of ripples in the digital marketing community. However, the latest decision that Google made to its AdWords platform may make up for that because they recently announced the addition of a feature that gives back more control to the user over their automatic bidding platform – the ability to select which type of conversion drives it.
Source: Web Design Deals
    

New Post has been published on http://freesourcecode.info/google-updates-adwords-again/

Google Updates AdWords Again

Earlier this month saw the decision by Google AdWords to take down the close variants option, which caused a lot of ripples in the digital marketing community. However, the latest decision that Google made to its AdWords platform may make up for that because they recently announced the addition of a feature that gives back more control to the user over their automatic bidding platform – the ability to select which type of conversion drives it.

Source: Web Design Deals

    

New Post has been published on http://nzbusinessdirectory.info/webdesign/10-ugliest-web-design-trends-of-all-times/10 Ugliest Web Design Trends of All Times

Web designs are like fashion trends: Some of them are classics while others are best left forgotten. However, they’re still good for a laugh and as a reminder of what happens when you try to get too creative with your design skills. Here are some of the ugliest web design trends of all times. Revisiting history ensures that you won’t repeat these mistakes.Type: Design PrinciplesLevel: All levels
    
Source: Web Design All Tutorials
    

New Post has been published on http://nzbusinessdirectory.info/webdesign/10-ugliest-web-design-trends-of-all-times/

10 Ugliest Web Design Trends of All Times

Web designs are like fashion trends: Some of them are classics while others are best left forgotten. However, they’re still good for a laugh and as a reminder of what happens when you try to get too creative with your design skills. Here are some of the ugliest web design trends of all times. Revisiting history ensures that you won’t repeat these mistakes.
Type: Design Principles
Level: All levels

Source: Web Design All Tutorials

    

New Post has been published on http://freesourcecode.info/10-ugliest-web-design-trends-of-all-times/10 Ugliest Web Design Trends of All Times

Web designs are like fashion trends: Some of them are classics while others are best left forgotten. However, they’re still good for a laugh and as a reminder of what happens when you try to get too creative with your design skills. Here are some of the ugliest web design trends of all times. Revisiting history ensures that you won’t repeat these mistakes.Type: Design PrinciplesLevel: All levels
    
Source: Web Design All Tutorials
    

New Post has been published on http://freesourcecode.info/10-ugliest-web-design-trends-of-all-times/

10 Ugliest Web Design Trends of All Times

Web designs are like fashion trends: Some of them are classics while others are best left forgotten. However, they’re still good for a laugh and as a reminder of what happens when you try to get too creative with your design skills. Here are some of the ugliest web design trends of all times. Revisiting history ensures that you won’t repeat these mistakes.
Type: Design Principles
Level: All levels

Source: Web Design All Tutorials