We can see that #C# has two regions of electron density around it, which means it has a steric number equal to 2. This implies that it is #sp# hybridized, therefore has 2 unhybridized p-orbitals with which it can form pi bonds with the oxygen atoms.
On the other hand, each #O# atom has three regions of electron density around it, which means it is #sp^2# hybridized. This allows each #O# atoms to have 1 unhybridized p-orbital with which to form a pi bond.
The bonding in the #CO_2# molecule looks like this:
#C#'s sp hybridized orbitals are shown in yellow and its two unhybridized p-orbitals are shown in blue. #O#'s #sp^2#hybridized orbitals are shown in green, while its remaining unhybridized p-orbital is shown in blue.
So, #C# uses its two sp hybridized orbitals to form sigma bonds with the two #O# atoms (each #O# atom uses an #sp^2# orbital for this).
Let's say #C# has its #p_z# and #p_x# orbitals left unhybridized. Its #p_x# orbital will form a pi bond with the #O# atom that has its #p_x# orbital unhybridized, while its #p_z# orbital will for a pi bond with the other #O# atom's #p_z# orbital.
Therefore, #CO_2# has 2 pi bonds and 2 sigma bonds.
A faster way to determine how many pi bonds the molecule has is to know that a double bond is comprised of 1 sigma and 1 pi bond. Since #CO_2# has 2 double bonds, it will have 2 pi bonds.