WordPress.org

Forums

Adding an autoname property to category page (4 posts)

  1. matt.blower92
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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?

    Matt

  3. bcworkz
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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.

    Thanks,

    Matt

Topic Closed

This topic has been closed to new replies.

About this Topic