Adding an autoname property to category page (4 posts)

  1. matt.blower92
    Posted 2 years ago #

    Hi there,

    I'm very inexperienced with PHP coding and am having issues with what I'm assuming is a relatively easy issue to fix.

    I'm attempting to customize the category pages on my website, so that when you click on the category page, a customized banner and title will come up. I want to customize the code so that the category ID tag will automatically be displayed as a header title. So if the category ID is "Doctors," the page will automatically display "Doctors" as a header.

    I've isolated this code in one of my themes template pages:

    echo '<div class="widget-head"><h3><a>cat_ID).'" title="View all posts under '.$cat->cat_name.'">'.$cat->cat_name.'</a></h3></div>';

    I think this will do what I want it too, but I'm not sure how to correctly write the code.

    Any help would be appreciated, thanks again!

  2. matt.blower92
    Posted 2 years ago #

    Ok I solved this issue by adding the single_cat_title as so:

    <p><?php single_cat_title('Currently browsing '); ?>.

    What I would like to know now is whether or not I can do the same thing with a designated image or banner.

    For example, when the category page for "Doctors" is opened, a banner or image appears with the text provided from the code above.

    Is this doable?


  3. bcworkz
    Posted 2 years ago #

    It's doable, but not as simply as the solution you found for the title. There's a few possibilities. You could build an array that relates category ID to the image filename:

    <?php $images = array(
       8 => 'doctors.jpg',
      13 => 'nurses.jpg',
      21 => 'cnas.jpg',
    ); ?>

    Then output the image tag referencing the array:
    <img src="http;//example.com/wp-content/banners/<?php echo $images[ $cat->cat_ID ] ?>" alt="Banner Image">

  4. matt.blower92
    Posted 2 years ago #

    Thanks for responding,e

    I actually figured it out earlier today, I installed the 'Categories Images' plugin, and then used the following command to automatically pull the cat image:

    <img src="<?php echo z_taxonomy_image_url($term->term_id); ?>" />

    But thanks for the array code, I've been wondering how to correctly utilize something like that.



Topic Closed

This topic has been closed to new replies.

About this Topic