NORTHAMPTON — Frank L. Stanley Jr. admitted in court Wednesday that he sexually abused three boys over seven years, and was sentenced to 20 to 30 years in prison for those crimes.

Stanley’s sentence was postponed for a day to allow him to appear Thursday in Hampshire Superior Court for a hearing on charges of possessing child pornography. Stanley may plead guilty to those charges at Thursday’s proceeding, according to the court clerk’s office.

Stanley, 42, of 35 Chmura Road, Hadley, pleaded guilty to a total of 18 counts in Hampshire Superior Court on what would have been the second day of testimony in his trial, which began Tuesday.

Stanley pleaded guilty to six counts of statutory rape of a child, four counts of indecent assault and battery on a child under 14, three counts of distributing obscene material to a minor, three counts of posing a child in a nude or lascivious position, and one count each of indecent assault and battery on a person over 14 and committing an unnatural act with a child.

The abuses took place between 2004 and 2011 in Granby and Hadley.

He will serve his sentence at the maximum security Cedar Junction Correctional Institution in Walpole and will be given credit for 657 days already served in custody while awaiting trial.

Stanley’s attorney, Jonah Goldsmith of the Committee for Public Counsel Services had sought a sentence of eight to 10 years followed by 10 years probation. The state’s recommendation was 25 to 30 years followed by 15 years of probation.

By pleading guilty, Stanley admitted he forced one of the boys to have sex with and perform sex acts on a life-size “sex doll,” touched another boy inappropriately, and posed the third naked and simulated sex acts with him, paying him $200 to $300 to do so. He also showed all three pornography.

In November of 2011, a relative of two of the boys discussed a news program about child predators with them, which prompted their disclosure of the abuses.

After Stanley was told relatives of the boys were going to contact police, he left the area and was later apprehended in Florida on a Massachusetts warrant and brought back to face charges.

Upon his release, Stanley will be on probation for 10 years, during which time he must register as a sex offender, report regularly to and complete any treatment required by the probation department, have no contact with anyone under 16, stay away from the victims and submit to GPS monitoring.