Ready to get started?Download WordPress


[resolved] overriding a page template dynamically (3 posts)

  1. jogol
    Posted 3 years ago #

    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,

  2. anmari
    Posted 3 years ago #

    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
    if $catsavailable = 4.....
    ...do code for 4, or call function or include file

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

  3. jogol
    Posted 3 years ago #

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


Topic Closed

This topic has been closed to new replies.

About this Topic