Despite that I have added the <?php comments_template(); ?> to single.php it seems like it's not working! I'm note sure, but why are the comments in the list of comments to be approved empty? The fields for name, email and URL and the content are empty for each comment.
Should the wp-comments-post.php be located together with the rest of the theme files or should it be together with the main files?
What could be the cause of this problem?
The function comments_template() looks for a file called comments.php in the root of your themes directory. The code inside comments.php should look like the following:
<!-- Display the comments -->
<?php if($comments) : ?>
<ol>
<?php foreach($comments as $comment) : ?>
<li id="comment-<?php comment_ID(); ?>">
<?php if ($comment->comment_approved == '0') : ?>
<p>Your comment is awaiting approval</p>
<?php endif; ?>
<?php comment_text(); ?>
<cite><?php comment_type(); ?> by <?php comment_author_link(); ?> on <?php comment_date(); ?> at <?php comment_time(); ?></cite>
</li>
<?php endforeach; ?>
</ol>
<?php else : ?>
<p>No comments yet</p>
<?php endif; ?>
<!-- Display the form -->
<?php if(comments_open()) : ?>
<?php if(get_option('comment_registration') && !$user_ID) : ?>
<p>You must be logged in to post a comment.</p><?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<?php if($user_ID) : ?>
<p>Logged in as <?php echo $user_identity; ?>. Log out ยป</p>
<?php else : ?>
<p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" />
<label for="author"><small>Name <?php if($req) echo "(required)"; ?></small></label></p>
<p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" />
<label for="email"><small>Mail (will not be published) <?php if($req) echo "(required)"; ?></small></label></p>
<p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" />
<label for="url"><small>Website</small></label></p>
<?php endif; ?>
</form>
<?php endif; ?>
<?php else : ?>
<p>The comments are closed.</p>
<?php endif; ?>
however, if you have a different theme directory layout, for example a custom comments.php, you can pass its path in as the funcion parameter. For example, if your theme had a modules direcotry:
<?php comments_template('modules/custom-comments.php'); ?>
Conclusion
This could be a code problem or a misuse of the comments_template() function. I recommend you don't change any WordPress code as it will just be overriden by future updates.
This answer is based on: https://codex.wordpress.org/Function_Reference/comments_template
Code Drops taken from:
http://code.tutsplus.com/articles/unraveling-the-secrets-of-wordpress-commentsphp-file--net-28
Related
I have a problem in the WP-Pro-Quiz plugin for WordPress. There are "Single Answer Options" that are visible, but not selectable. I need these options, I was thinking I might be able to get the checkboxes to function and in turn get the result I need in my quiz.
What is causing these checkboxes to be "Greyed Out"?
<?php
}
private function singleChoiceOptions($data)
{
$single = $data[0];
?>
<div class="postbox" id="singleChoiceOptions">
<h3 class="hndle"><?php _e('Single choice options', 'wp-pro-quiz'); ?></h3>
<div class="inside">
<p class="description">
<?php _e('If "Different points for each answer" is activated, you can activate a special mode.<br> This changes the calculation of the points',
'wp-pro-quiz'); ?>
</p>
<label>
<input type="checkbox" name="answerPointsDiffModusActivated"
value="1" <?php $this->checked($this->question->isAnswerPointsDiffModusActivated()); ?>>
<?php _e('Different points - modus 2 activate', 'wp-pro-quiz'); ?>
</label>
<br><br>
<p class="description">
<?php _e('Disables the distinction between correct and incorrect.', 'wp-pro-quiz'); ?><br>
</p>
<label>
<input type="checkbox" name="disableCorrect"
value="1" <?php $this->checked($this->question->isDisableCorrect()); ?>>
<?php _e('Disable correct and incorrect.', 'wp-pro-quiz'); ?>
</label>
<div style="padding-top: 20px;">
<?php _e('Explanation of points calculation', 'wp-pro-quiz'); ?>
<?php $this->answerPointDia(); ?>
</div>
</div>
</div>
<?php
}
The are gray because the are disabled by disabled="enabled", even if the value is enabled, the input gets disabled, any value will disable the input, in fact, you can just put disable and it will be disabled, latest browers just read disabled and disable the input. remove disabled="enabled" and the input will be enabled.
I figured it out, the name values weren't matching the $this value, capital letters. Plugin author must've missed it. Hopefully the function works.
<div class="inside">
<p class="description">
<?php _e('If "Different points for each answer" is activated, you can activate a special mode.<br> This changes the calculation of the points',
'wp-pro-quiz'); ?>
</p>
<label>
<input type="checkbox" name="AnswerPointsDiffModusActivated" value="1" <?php $this->checked($this->question->isAnswerPointsDiffModusActivated()); ?>>
<?php _e('Different points - modus 2 activate', 'wp-pro-quiz'); ?>
</label>
<br><br>
<p class="description">
<?php _e('Disables the distinction between correct and incorrect.', 'wp-pro-quiz'); ?><br>
</p>
<label>
<input type="checkbox" name="DisableCorrect"
value="1" <?php $this->checked($this->question->isDisableCorrect()); ?>>
<?php _e('Do not show correct and incorrect.', 'wp-pro-quiz'); ?>
</label>
<div style="padding-top: 20px;">
<?php _e('Explanation of points calculation', 'wp-pro-quiz'); ?>
<?php $this->answerPointDia(); ?>
</div>
</div>
</div>
<?php
I have a magento store where the Add to Cart button has stopped working and instead a search query is performed ( where the & are changed to & so it doesn't even work ) This can be seen by adding a item to cart here: http://bit.ly/1o8SwmE
This add to cart button does however work on category grid pages. I have tried pasting the link generated in the form into a web browser and it also redirects me to the same broken search page, I have also tried pasting the action link from the add to cart form on a working category grid page into firebug on the non working page and this then adds the product from the category page perfectly.
The snippets of code i have used are pasted below and other people have had them working it seems so this may not be the issue.
OLD CODE
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('QTY') ?>:</label>
<input type="text" name="qty" id="qty" class="new-qty-cat" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<?php endif; ?>
<button class="new-qty-button" type="button" onclick="this.form.submit()"></button>
</form>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
NEW CODE
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId(); ?>">
<input name="qty" type="text" class="input-text qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" />
<button class=form-button" onclick="productAddToCartForm_<?php echo $_product->getId(); ?>.submit()"><span><?php echo $this->__('Add to Cart') ?></span></button>
</form>
<script type="text/javascript"> var productAddToCartForm_<?php echo $_product->getId(); ?> = new VarienForm('product_addtocart_form_<?php echo $_product->getId(); ?>'); productAddToCartForm_<?php echo $_product->getId(); ?>.submit = function(){ if (this.validator.validate()) { this.form.submit(); } }.bind(productAddToCartForm_<?php echo $_product->getId(); ?>);</script>
NEW CODE 2
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty') ?>:</label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<?php endif; ?>
<button type="button" onclick="this.form.submit()"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
</form>
New Code 3
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty') ?>:</label>
<input class="new-qty-cat" type="text" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<?php endif; ?>
<button type="button" class="new-qty-button" onclick="this.form.submit()"><span><span> </span></span></button>
</form>
My first post, i have code where i can individually remove add-to-cart options from products using an additional attribute in the back end, added in addtocart.phtml.
The problem i am having is that i do not want this to affect the add to cart button just the quantity box and label.
I have tried many variations and nothing seems to help, i am thinking that i have this code inserted in an incorrect file but i am not sure.
You can see the code below, i was wondering if anyone could assist me in amending this code in order to achieve the functionality that i am looking for:
<?php $_product = $this->getProduct() ?>
<?php $attTest= $_product->getData(); ?>
<?php if($attTest['sell_online']): ?>
<?php if($_product->isSaleable()): ?>
<div class="add-to-cart">
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Number of weeks:') ?></label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" title="<?php echo $this->__('Number of Weeks') ?>" class="input-text qty" />
<?php endif; ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="productAddToCartForm.submit()"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php echo $this->getChildHtml('', true, true) ?>
</div>
<?php endif; ?>
<?php endif; ?>
Any help with this would be much appreciated. thanks in advance.
Set hints for template on to get .phtml and block class involved.
Cross check if block class in local folder.
Also check if compiler mode is on in that case your file will be in inc class folder.
Once you make sure you have modify right file then :
assuming that if $attTest sell online is the needed variable value.
<?php if($attTest['sell_online']): ?>
<label for="qty"><?php echo $this->__('Number of weeks:') ?></label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" title="<?php echo $this->__('Number of Weeks') ?>" class="input-text qty" />
<?php endif; ?>
I update this answer for any of the community members searching for this solution, my thanks go out to Satish the cleaver dude who helped me with my predicament and the original code provider who gave me the idea.
So firstly create an attribute so that you can turn quantity on and off (quantity_active), set catalog input type for store owner to yes/no.
Then copy and paste the following code over the code that exists in your addtocart.phtml.
<?php $_product = $this->getProduct() ?>
<?php $attTest= $_product->getData(); ?>
<?php if($_product->isSaleable()): ?>
<div class ="add-to-cart"></div>
<?php if(!$_product->isGrouped()): ?>
<?php if($attTest['quantity_active']): ?>
<strong><label for="qty"><?php echo $this->__('Number of Weeks:') ?></label></strong>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty ($_product) ?>" title="<?php echo $this->__('Number of Weeks') ?>" class="input-text qty" />
<?php endif; ?>
<div class ="clear"></div>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="productAddToCartForm.submit()"><span><span><?php echo $this->__('Add to Cart') ? ></span></span></button>
<?php echo $this->getChildHtml('', true, true) ?>
<?php endif; ?>
<?php endif; ?>
you should now be able to switch the quantity option on and off. :-)
The other answer is great except that if any product doesn't have the attribute, an error will be thrown. Best to change the if test slightly:
<?php if (empty($attTest['quantity_active']) || false) :?>
This just checks to see if the attribute exists or is set for the product.
Evry time while logging in an error "INVALID TOKEN" its shown at the joomla2.5/jomsocial2.4 site, but after 2,3 refreshes it shows the profile page as logged in... why is it so.... Is it problem of Joomla... I have uninstalled a plugin alphauserpoints ... is that a problem.. or should i modify the code default.php
<?php
// no direct access
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
?>
<?php if ($type == 'logout') : ?>
<form action="<?php echo JRoute::_('index.php', true, $params->get('usesecure')); ?>" method="post" id="login-form">
<?php if ($params->get('greeting')) : ?>
<div class="login-greeting">
<?php if($params->get('name') == 0) : {
echo JText::sprintf('MOD_LOGIN_HINAME', $user->get('name'));
} else : {
echo JText::sprintf('MOD_LOGIN_HINAME', $user->get('username'));
} endif; ?>
</div>
<?php endif; ?>
<div class="logout-button">
<input type="submit" name="Submit" class="button" value="<?php echo JText::_('JLOGOUT'); ?>" />
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="user.logout" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
<?php else : ?>
<form action="<?php echo JRoute::_('index.php', true, $params->get('usesecure')); ?>" method="post" id="login-form" >
<?php if ($params->get('pretext')): ?>
<div class="pretext">
<p><?php echo $params->get('pretext'); ?></p>
</div>
<?php endif; ?>
<fieldset class="userdata">
<p id="form-login-username">
<label for="modlgn-username"><?php echo JText::_('MOD_LOGIN_VALUE_USERNAME') ?></label>
<input id="modlgn-username" type="text" name="username" class="inputbox" size="18" />
</p>
<p id="form-login-password">
<label for="modlgn-passwd"><?php echo JText::_('JGLOBAL_PASSWORD') ?></label>
<input id="modlgn-passwd" type="password" name="password" class="inputbox" size="18" />
</p>
<?php if (JPluginHelper::isEnabled('system', 'remember')) : ?>
<p id="form-login-remember">
<label for="modlgn-remember"><?php echo JText::_('MOD_LOGIN_REMEMBER_ME') ?></label>
<input id="modlgn-remember" type="checkbox" name="remember" class="inputbox" value="yes"/>
</p>
<?php endif; ?>
<input type="submit" name="Submit" class="button" value="<?php echo JText::_('JLOGIN') ?>" />
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="user.login" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
<?php echo JHtml::_('form.token'); ?>
</fieldset>
<ul>
<li>
<a href="<?php echo JRoute::_('index.php?option=com_users&view=reset'); ?>">
<?php echo JText::_('MOD_LOGIN_FORGOT_YOUR_PASSWORD'); ?></a>
</li>
<li>
<a href="<?php echo JRoute::_('index.php?option=com_users&view=remind'); ?>">
<?php echo JText::_('MOD_LOGIN_FORGOT_YOUR_USERNAME'); ?></a>
</li>
<?php
$usersConfig = JComponentHelper::getParams('com_users');
if ($usersConfig->get('allowUserRegistration')) : ?>
<li>
<a href="<?php echo JRoute::_('index.php?option=com_users&view=registration'); ?>">
<?php echo JText::_('MOD_LOGIN_REGISTER'); ?></a>
</li>
<?php endif; ?>
</ul>
<?php if ($params->get('posttext')): ?>
<div class="posttext">
<p><?php echo $params->get('posttext'); ?></p>
</div>
<?php endif; ?>
or does the uninstallation affected the configuration file of joomla
Try this link: http://developersbench.in/invalid-token-during-registration-jomsocial/#.T19wtHm45F0 . You might get some help from this.
The info i have about this is every time you open a page and submit a form it first validates the token and if token is expired which is mainly because of remaining idle on the page for a few time, then you get "Invalid token" error.
Simply if you are not worried about the token, go to the file root/libraries/joomla/environment/request.php and check the below function
function checkToken( $method = 'post' ), comment all the lines between this and simply return true, whatever be the case. I haven't tried this, but i guess this will work.
I have a simple if-else statement--if true, I'd like it to echo this content:
<div id="login">
<h2>Login</h2>
<div class="box">
<form method="POST" action="index.php/login">
Username/Email:<br />
<input type="text" name="username" value="<?php echo set_value("username"); ?>" size="50" class="form" />
<?php echo form_error("username"); ?>
Password:<br />
<input type="password" name="password" value="<?php echo set_value("password"); ?>" size="50" class="form" />
<?php echo form_error("password"); ?>
<input type="submit" value="Login" name="login" />
</form>
</div>
</div>
and if false do something similar.
How should I approach this? I'm a PHP noob (and I've been annoying the community here!)--so I'm standing at the echo function right now--I think I can set variables, but that's about it.
Thanks so much!
Same thing as you have been doing:
<?php
if some_condition
{
?>
<p> I am inside the true condition due : <?php echo "true on condition" ?> </p>
<?
}
else
{
?>
<p> I am inside the false condition due : <?php echo "false on condition" ?> </p>
<?
}
?>
You can simply break out of PHP in the if/else statement.
if(true)
{
?>
Regular HTML Here
<?php
}
else
{
?>
Regular HTML Here
<?php
}
You can break out of PHP at any time using the '?>' operator, and with any control structure, it should show the code just as if you echo'd it. Another option would be to use output buffering.
if(true)
{
ob_start();
?>
Regular Code Here
<?php
$contents = ob_get_contents();
ob_end_clean();
}
This will leave the contents of what outputted between the start and end in $contents.
Finally, you could use an include() to only include your login form when you actually need it. (I prefer this method because I can put login forms almost anywhere on the site very easily)
if(true)
{
include('loginform.php');
}
<?php if ($condition) { ?>
<div id="login">
<h2>Login</h2>
<div class="box">
<form method="POST" action="index.php/login">
Username/Email:<br />
<input type="text" name="username" value="<?php echo set_value("username"); ?>" size="50" class="form" />
<?php echo form_error("username"); ?>
Password:<br />
<input type="password" name="password" value="<?php echo set_value("password"); ?>" size="50" class="form" />
<?php echo form_error("password"); ?>
<input type="submit" value="Login" name="login" />
</form>
</div>
</div>
<?php } else { ?>
other html here
<?php } ?>
Just a suggestion; for readability and ease of flexibility, it is better to place what you want to display inside a variable first.
$html = "<form method='post' action='?'> ...... ";
if ($condition)
$html .= "Error"
else
$html .= "No problem"
....
<html>
<body>
<?php
echo $html;
?>
</body>
</html>
Or you can use a template. One which I would recommend is EasyTemplate.
there's a form of php conditional that's somewhat easier to read for this, uses colon notation so instead of
<?php if ($condition) { ?>
...html
<?php } else { ?>
...html
<?php } endif; ?>
you do
<?php if ($condition) : ?>
...html
<?php else : ?>
...html
<?php endif; ?>
also if your config allows it, you can shorthand
<?= $variable ?>
instead of
<?php echo($variable); ?>
Dropping out of php is the easiest way to do this. I find that using the alternate control structures makes this sort of code much more readable than stranded curly braces, especially if you have a lot of html.
<?php if (!$logged_in): ?>
<div id="login">
<h2>Login</h2>
<div class="box">
<form method="POST" action="index.php/login">
Username/Email:<br />
<input type="text" name="username" value="<?php echo set_value("username"); ?>" size="50" class="form" />
<?php echo form_error("username"); ?>
Password:<br />
<input type="password" name="password" value="<?php echo set_value("password"); ?>" size="50" class="form" />
<?php echo form_error("password"); ?>
<input type="submit" value="Login" name="login" />
</form>
</div>
</div>
<?php else: ?>
// display html for a logged-in user
<?php endif; ?>
Use something like this
echo htmlentities($string);
htmlentities
Set the string to the html code you want to output.