Mixing bibliographic styles in Biblatex

After much searching on Tex.StackExchange, I put together a hack that produced this:

enter image description here

I hope my code will be of use to others who want to do something similar.

Code:

\documentclass{article}
\usepackage[backend=biber, %I think this should work for BibTex too, but I'm not sure.
  style=authoryear, %Set author-year as the default style; later hacks will produce a fake numeric style.
  defernumbers %Works together with resetnumbers so that the numbering of numeric entries is independent of the author-year citations.
  ]{biblatex}
\addbibresource{Bibliography.bib}

%Copied from numeric.cbx to imitate numerical citations.
\providebool{bbx:subentry}
\newbibmacro*{citenum}{%Note: the original macro was called "cite". I did not redefine "cite", but instead defined a new macro "citenum", because the author-year citations use the "cite" macro too. "\renewbibmacro*{cite}" would have caused all the author-year citations to become numeric too.
  \printtext[bibhyperref]{%If you ever want to use hyperref
    \printfield{prefixnumber}%
    \printfield{labelnumber}%
    \ifbool{bbx:subentry}
      {\printfield{entrysetcount}}
      {}}}

%Copied from numeric.cbx to define a new numeric citation command for @online entries.
\DeclareCiteCommand{\conline}[\mkbibbrackets]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{citenum}}%Note: this was originally "cite" but I changed it to "citenum" to avoid clashes with the author-year style.
  {\multicitedelim}
  {\usebibmacro{postnote}}

\begin{document}
Cite books, \parencite{Book} \parencite{Book2}

Cite online stuff, \conline{Online} \conline{Online2}

%Print the normal author-year bibliography
\printbibliography[nottype=online]

%Redefine the bibliography environment to imitate the numeric citation style
\defbibenvironment{bibliography}
{\list
{\printfield[labelnumberwidth]{labelnumber}}
{\setlength{\labelwidth}{\labelnumberwidth}%
\setlength{\leftmargin}{\labelwidth}%
\setlength{\labelsep}{\biblabelsep}%
\addtolength{\labelsep}{1em}
\addtolength{\leftmargin}{\labelsep}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}%
\renewcommand*{\makelabel}[1]{\hss##1}}
{\endlist}
{\item}
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}\hspace{-1.1em}}
\printbibliography[type=online,title=Online,resetnumbers]
\end{document}

The file Bibliography.bib contains:

@book{Book,
  author    = {Author},
  title     = {Title},
  publisher = {Publisher},
  year      = {2014},
}

@book{Book2,
  author    = {Author2},
  title     = {Title2},
  publisher = {Publisher2},
  year      = {2015},
}

@online{Online,
  author = {Author},
  title = {Title},
  titleaddon = {titleaddon},
  subtitle = {subtitle},
  url= {http://tex.stackexchange.com/},
}

@online{Online2,
  author = {Author2},
  title = {Title2},
  titleaddon = {titleaddon2},
  subtitle = {subtitle2},
  url= {http://tex.stackexchange2.com/},
}

Tags:

Biblatex