How do I make this simplier?

<?php if ( $page_title == Sets ) {echo "Cursor";} else {echo "";} ?> <?php echo $page_title; ?> <?php if ( $page_title == Sets ) {echo "";} else {echo "Cursors";} ?>

So basically, I want the title to be

“Cursor Sets” or “Title Cursors”

Replace “Cursors” with " Cursors" :slight_smile:

on my local server it does.

I guess they meant:

“Cursor Sets” or “$page_title Cursors”

Your code doesn’t do that :wink:

it’s there on my screen.

Where did $page_title go? :slight_smile:

I would just do


 echo ($page_title == Sets)? 'Cursor Sets' : 'Title Cursors';

I am assuming Sets is a string variable

else is not required, you can easily strip those. Also, if you only want one line to of code to happen when an if evaluates to true, you don’t need the curly braces.
What do you mean by == Sets btw? I assume you mean == ‘Sets’, i.e. ‘Sets’ is a string ?

<?php if ( $page_title == 'Sets' ) echo "Cursor"; ?> <?php echo $page_title; ?> <?php if ( $page_title != 'Sets' ) echo "Cursors"; ?>

Alternative method using the ternary operator

<?php echo ( $page_title == 'Sets' ? "Cursor" : ""), $page_title, ( $page_title != 'Sets' ? "Cursors" : ""); ?>

When I use this, the title becomes oneword. Like TitleCursor or CursorTitle intead of it being properly spaced.

.


<?php
$page_title = 'Beach';

// OP's code (echoes "Beach Cursors")
if ( $page_title == Sets ) {echo "Cursor";} else {echo "";} ?> <?php echo $page_title; ?> <?php if ( $page_title == Sets ) {echo "";} else {echo "Cursors";}

// Your code (echoes "Title Cursors")
echo ($page_title == Sets)? 'Cursor Sets' : 'Title Cursors';

Ehmm… :shifty: