In this paper we present an extension of Stanley's theorem related to partitions of positive integers. Stanley's theorem states a relation between "the sum of the numbers of distinct members in the partitions of a positive integer $n$" and "the total number of 1's that occur in the partitions of $n$". Our generalization states a similar relation between "the sum of the numbers of distinct members in the partitions of $n$" and the total number of 2's or 3's or any general $k$ that occur in the partitions of $n$ and the subsequent integers. We also apply this result to obtain an array of interesting corollaries, including alternate proofs and analogues of some of the very well-known results in the theory of partitions. We extend Ramanujan's results on congruence behavior of the 'number of partition' function $p(n)$ to get analogous results for the 'number of occurrences of an element $k$ in partitions of $n$'. Moreover, we present an alternate proof of Ramanujan's results in this paper.