Marriages can end for a lot of reasons, and fault or misconduct by one spouse can be a pivotal part of divorce proceedings in some states. For example, in South Carolina, it can prohibit an award of alimony. However, depending on the laws of the state, it doesn't always affect matters of custody.
Effect on Parenting
Some courts, such as those in Illinois, take the position that cheating on your spouse does not necessarily make you a bad parent. States have a determined interest in preserving the parent-child relationship post-divorce, because it's usually in a child's best interests to have frequent and meaningful contact with both parents. Therefore, the reason that a marriage has ended typically has no effect on custody decisions. Adultery doesn't lessen a child's need to have a relationship with both his parents.
Effect on Children
When adultery crosses the line and affects a child, a court may treat this situation a little differently. Even states that do not recognize fault grounds, such as California, acknowledge that under some circumstances, marital misconduct can have far-reaching effects and must be considered. If a spouse exposes his children to his affair, such as by telling them that his paramour is their new mommy and causing them pain and consternation, this can affect custody. If he engages in amorous activities in front of the children, this would probably have some effect on a judge's custody decision.