Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Adding HTML into PHP Loop

Featured Replies

Hello,

 

I am working on a Wordpress website that is using custom taxonomies. I have found the following code to list taxonomies:

<?php   // Get terms for post
 	$terms = get_the_terms( $post->ID , 'status' );
	// Loop over each item since it's an array
	if ( $terms != null ){
		foreach( $terms as $term ) {
			// Print the name method from $term which is an OBJECT
			print $term->slug ;
			print $term->name;
 			// Get rid of the other data stored in the object, since it's not needed
 			unset($term);
		}
	} 
?>

How my question is, how can I add html to this loop? I have tried multiple times but it either errors out, or it doesn't print the taxonomies.

 

The desired result it to have the following markup:

<button class="filter $term->slug" data-filter="$term->slug">$term->name</button>

If anyone could help me, I would greatly appreciate it :-)

How about ...

<?php   // Get terms for post
 	$terms = get_the_terms( $post->ID , 'status' );
	// Loop over each item since it's an array
	if ( $terms != null ){
		foreach( $terms as $term ) { ?>
<button class="filter <?php print $term->slug; ?>" data-filter="<?php print $term->slug; ?>"><?php print $term->name; ?></button>			print $term->slug ;
<?php // Get rid of the other data stored in the object, since it's not needed
 			unset($term);
		}
	} 
?>

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.