We present emergent dynamics of the continuous and discrete Cucker--Smale (CS) type models with the q-closest neighbors in a self-consistent time-varying temperature field. Asymptotic flocking dynamics of the thermodynamic Cucker--Smale (TCS) ensemble has been extensively studied using particle, kinetic, and fluid models under several connection topologies that can be realized by the complete network, connected symmetric network, directed graph with a spanning tree, etc. In this paper, we propose sufficient frameworks for the monocluster flocking of the continuous and discrete TCS models on a digraph with a neighbor set determined by q-closest neighbors from the test particle. In our proposed frameworks, there can be a phase-transition-like phenomenon from local (multicluster) flocking to global (monocluster) flocking, depending on the size q of the neighbor set, as we increase q. When q is larger than half of the population, any initial configuration will tend to the monocluster flocking state in a positive coupling regime. In contrast, when q is smaller than half of the population, we need to impose some restrictive conditions on the initial data to guarantee the emergence of monocluster flocking. Thus, our results generalize Cucker and Dong's result [Math. Models Methods Appl. Sci., 26 (2016), pp. 2685--2708] for the CS ensemble in a homogeneous constant temperature field. We also provide several numerical examples and compare them with our analytical results.