  The Wiener polarity index of a graph is defined as the number of unordered
pairs of vertices at distance three. In recent years, this topological index
was extensively studied since it has many known applications in chemistry and
also in network theory. In this paper, we generalize the result of Behmaram,
Yousefi-Azari, and Ashrafi proved in 2012 for calculating the Wiener polarity
index of a graph. An important advantage of our generalization is that it can
be used for graphs that contain $4$-cycles and also for graphs whose different
cycles have more than one common edge. In addition, using the main result a
closed formula for the Wiener polarity index is derived for phenylenes and
recalculated for catacondensed benzenoid graphs. The catacondensed benzenoid
graphs and phenylenes attaining the extremal values with respect to the Wiener
polarity index are also characterized.
