Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress category if-condition not working

I have a wordpress-generated page where I need some posts (in a specific category) to have a 'Sign up' button. But when I add the conditioning code, found in this helpsheet, the page just shows this error:
'Parse error: syntax error, unexpected '<' in /home006/sub008/sc74101-DVGF/gadebold.dk/wp-content/themes/gadebold/single.php on line 9'

I'm placing the conditioning code in the loop (in single.php) like this:

if ( is_category('8') ) {
<div id="tilmeldknap">
<form method='post' action='<?php echo site_url('/events/tilmeld-hold/')?>'>
<input name="event" type="hidden" value="<?php echo the_title() ?>" />
<input type="submit" name="tilmeld" value="Tilmeld Hold" /></form></div>
<?php } else { ?>
<?php } ?>

starting with a php-tag ofc. since i couldn't get the code to show with it infront.

What am I doing wrong in this snippet?

like image 854
VoodooBurger Avatar asked Sep 13 '25 00:09

VoodooBurger


2 Answers

Change is_category to in_category. is_category means that you are on the category page for category 8, not that you are viewing a post that belongs to that category.

like image 105
windyjonas Avatar answered Sep 22 '25 04:09

windyjonas


Only problem with your code that you have mixed html and php conditions. you should separate you php condition like

if ( is_category('8') ) { ?>
 <div id="tilmeldknap">
 <form method='post' action='<?php echo site_url('/events/tilmeld-hold/')?>'>
 <input name="event" type="hidden" value="<?php echo the_title() ?>" />
 <input type="submit" name="tilmeld" value="Tilmeld Hold" /></form></div>
<?php } else { ?>
<?php } ?>
like image 22
Waheed ur Rehman Avatar answered Sep 22 '25 04:09

Waheed ur Rehman