(a) A mortgage or deed of trust given for the price of real property, at the time of its conveyance, has priority over all other liens created against the purchaser, subject to the operation of the recording laws.

(b) The priority of the lien of a mortgage or deed of trust on an estate for years in real property shall be determined in the same manner as for determining the priority of a lien of a mortgage or deed of trust on real property.

Where one has a lien upon several things, and other persons have subordinate liens upon, or interests in, some but not all of the same things, the person having the prior lien, if he can do so without risk of loss to himself, or of injustice to other persons, must resort to the property in the following order, on the demand of any party interested:

1. To the things upon which he has an exclusive lien;

2. To the things which are subject to the fewest subordinate liens;

3. In like manner inversely to the
number of subordinate liens upon the same thing; and,

4. When several things are within one of the foregoing classes, and subject to the same number of liens, resort must be had—

(1.) To the things which have not been transferred since the prior lien was created;

(2.) To the things which have been so transferred without a valuable consideration; and,

(3.) To the things which have been so transferred for a valuable consideration in the inverse order of the transfer.