I'm running into issues when using lstlisting to highlight code. In the latex code I have intended the listing to appear below the text, but it disregards the way the code is structured and puts it above the code. How do I force code listings to obey the structure and order I write in the latex code?
The core latex code:
\documentclass[12pt, a4paper]{article}
%% PACKAGES %%
\usepackage[a4paper,left=1.6cm, right=2cm, top=1.5cm, bottom=0.5cm,includefoot, footskip=30pt]{geometry}
\usepackage[backend=biber, style=iso-numeric, babel=other, urldate=short]{biblatex}
\addbibresource{ref.bib}
\usepackage{url}
\usepackage{float}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{pdfpages}
\usepackage{setspace}
\usepackage{lipsum}
%% FORMATING %%
\DeclareCaptionType{code}[code][list of code]
\renewcommand{\lstlistingname}{code}
\onehalfspacing
%% CODE COLORS %%
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.97,0.97,0.97}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegray},
keywordstyle=\color{codegreen},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
\setcounter{section}{-1}
\begin{document}
%% START DOCC %%
\section{sample that should be on top}
\lipsum[1]
\begin{center}
\begin{code}
\begin{lstlisting}[language=python, frame=single]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat
ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget,
consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant
morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras \end{lstlisting}
\caption[bleh1]{bleh1}
\end{code}
\end{center}
\begin{center}
\begin{code}
\begin{lstlisting}[language=python, frame=single]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat
ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget,
\end{lstlisting}
\caption[bleh2]{bleh2}
\end{code}
\end{center}
%% END OF DOCC %%
\end{document}
Output: