• Resolved jonm76

    (@jonm76)


    Trying to use get_template_part with single_cat_title.

    Does not give me an error but does not work. I’ve tried so many slightly tweaked versions of this but just not familiar enough with PHP yet to know why none of them work. (Works fine when I just type the slug name instead of trying to get the current cat.)

    Inserted single_cat_title, took out the php tags since it’s already within tags (examples I saw used periods?) and added the false statement to parse the cat title, not print it.

    <?php get_template_part(‘. single_cat_title(“”,FALSE).’)?>

    Did I totally mangle this??

Viewing 3 replies - 1 through 3 (of 3 total)
  • fonglh

    (@fonglh)

    Take out the quotes.

    <?php get_template_part( single_cat_title(“”, FALSE) )?>

    Not tested.

    Michael

    (@alchymyth)

    also, be aware that single_cat_title() only works in category archives and outputs the category title, not the slug; i.e. you will get problems when the category title contains capital letters or more than one word.

    Thread Starter jonm76

    (@jonm76)

    Thank you! Taking out the quotes worked. Thought for sure I had tried that but but obviously not since this fixed it right away.

    My template part filename DID need to have the first letter capitalized. I had made multiple versions (test.php, Test.php, TEST.php) and it uses the one that matches the output of single_cat_title() exactly.

    All my category names are single words so hopefully I won’t have any further issues.

    Thanks again!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘PHP within PHP – How to use get_template_part with single_cat _title’ is closed to new replies.