donderdag 31 juli 2014

4 ways to create richer web experiences

thumbnailThe Web has evolved a lot from being a simple document repository, and we now have browsers capable of rich visual interactions on desktop as well as mobile.


Because I’d like to talk about where the Web is headed in this article, many of the features I’ll cover may have limited support, so it is important to use resources like caniuse.com which has a robust list of features and charts specifying where they are supported.


Let’s take a dive into the four ways you can enhance your site UX:


1. CSS


CSS is the styling language for our documents, we tend to think of this in simple terms like changing font size or color, but it is becoming increasingly powerful with features like transforms and animations. We’re also getting new features to make it even more powerful.


If you’ve used Vector Masks in tools like Photoshop, you should be familiar with the idea behind CSS Clip Paths. This feature allows you to define a shape in CSS that defines the transparent and opaque parts of your HTML content. These work great with CSS Transitions for hiding and revealing UI elements. Similarly CSS Masks are making their way to the Web, which allow you to define the transparent parts of your content using an image. This allows you to use transparency more effectively in your designs for visual interest or textures.


4 ways to create richer web experiences


 


2. SVG


Most of the images we find on the Web today are raster images, made up of pixels. This means that as we scale them or view them on higher resolution devices they get pixelated.


Vector graphics are awesome because they are made up of geometric primitives that retain their crisp edges at any size.


SVG is the vector format for the Web. We can use it to display graphics and even manipulate and animate its properties with CSS. Where SVG gets really powerful is when we combine it with scripting. Snap is a JavaScript library that makes it easy to manipulate and animate SVG content. It’s focused on modern browsers, so it supports the newest SVG features like groups and clip paths. Snap is open sourced on GitHub and we even used it to create a rich animated banner ad, you can read more about it in my blog.


And here’s a sample of an ad we did using SVG. 


4 ways to create richer web experiences


 


3. 2D Canvas


2D Canvas is another powerful feature of the Web optimized for drawing shapes and images. It provides a JavaScript API that gives you granular control over your canvas element. It also gives you the freedom to integrate other forms of media, such as video, creating the potential for rich interactive buttons that play, pause or scrub video footage. 2D Canvas now supports blend modes, which allow you to mix the colors of layers in visually interesting ways, which you can read more about here.


We’re also starting to get support for alpha video that allows us to more seamlessly integrate video into our content. A fun example of alpha video is in OK Go’s music video ‘WTF’.



OK Go is known for elaborate music videos, and in this particular video they shot choreography in front of a green screen. Then using post processing continued to render the footage on top of itself creating a cool echo effect where the transparency was. We can reproduce this effect using 2D Canvas, but we can take it a step further and make it interactive using features like canvas blend modes to create new visual effects in real-time.


4 ways to create richer web experiences


 


4. WebGL


WebGL provides a low level API for drawing hardware accelerated 2D and 3D graphics. The potential here is console style games, like Grand Theft Auto 5 running right inside your browser. As you can imagine WebGL gets somewhat complicated, fortunately open-source libraries like Three.js provide a great entry point with great examples to get you started. 


GitHub has become a great resource for the open source community. You can find Three.js and Snap on GitHub as well as other great libraries making it easier to do amazing work on the Web. I often put experiments and tools I make on GitHub as well, such as a camera spline tool I used to create camera paths for Three.js to fly through 3D worlds.


4 ways to create richer web experiences


 


As we can see the Web is becoming increasingly diverse and powerful, it’s an exciting time to be a Web developer. The variety of technologies and resources we have access to are constantly growing, and it’s fun to see the rich experiences people are creating with them.






LAST DAY: UX Web Tiles for Flow Diagrams and Sitemaps – $24!
4 ways to create richer web experiences



Source




4 ways to create richer web experiences

How to Add More Than One Background Image with CSS

Sometimes, you may want to use more than one background in your page. For example, you may want one background for one paragraph and another background for another paragraph. Follow the steps provided in this tutorial to add more than one background image with CSS.


Steps to add more than one background image with CSS


1. First of all, create an html file. You may use any IDE like notepad or notepad ++ or Adobe Dreamweaver to create an html file. In this tutorial, we are using plain notepad that is available in any Windows PC. Open notepad and type the following code:


<html>

<head>

<title>CSS tutorial – 4</title>

<link rel=”stylesheet” type=”text/css” href=”css/style.css” />

</head>

<body>

<p>

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. </p>

</body>

</html>


And then save the file as .html (eg: tut4.html).

Here, <link rel=”stylesheet” type=”text/css” href=”css/style.css” /> will link the stylesheet that we are going to create. Also, you can use any text inside those p tags.


step-1-create-html-multiplebg


2. Next, in the same directory (folder), create another folder named css and create new css file named style.css. To do that, open notepad and save it as style.css


step-2-create-css-multiplebg


3. Next, prepare two different background images. Make sure you save those images in the same folder where your HTML file is situated and then open the css file that you have created in step 2 of this tutorial.


step-3-prepare-bg-multiplebg


4. Type the following code in the same css file (in your style.css or whatever you named it as)


body
background-image: url(‘../mainbg.png’);


p
background-image: url(‘../bg1.jpg’);


Here,


body
background-image: url(‘../mainbg.png’);

will insert a background image in the whole body.


p
background-image: url(‘../bg1.jpg’);

will insert a background image on a paragraph only.


step-4-type-css-multiplebg


This completes our tutorial on how to add more than one background image with CSS. If you’ve found it helpful, please do leave a comment below.


The post How to Add More Than One Background Image with CSS appeared first on Web Design Blog | Magazine for Designers.




How to Add More Than One Background Image with CSS

Design a Vector Themed Cereal Box in Adobe Illustrator

Final product image
What You’ll Be Creating

The most important meal of the day is Adobe Illustrator. I’m pretty sure breakfast comes second. As such, we’re going to combine the two and pay homage to the cereal boxes of our childhood with this cartoony box design.


1. Start With a Sketch


Step 1


It’s important to figure out your central character and layout within your sketch. I like sketching within Adobe Illustrator CC itself (though you can import a sketch as well). Using the Paintbrush Tool (B) with Fidelity set to Smooth in the Paintbrush Tool Options panel and a default Calligraphic brush selected, I’ve drawn out an excited cartoon character and blocked in the cereal’s name above him. 


For a detailed guide to drawing the hands, take a look at Cartoon Fundamentals: How to Draw Cartoon Hands by .


Step 2


Since this is a cereal box, don’t forget to showcase the cereal bowl. In this case, we’ll be drawing (mostly) O-shaped cereal bits with the character jumping out of (or presenting) the bowl (which has been filled to the brim). Group (Control-G) together your sketch lines and lock the group in the Layers panel, as you’ll be tracing these when creating your final design.


2. Form the Head


Step 1


Building up every bit of anatomy isn’t necessary in this design. 


  1. Start with the face by tracing your sketch with the Pen Tool (P)

  2. The face comprises half of the head and one ear. You can draw portions of it (head, jaw, and ear) separately and Unite in the Pathfinder panel.

  3. Either set the stroke color to dark brown in order to create an outline, or Copy (Control-C) and Paste (Control-V) your face shape, set the fill and stroke color to dark brown, Stroke Weight to 2 pts, and Align it behind the original face.

  4. Draw a small D-like shape for the other ear, in a darker flesh-tone (relative to whatever flesh-tone you’ve chosen) and place it behind the other head shapes. For more info on various skin-tones, check out this quick tip from yours truly.

Step 2


  1. Having figured out the hair during the sketch stage, I can now just trace it with the Pen Tool.  Think of hair as being in sections: bangs (fringe), sides, and back. If you want your hair design to be a bit more fluid, use the Pencil Tool (N) to draw it quickly and round out any edges by manipulating Live Corners.

  2. Using the same dark flesh-tone used for the ear, draw a shape that mimics the edges of the hair. This will serve to cast a shadow from the hair onto the face. Place the shape beneath the hair in the Layers panel.

  3. Don’t forget a C-shape for the inside of the left ear.

Step 3


The face is mostly built from simple shapes combined to form a really, really excited face.


  1. Draw two overlapping circles using the Ellipse Tool (L). If you set the fill color to null and the stroke to the same dark brown being used for outlines, you can then alter the width of the circles on the outer edges with the Width Tool (Shift-W). The mouth, drawn with the Pen Tool, is like a sideways jelly bean.

  2. The nose is like an upside-down question mark, or half-circle with a little leg on it.

  3. For the tongue, I chose a light pink and drew a shape that takes up the lower half of the mouth.

  4. The teeth are curved shapes which follow the contour of the mouth.

  5. Copy and Paste the circles created for the eyes and fill them with a light blue. Make sure the left eye overlaps the right.

Step 4


Continuing with the eyes:


  1. Draw white circles that overlap the light blue ones from the previous step. If you select the light blue circle and its overlapping white counterpart, you can use the Shape Builder Tool (Shift-M) to separate the non-intersecting portion of the white circle (by selecting it), Deselect, and Delete.

  2. Use the Width Tool to increase the width of the eye’s stroke. In this case, I Pasted the outline circle from the previous step and placed it over the white and light blue shapes forming the right eye.

  3. The mouth needs an outline too. Copy and Paste the base mouth shape (that sideways jelly bean) and set the stroke to 1pt weight.

  4. So that the nose doesn’t appear transparent, draw a half circle and place it beneath the nose line, but above the eyes in the Layers panel.

  5. Thicken up the outline of the left eye too and draw two small circles for the eyes’ pupils.

  6. Using the Paintbrush Tool, I drew two small eyebrows and Expanded them under Object.

Step 5


When you’re satisfied with your cartoon guy’s head, Group everything together. To add a thicker outline around the entire thing (while retaining the one drawn previously, which helps define where the head ends and barely seen ear on the right begins), CopyPaste, and Unite the copied head in Pathfinder. Set the fill and stroke color to dark brown and the stroke weight to 2-3pts, depending on what you prefer. Align the head and its silhouette and Group them together. 


3. Let’s Add a Body


Step 1


Once again, the shape of the body was figured out during the sketch stage.


  1. The body’s sections are as follows: two hands, two arms, a neck, a shirt, and the insides of the shirt. I found it easiest, for me, to CopyPaste, and Reflect the left arm (over a Vertical Axis) to get the right arm. I scaled and rotated it as well in order to fit with the sketch.

  2. Using the technique from the previous section, give the neck and arms a 2pt weight outline.

  3. Using the same dark skin-tone as used in the shadows on the face, draw shadow shapes for the palms of the hands, on the neck, and upper arms (where shadows from the sleeves are being cast).

Step 2


Use the Pen Tool to draw lines on the shirt denoting sleeve cuffs, stitching, and a collar. Group everything together and once again, CopyPasteUnite in the Pathfinder panel, apply a thick stroke weight to the shape, and Align behind the main character. Group all of this together and we’ll move on to create the rest of the box design.


4. Drawing Three-Dimensional Cereal


Step 1


Draw a circle within a large circle using the Ellipse Tool. With both selected, hit Minus Front in the Pathfinder panel. Select your flat donut shape and go to Effect > 3D> Extrude & Bevel…. Play with the rotation, or enter in the following details to get the same 3D shape below:


  • X Axis: 

  • Y axis: 

  • Z axis: -2°

  • Extrude Depth: 34 pt

  • Surface: Plastic Shading

Step 2


With the 3D donut shape selected, go to Object> Expand Appearance. Use the Direct Selection Tool (A) to select the face of the cereal shape and set the fill color to a light tan. Select everything but the face of the object and set the fill color to a darker tan. Follow the steps from Section 3, Step 2 to give the cereal shape a thick outline. Group these shapes together. You’ll be using this process of drawing a flat image, extruding it, changing the fill colors, and giving it an outline for the other cereal pieces later in this tutorial.


Step 3


Copy and Paste several of the “Vector O’s”. Rotate them around as you see fit, or even create new 3D versions of them for extra variety in each cereal object’s perspective. Select a group of them and in the Pattern Options panel, create a new pattern. Choose Hex by Column or whatever will give you the most coverage. Save your pattern and move on to the next step.


Step 4


  1. Draw a large ellipse that will serve as the top of the bowl. Set the fill color to a light cream (this will serve as our milk).

  2. Copy and Paste that ellipse and apply your new pattern to it (please ignore the lack  marshmallow shape, as that’s coming up shortly).

  3. Paste cereal shapes around the bowl in order to cover any pattern edges and to make the cereal bowl look like it’s filled to the brim with delicious “Vector O’s”. Use the Pen Tool to draw shallow bowl. Only the sides and top edge will show in the final design, so how precise in the bowl’s perspective you are is your call entirely.

5. Marshmallow Shapes!


Step 1


The previous section mentioned some of the Illustrator-themed marshmallow shapes we’re adding to the bowl of cereal. Let’s get working on them. Let’s start with a Pen Tool-inspired marshmallow. Draw one-half of the design, seen below, with the Pen Tool itself. Copy and Paste the object and Reflect it over a Vertical Axis. Using the steps from Section 4, Step 1, create a 3D version of the pen tool and change the shadow colors to dark teal. Draw a circle in the center of the shape and Group together. Give it a thick outline just like the cereal O’s.


Step 2


For the next marshmallow shape, we’ll be creating a yellow pencil. Use the Rectangle Tool (M) to draw a narrow rectangle. Round the corners by selecting it with the Direct Selection Tool and pulling the Live Corners inward. Cut the shape in half (or more) by drawing a rectangle over it and hitting Minus Front in the Pathfinder panel.


Step 3


  1. Use the Polygon Tool to draw a simple triangle. 

  2. Align and Scale it so its base is the same width as the rest of the pencil shape.

  3. Using the Pathfinder panel again, cut off the tip of the triangle.

  4. From here, you can draw some narrow stripes on the pencil and proceed to creating a 3D object as done with the other cereal shapes.

Step 4


The other marshmallow shapes get a quick overview, since it’s more of the same in creating them.


  1. Note how different values in rotating over different axes will give you different perspectives for your marshmallows.

  2. The third shape is a paintbrush. I draw it based off of the Paintbrush Tool icon with the Pencil Tool

  3. The final marshmallow is the Selection Tool rendered in green. It’s made of a rectangle and a large, indented triangle.

Step 5


Scatter your marshmallows and “Vector O’s” around the design, making sure to put some near and on the character’s hand as though he’s popping out of the bowl and throwing them around. Group all of this together. You’ll notice, too, the pen icon used for the blue marshmallow was also added to his shirt. Clearly, this guy loves vector art.


6. Sticker and Background


Step 1


Let’s draw that cute sticker located in the lower right side of the composition.


  • Draw a circle with the Ellipse Tool and fill it with a dark yellow color. Go to Effect > Distort & Transform > Zig & Zag… Adjust the effect to your liking. The larger the size, the deeper the points will plunge into the center of the circle. And the more ridges per segment, the more points you’ll have around your circle.

  • Create an outline for your sticker shape and make sure the corners are rounded out either through manipulating Live Corners or choosing Rounded Caps and Corners in the Stroke panel.

  • To make it shiny, draw a circle with a Linear Gradient going from light yellow at 100% to 0% Opacity and angled from the top left. Delete any non-intersecting portions of the circle from your sticker shape using the Shape Builder Tool.

  • Finally, use a comic-style font like Arch Rival or Toontime for your text layers.

Step 2


The background is fairly simple. Draw a large rectangle over the artboard in “teal” using the Rectangle Tool. With the Pen Tool, draw long shapes radiating outwards from the center (or so) of the design. Unite them in the Pathfinder panel and apply a Radial gradient to the Compound Shape going from light blue in the center and teal at the edges. Most of your design will cover the more opaque portions of the shape in the center.


7. The Logo


Step 1


Using another comic-like font, I wrote out out cereal’s name. This font is called Helsinki. I recommend using something that is childlike and either rounded or looks hand-drawn. Extrude & Bevel, just like the marshmallow shapes were before.


Step 2


The steps to creating the logo are pretty simple:


  1. Expand your 3D text in Object and Ungroup so you can move each letter up, down, or rotate it to your liking.

  2. Change the letters’ faces to light blue and their shadow colors to teal.

  3. Scale some of the letters up, like the C and the O, and some of them down, like the E.

  4. Group the text together once satisfied with the placement and create an outline by CopyingPasting, and Uniting the copied group in the Pathfinder panel. Set the stroke weight at 3-5pts and Align it behind the first logo group. Note how the text curves a bit, ready for the box design. 

Step 3


Put it all together! I decided the character should overlap the logo a bit and the additional text of “with marshmallow tools” was set in Arch Rival  again. I also added two extra outlines to the character, bowl, and cereal bits flying around in order to set them apart from the background further. 


At this point, with the main design completed, you can call this project well done. Or, you can continue on to create a digital cereal box mock-up.


8. The Side Panel


Step 1


Before we bother with mocking up the design, we need to create the side panel of the cereal box. I’ve decided to go to the trouble of creating the full nutrition facts. Use the Rectangle Tool to draw a narrow rectangle filled with white and the stroke color set to black and a 2pt weight. For the lines, I used the Line Segment Tool to draw each line, making sure the width of the lines matched the width of the initial rectangle. Check out a real cereal box (or other foodstuff) in order to match the FDA’s guidelines for nutrition facts. Unless you’re going the route of just making it all up, then take whatever artistic liberties you want.


Step 2


The font used for “Nutrition Facts” is Franklin Gothic. For the rest of the label, I used Liberation Sans, as I prefer it over Arial or Helvetica. Make sure that you’re aligning your text so that the vitamins and major nutritional components line up while their values and percentages line up on the other side.


Step 3


Like the front of the cereal box, the side panel is also teal (though without the radiating gradient shapes). Copy and Paste the logo and Scale it down so it fits within the rectangle. Paste your nutrition facts and assorted instances of the marshmallow designs too.


Step 4


You’ll need to open up Adobe Photoshop CC for the completion of the rest of this tutorial. You’ll also need this great cereal box mock-up on Graphic River created by Zeisla. There’s an instructional .PDF with the download file.


Open up the file labeled 3.PSD in Photoshop. You’ll notice the top layer is titled “Box (Your Image Here)“. Right-click this layer and hit Edit ContentsPaste your front box design and make sure it fills the entire document. Hit save and go back to 3.PSD. You’ll notice your design is now on the previously blank box. Repeat this step with the second layer labeled “Box Side (Your Image Here)” for your previously created side panel (you can also assemble your side panel contents onto the file directly).


Great Job, You’re Done!


Throw some marshmallows in the air, you’re done! Then pick them up again, I doubt you want ants. For more fun with packaging design and cartooning, check out these fantastic tutorials:




Design a Vector Themed Cereal Box in Adobe Illustrator

Understanding and Working with Relationships Between Data in WordPress

In the first part of this series on data in WordPress, I gave an overview of the WordPress database tables, and which tables are used to store what kind of data. In this second part, I’ll outline how WordPress manages the relationships between that data.


As you’ll see, WordPress uses three kinds of data relationship – one-to-one, one-to-many and many-to-many. I’ll look at each of these and what they mean for your WordPress site.


One-to-One Relationships


A one-to-one relationship is the simplest relationship of all – it simply means that one record is related to just one other. Data like this is generally stored within one table (although not always, as we’ll see later on in this tutorial).


Examples of one-to-one relationships in WordPress include:


  • post ID and post content

  • post title and post content

  • post ID and post slug

  • comment ID and comment content

  • user ID and username

The list could go on, but the main point is that any two records which are stored in different fields in one row of a table have a one-to-one relationship.


One-to-one relationships, however, are the least interesting kind of database relationship. So without further ado let’s move on to a relationship type used a lot by WordPress – one-to-many.


One-to-Many Relationships


One to many relationship are very common in databases, and are what makes a database more powerful than a ‘flat’ table such as a spreadsheet. These occur when one record has a relationship with more than one other record. 


In WordPress, most one-to-many relationships are created by a link between two database tables, using a unique identifier to join the two. So for example, the post_id record will be unique to each post stored in the wp_posts table, but will also be used in the wp_comments table to identify which post each comment was posted to. This means that each post_id value will appear only once in the wp_posts table but could appear multiple times – or not at all – in the wp_comments table.


Some other examples in WordPress include:


  • posts and post metadata

  • posts and users

  • users and user metadata

  • taxonomies and taxonomy terms

Again, the list goes on. As this is an important topic in WordPress, let’s take a look at the one-to-many relationships in more detail.


One-to-Many Relationships Involving Posts


The table which is connected to the most other tables is the wp_posts table, and most of the relationships these connections create are one-to-many relationships.


As you can see in the diagram below, the wp_posts table is linked to four other tables:


In addition to this, posts can also have a one-to-many relationship with other posts, in the form of attachments or parent pages.


Let’s take a look at these relationships in more detail.


Posts-to-Posts


As explained above, data stored in the wp_posts table can have a one-to-many relationship with other data in the same table; however, this relationship isn’t between what you would think of as posts, but instead is between posts and attachments or pages and other pages. After all, attachments and pages are post types.


An attachment stored in the wp_posts table will have a record in the post_parent field, which will be the ID of the post to which the attachment is attached (with apologies for the repetition!). This is a one-to-many relationship because each attachment will only have one parent, while each post could have many attachments. This will apply even if you’ve used the Media Manager to add an attachment to another post – only the post to which it was originally added will be stored in the database as its parent.


Posts can also have a one-to-many relationship with other posts when one page is specified as the parent of another. The record is stored against the child page, in the post_parent field – again this will be the post_id of the parent page. This is a one-to-many relationship because parent pages can have many child pages but child pages will only have one parent page.


When thinking about relationships between posts like this, it’s important to remember that when considering WordPress data handling, posts are not what you might normally refer to as posts. They include pages, attachments and other post types, all of which are stored in the wp_posts table.


Posts-to-Post Metadata


Post metadata is stored in its own table wp_postmeta. This table only includes four fields – for the post_id, the meta_id, the key and the value. One post can have many items of post metadata associated with it but each post metadata record will only be linked to one post.


Posts-to-Comments


Comments also have their own table, wp_comments. Each comment will relate to only one post while each post can have multiple comments stored against it. As with all of the other tables linked to wp_posts, the post_id field is used for the link (in the comment_post_id field in wp_comments).


The wp_comments table has 15 fields by default, to store data about the author, the author’s email address, the comment itself and its approval status. It’s also linked to the wp_users table, as we’ll see in the next section.


Comments also have their own metadata, stored in another table, which I’ll come to shortly.


Posts-to-Users


Each post is attached to the wp_users table via the user_id record, which is stored in the post_author field in wp_posts. This is a one-to-many relationship because each post has only one author but each user can be the author of multiple posts.


The relationship between posts and users is different rom that between posts and comments or metadata because its nature is of one user, multiple posts, not one posts multiple comments or mete data records. This is why the user_id field provides the link instead of the post_id field.


One-to-Many Relationships Not Involving Posts


There are also three relationships which are one-to-many and don’t involve posts. Two of these involve metadata – the relationship between comments and their metadata, and users and their metadata.


Users-to-User Metadata


WordPress stores additional metadata about users in the wp_usermeta table. This is generally used for non-standard data about users, such as metadata about superadmins in a multisite installation and metadata about the admin colors a user has selected if these aren’t the default. 


Most data on users will be in the wp_users table. The two tables are linked via the user_id field and one user record will have multiple items of metadata associated with it, whereas each item of metadata will only apply to one user.


Comments-to-Comment Metadata


Again, most data about comments is stored in the wp_comments table along with the comment itself, but the wp_commentmeta table is used to store additional metadata such as data created by plugins like Akismet. The relationship is the same as between users and usermeta.


Comments-to-Users


The final one-to-many relationship is between comments and users. The wp_comments table includes the user_id field, which can be used to store the user ID when a logged-in user has posted a comment. Note that this field isn’t mandatory for those sites where users don’t have to be logged in to comment.


Many-to-Many Relationships


The final kind of database relationship is the one-to-many relationship, where the many link goes both ways. This is only used once in WordPress, for taxonomy terms (including categories and tags as these are simply taxonomies). One post can have many terms assigned to it and one term can be assigned to multiple posts.


WordPress creates this relationship in the same way as any other database with manay-to-many database: by using an interim table linking the two tables with the key data. This is the wp_term_relationships table, which links the wp_posts table to the wp_term_taxonomy table. 


Note: This table also links the wp_links table to the wp_term_taxonomy table, as links behave in much the same way as posts – I’ll come to links shortly.


This is most easily explained by looking first at the two outlying tables. The wp_posts table contains data on each post, while the wp_term_taxonomy table contains data on each term, including the taxonomy it is in and its ID. 


To create a link between a term in the wp_term_taxonomy table and a post in the wp_posts table, WordPress creates a record in the wp_term_relationships table, which includes the post_id and the term_id (stored as object_id and term_taxonomy_id respectively in the wp_term_relationships table). This means that the wp_term_relationships table can include multiple records for each post and multiple records for each term, creating the many-to-many relationship.


The diagram below show how this works:


In the example above, the posts have the following terms:
  • post 1 has terms 1 and 3

  • post 2 has term 2

  • post 3 has term 4

  • post 4 has terms 1 and 3

You could also look at it the other way – for example, term 3 relates to posts 1 and 4.


However things don’t stop there. There is a fourth table, the wp_terms table. This holds data about each term, namely the name, slug and description for each term. Each term has only one record in the wp_terms table, so the relationship between that and the wp_term_taxonomy table is actually one-to-one. Theoretically speaking, there’s no reason this data couldn’t be held in the wp_term_taxonomy table, but it isn’t.


A Note on Links


Links, or the blogroll, is a feature of WordPress which is far less prominent than it once was. In fact, since version 3.5 links have been turned off in the admin by default; however, they do have their own table: the wp_links table. 


This is very similar to the wp_posts table. After all, links are a content type very similar to posts) and have the same many-to-many relationship with taxonomy terms.


Summary


As we’ve seen, WordPress uses a variety of relationships to link data in 10 of its 11 database tables. The only table I haven’t mentioned here is wp_options, because that isn’t linked to any other tables, as it simply stores data about the site, rather than about content. I’ll cover that in more detail later in this series.


By understanding the one-to-one, one-to-many, and many-to-many relationships in WordPress, that can help you to identify ways to manipulate your data and write custom queries in your theme and/or plugins.


In the next part of this series, I’ll cover content types in more detail, looking at the types of content stored in the WordPress database and the similarities and differences between them.




Understanding and Working with Relationships Between Data in WordPress

Updated ASP.NET Database Resource Provider

I’ve updated my database ASP.NET Resource Provider project into a more formal project with a new home page, and official GitHub repository for the source code as well as a getting started video. In this video I talk about what’s new and a few examples on how to use the provider.






Updated ASP.NET Database Resource Provider