When it comes to custody disputes in divorce, some attorneys represent the grownups, and others look out for the interests of the children. The latter is called a guardian ad litem, or GAL, and it's a bit of a misconception that he "represents" the children. His role is to investigate and help the court determine what's best for them.
GALs are typically used if custody is a highly contentious aspect of your divorce. They're appointed by the court, or at the request of either parent, usually when allegations of abuse or unfitness are involved. The attorney's role is to uncover and ascertain the facts. He will typically interview both parents, all siblings, extended family members, and possibly even teachers or pediatricians.
After his investigation, a GAL reports to the court, detailing his findings. The GAL can't actually be your child's lawyer because he can't be restrained by attorney-client privilege; he may have to divulge things to the court that your child has told him. He'll recommend a custody arrangement to the court that he believes is in the best interests of the child.
Some states, such as Connecticut, will appoint an attorney to represent older children, but this isn't technically a GAL. This attorney can present your child's wishes and feelings to the court and fight for them, whereas a GAL is neutral and concerned only with what's in the child's best interests.