开发者

Wordpress category if-condition not working

I have a wordpress-gen开发者_开发知识库erated 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?


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.


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 } ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜