WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] overriding a page template dynamically

[Resolved] overriding a page template dynamically

  • hi, is it possible to assign a page template on the fly when a page is loaded?

    let´s say i have a page with code to list all categories available in my wp blog. there´s also code that counts the number of categories ($catsavailable).

    now if there is three categories i want page-template-3.php to be assigned to that page, if the output is four categories page-template-4.php and so on.

    does it make sense to hack the function get_page_template or template-loader.php? but how would these get the info of $catsavailable?

    thanks in advance,
    jogol

Viewing 2 replies - 1 through 2 (of 2 total)
  • anmari
    Participant

    @anmari

    Hi jogol

    why wouldn’t you just have the special code in the main template?

    if $catsavailable = 3…..
    do code for 3, or call function or include file
    else
    if $catsavailable = 4…..
    …do code for 4, or call function or include file

    else
    do some default code so the whole thing does ot fall apart if someone adds a category.

    thanks for the input anmari, really good idea! i´ll check if i can achieve what i want with your suggestion.

    best,
    jogol

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] overriding a page template dynamically’ is closed to new replies.