Adding a class to this line

Hi there,

I have the following line which outputs classes:

<li <?php job_listing_class(); ?> data-longitude="<?php echo esc_attr( $arr_post->geolocation_lat ); ?>"
                data-latitude="<?php echo esc_attr( $arr_post->geolocation_long ); ?>">

I believe this part: <?php job_listing_class(); ?> is the part outputting class=“classname classname etc”.

What I would like to do is add some custom classes to this line, but but not sure how to do this.

I have tried something like this:

<?php job_listing_class(); .'myclassname' ?> but this didn’t work.

Can anyone tell me how I can add my own classes?

Many thanks!

You’d need to add them to the output of the job_listing_class function. Do you know where that function is defined?

Thanks for the reply.

No, not sure where this is. I would not want the classes I am adding to it to be added to all other pages that use that function though.

Is there another way around it?

Yes. Create a copy of the function and use it here.

What you seem to want is a workaround. That works fine in the short run, but causes lots of trouble in the long run as everything becomes very unpredictable.

What are you using to edit php files?

I see, I have found the function and added a test class:

function job_listing_class( $class = '', $post_id = null ) {
	// Separates classes with a single space, collates classes for post DIV.
	echo 'class="test ' . esc_attr( join( ' ', get_job_listing_class( $class, $post_id ) ) ) . '"';
}

However, this has added it every instance that uses this, so I guess I will need to create a copy of it.

Would I simply copy this function into the file that I need to add the different classes to? Or would I copy it and call the function something else?

I am using DreamWeaver which I know is old school!

Yes you’d need to copy it. I would put it below the original function, so they are close together.

And indeed, Dreamweaver really is old school. Have you ever considered an alternative, like PHPStorm (paid) or VS Code (free)? Both are very good at editing PHP files. VS Code needs a few plugins to get real good, but is already better than Dreamweaver out of the box.

1 Like

Your name here is toolman. If there is anyone who should be comfortable with new tools it should be you, right? :wink:

2 Likes

Thanks for the reply. I copied it and added it to the files that I am editing rather than under the current one. Is it better to have it in one place, i.e under the other one?

I have used PHP Storm in the past but I am so used to Dreamweaver, I just stuck to that.

What plugins should I add to VS Code? Also, I guess it has a similar function to Dreamweaver that lets you upload. DW uses CTRL+SHIFT+U.

The best place to put it is the first place where you would go looking for it if you didn’t know where it was. In general code is read way more than it is written, so if you want to optimize your use of time, you’d better make sure it’s easy to read.

As for plugins, I would at least look at https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-intellisense

As for uploading, I wouldn’t know. I never upload anything to a production server from my own device directly. Haven’t done so for a long long time.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.