WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [closed] Remove text field from comment form (50 posts)

  1. edow
    Member
    Posted 5 months ago #

    Hi,

    I would like to remove the text field from the comment form. The idea is that users can vote if they like the post or not. The like/unlike option must be done with radio buttons in a custom field (that would be the next problem).

    But first: How can I remove the text field? I don't want it hidden, but entirely removed. What is the best practice for this? I can't find a decent solution.

    Hopefully anyone can help me with this.

  2. nickohrn
    Member
    Posted 5 months ago #

    Are you looking to do this on your site alone or make a plugin that is reusable across multiple sites? What theme are you using? How are you displaying the comment form? Are you just using the comment_form template tag?

    There's ways to do this, but it really depends on your exact setup.

  3. edow
    Member
    Posted 5 months ago #

    Hi,

    I want to do this on one site only and I made the theme myself.
    I use <?php comments_template(); ?> to display the form. So I think it's the same?

  4. nickohrn
    Member
    Posted 5 months ago #

    comments_template simple sets up some variables and includes a template file (probably comments.php in your theme). The form is usually generated by the comment_form template tag which has a bunch of things you can override.

    For your purposes, you probably just need to find where the comment_form template tag is used and pass the correct arguments to it. Something like:

    comment_form(array('comment_field' => '<input type="hidden" name="comment" value=" " />'));

    That basically says, replace the textarea (which is the default value for comment_field) with a hidden input that contains a space character so that the comment isn't empty.

    Whether or not this works from that point forward is a question of whether WordPress allows almost empty comments. You should be good to go for the most part, though.

    For adding additional elements to the comment form, you can hook to one of the following actions:

    • comment_form_before
    • comment_form_must_log_in_after
    • comment_form_top
    • comment_form_logged_in_after
    • comment_form_before_fields
    • comment_form_after_fields
    • comment_form
    • comment_form_after

    Your best bet is to just open up /wp-includes/comment-template.php and figure out where there are hooks available to modify the behavior you want and take advantage of them. Best of luck!

  5. edow
    Member
    Posted 5 months ago #

    Thank you for your response. Tomorrow I'll take a look at this. Thanks in advance!

  6. edow
    Member
    Posted 4 months ago #

    My comment_form tag looks like this:

    <?php do_action('comment_form', $post->ID); ?>

    I'm not sure how to use your line of code, because the form doesn't show anymore after I use your code within my code. I think I'm doing something wrong.

    If it will work, doesn't the database get full of code of tags (?) with whitespace? I'm not sure how this works, but I suppose the space from the textfield is saved in the database?

    Sorry for my bad English.

  7. nickohrn
    Member
    Posted 4 months ago #

    edow - I'm sorry, but I can't help you any further at this point. If you have do_action('comment_form', $post->ID) then you probably have a form hardcoded into your comments.php file. If that's the case, simply remove the textarea tag and see if that works. Beyond that, I recommend contacting a WordPress developer who can take on small jobs like this.

  8. edow
    Member
    Posted 4 months ago #

    I appreciate your quick replies.

    I've managed to remove the text field, because (as you said) it's hardcoded.

    This is my code now:

    <div class="comment">
    					<label>Review: (verplicht)</label>
    					<input type="radio" name="comment" id="comment" value="like">Like<br>
    					<input type="radio" name="comment" id="comment" value="unlike">Unlike
    					<br />
    					<input type="submit" class="commentsubmit" value="Review plaatsen" />
    					<?php if ( is_user_logged_in() ) { echo ''; } else { echo '<span> - Het is niet verplicht, maar je kan een <a href="http://aigoo.nl/wp-login.php?action=register">gratis profiel aanmaken</a> of <a href="'.wp_login_url( get_permalink() ).'">inloggen</a></span>'; };?>
    				</div>

    I also made radio buttons as you can see. The problem now is that it says "Your comment is awaiting moderation." and I can only place one review. Maybe because it's from the same IP.

  9. edow
    Member
    Posted 4 months ago #

    Now it works. In the WordPress settings I changed the option that the user must have a previous approved review. It looks like it works well.

    The next problem is that I want to sort the people in two lists. One list with people who choose "LIke" and a list of people (avatars shown only) who choose "Unlike".

  10. Media2U
    Member
    Posted 4 months ago #

    Hello, i was just saw this about comment so im try to ask you here. For a while ago I made a site to a guy that had try to do it by himself, hes mistakes was he let anyone register as (administrator) instead of authour. When he contact me i removed a hacked link into main template of hes site and i thought that was enough but still even i make a sign up as auhour and want to leave a comment on hes food recipes i cant do that.

    this is hes website: http://www.svenskakocken.se/ and its impossible for me atrleast to leave comment but i see that now after few days he got several other ppl logged in and register as authour but as what i see no comments only one had did one comment and i cant allow that comment coz i know thats a hacking person...

    What should i do to fix this error on hes comment section.

    OK next Questian..
    Im adding few social plugins on hes website, im kinda new onb doing that coz before i never add those stuff not even on mine...

    BUt however, hes website is simular to a women website also foods but different country and taste...

    Google plus on her site i can see a big picture of some foods and her profil picture in google plus and the circle following thing, he want like that on hes but the plugin i was choose seems not allow that and im not sure what to do here to help him... he had just hes profile picture there.

    http://frenchcookingfordummies.com/ this is the french women site

    http://www.svenskakocken.se/ and this is my friends site....

    hoping to get some help here

  11. bcworkz
    Member
    Posted 4 months ago #

    Hello Media2U,

    If a hacker had access as administrator, there is a good chance he installed a hidden backdoor somewhere on the site. These can be extremely difficult and time consuming to find and successfully remove. It's usually best to wipe the entire site and restore it from a known clean backup. See FAQ My site was hacked.

    FYI, tagging onto someones topic is frowned upon in these forums. Please start your own topic so your issue can be fully addressed without being confused with other answers. I also suggest you focus on one issue per topic, an expert in hackers may know nothing of social media or vice versa, so he may be reluctant to help you since he cannot fully address all your issues. A focused topic will more likely get you a focused answer.

  12. edow
    Member
    Posted 4 months ago #

    I've still my question. Is it possible to sort the comments in two lists? Comments can only contain the word "like" or "unlike". Is it possible, based on these words, to sort these comments in two seperate lists? One list with the "likes" and the other one with the "unlike". In this list only the avatar should be shown. Hopefully anyone can help me with this.

  13. bcworkz
    Member
    Posted 4 months ago #

    Sorry edow, I didn't realize you still had a pending question.

    Yes you can sort comments as you envision. The specifics depend on how your theme handles comments, exactly how the vote selection is stored, and your coding abilities. There's a number of possibilities. You could do a single query, ordered by the vote field. The comment loop would detect when the votes change and start a new list. You could do two separate queries. You could use a single query and sort the results using PHP, either as part of the comment loop, a user array sort, or part of a walker function. There's probably hybrid variations of any of those approaches.

  14. edow
    Member
    Posted 4 months ago #

    Hi bcworkz,

    No problem and thanks for your reply!

    These are the input fields for the like/dislike buttons in the comment section:

    <div class="comment">
    					<label class="commentformtitle">Do you like <?php the_title(); ?>?</label>
    					<span class="radiobuttonleft"><input type="radio" name="comment" id="comment" value="like">I like this!</span>
    					<span class="radiobuttonright"><input type="radio" name="comment" id="comment" value="unlike">I don't like this...</span>
    					<input type="submit" class="commentsubmit" value="Submit review" />
    				</div>

    My coding abilities aren't so well. I'm not sure how to achieve this. Is it possible that you help me a little bit further with this?

    The comment form itself works good. Guests have to input their name, email and choose like or unlike. After submit the comment text is "like" or "unlike" so that works great.

    I realy don't know how to handle this. In the database the comment text only saves "like" or "unlike", so perhaps with PHP I can sort the likes and unlikes based on the comment-text? Hopefully you can help me a little bit further.

  15. bcworkz
    Member
    Posted 4 months ago #

    So there aren't any true comments with authored words, the entire comment text will either be "like" or "unlike" and nothing else? That certainly simplifies things if so. Do you just need a count of each vote, or do you actually want a list of who voted one way, then those voting another way?

    Which approach would make the most sense somewhat depends on the scale of the site. Small sites can do almost anything without consequences. Huge sites must carefully consider every approach. What scale do you ultimately see for this site? How many comments per post? Dozens, hundreds, thousands? Same for how many posts eventually.

    I generally don't code for people except in way of illustrating a point or something simple and short. You may fall into the latter category if I understand your situation correctly. Unfortunately, I'm under a major time crunch for the next few days. (and currently have no access to my usual development tools) I can probably help you out in a few days if no one else jumps in before hand.

  16. edow
    Member
    Posted 4 months ago #

    Yes you're right, the entire comment text is "like" or "unlike". There is no text field, only the radio buttons and the input field for your name and email address.

    I want a list with people who voted "like" and a seperate list of people who voted "unlike". I have two lists like this:

    `<div class="upvoters" id="votes">
    <h2>We like this!</h2>
    <div class="voter-img">
    <a href="#respond"><img src="/wp-content/themes/aigooNL/images/upvote.png" class="upvote"></a>
    <img src="/wp-content/themes/aigooNL/images/voter.png" class="tooltip" title="John">
    <img src="/wp-content/themes/aigooNL/images/voter.png" class="tooltip" title="Edo">
    <img src="/wp-content/themes/aigooNL/images/voter.png" class="tooltip" title="Peter">
    <img src="/wp-content/themes/aigooNL/images/voter.png" class="tooltip" title="Joey">
    </div>
    </div>

    <div class="downvoters">
    <h2>We, not so much...</h2>
    <div class="voter-img">
    <a href="#respond"><img src="/wp-content/themes/aigooNL/images/downvote.png" class="downvote"></a>
    <img src="/wp-content/themes/aigooNL/images/voter.png" class="tooltip" title="Chris">
    <img src="/wp-content/themes/aigooNL/images/voter.png" class="tooltip" title="Michael">
    </div>
    </div>`

    There are two classes: upvoters and downvoters. These lists reflects the votes.

    I have a small website. Sure, I want the site to grow, but right now I'm thrilled if someone gave a review ;)
    Hopefully the site will grow and I get dozens "likes/unlikes" on each post, but certainly not thousands.

    I understand if you don't have the time to help me with this, but I would really appreciate it if you or someone else could help me a little bit more. I understand how to design and know about html, but I don't know much about PHP or other coding languages.

    I'm not in a hurry. If you need more information please let me know. Thanks already for any help you can give.

  17. bcworkz
    Member
    Posted 4 months ago #

    This should more or less work for you. It may take some minor tweaks to get it perfect.

    <div class="upvoters" id="votes">
    <h2>We like this!</h2>
    <div class="voter-img">
    <a href="#respond"><img src="/wp-content/themes/aigooNL/images/upvote.png" class="upvote"></a>
    <?php $comments = get_comments( array('post_id' => get_the_ID(),) );
    $likes = array();
    $unlikes = array();
    foreach( $comments as $comment ) {
    	if('unlike' == $comment->comment_content ) $unlikes[] = $comment;
    		else $likes[] = $comment;
    }
    foreach( $likes as $like )
    	echo("<img src=\"/wp-content/themes/aigooNL/images/voter.png\" class=\"tooltip\" title=\"$like->comment_author\">");
    ?>
    </div>
    </div>
    
    <div class="downvoters">
    <h2>We, not so much...</h2>
    <div class="voter-img">
    <a href="#respond"><img src="/wp-content/themes/aigooNL/images/downvote.png" class="downvote"></a>
    <?php
    foreach( $unlikes as $unlike )
    	echo("<img src=\"/wp-content/themes/aigooNL/images/voter.png\" class=\"tooltip\" title=\"$unlike->comment_author\">");
    ?>
    </div>
    </div>

    You should be able to see the main idea here in how each comment for the post is sorted into one array or another based on content, then each sorted array's author names are output as image title attributes.

  18. edow
    Member
    Posted 4 months ago #

    Super awesome! Works great immediately. I hardly dare to ask, but is there with this code the possibility to show a counter for the upvotes and downvotes? If not, it doesn't matter. This is super awesome already! Thank you so much!

  19. bcworkz
    Member
    Posted 4 months ago #

    You're most welcome, I'm glad I could help.

    A count is super easy as long as you want the counts to appear after the sorting loop (the first foreach{ } loop). Otherwise a little restructuring is required, still not a big deal. Insert something like the following line where you want the count to appear (outside of the loops but inside a <?php ?> block):
    echo '('.count($likes).' votes)';

    Just substitute $unlikes for $likes for the downvotes. I would personally insert this after each echo line, but it will work above the related foreach lines as well.

  20. edow
    Member
    Posted 4 months ago #

    Great! Now I've the code like this:

    <div class="upvoters" id="votes">
    		<?php $comments = get_comments( array('post_id' => get_the_ID(),) );
    		$likes = array();
    		$unlikes = array();
    		foreach( $comments as $comment ) {
    			if('unlike' == $comment->comment_content ) $unlikes[] = $comment;
    				else $likes[] = $comment;
    		}
    		echo '<h2>'.count($likes).' bezoekers vinden dit leuk</h2>';
    		echo '<div class="upvoter-img">';
    		foreach( $likes as $like )
    			echo("<img src=\"/wp-content/themes/aigooNL/images/voter.png\" class=\"tooltip\" title=\"$like->comment_author\">");
    		echo '</div>';
    		?>
    		</div>
    
    		<div class="downvoters">
    		<?php
    		echo '<h2>'.count($unlikes).' bezoekers vinden dit niet leuk</h2>';
    		echo '<div class="downvoter-img">';
    		foreach( $unlikes as $unlike )
    			echo("<img src=\"/wp-content/themes/aigooNL/images/voter.png\" class=\"tooltip\" title=\"$unlike->comment_author\">");
    		echo '</div>';
    		?>
    		</div>

    It's working great. This is the screenshot (in Dutch) how it looks like: http://oi57.tinypic.com/30hv7g6.jpg
    I guess the code is still correct with my changes?

    I have to design it now, but the functions are working great! Thanks again.

    WordPress has it build in that you may not comment the same text twice. I was forgotten to mention it, but now visitors can comment "like" and "unlike". Is there a simple solution that prevents visitors from voting like and unlike on the same post? WordPress prevents from like the same post twice or unlike it twice.

  21. edow
    Member
    Posted 4 months ago #

    And what do I have to do to show the counters outside the code? I'm thinking of showing them also at the top of the page as well as how I'm showing them now.

  22. bcworkz
    Member
    Posted 4 months ago #

    Yeah, your changes are fine :)

    I kind of wondered if there was a counter vote prevention, I guess not. It's a little complicated, we need to query the database, it gets a little messy to ensure the query doesn't return false positives. Fortunately, I knew right where to find the WP duplicate prevention and it was pretty easy to hack it up for your situation. This goes either in your theme's (preferably child theme's) functions.php, or in a simple plugin. If you don't have a custom site specific plugin, it's a handy thing to have for little tweaks like this.

    //prevent more than one %like
    add_filter('pre_comment_approved','edow_one_vote',10 ,2);
    function edow_one_vote($approved, $commentdata) {
    	global $wpdb;
    	extract($commentdata, EXTR_SKIP);
    	// expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)
    	$dupe = $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = %s AND comment_approved != 'trash' AND ( comment_author = %s ", wp_unslash( $comment_post_ID ), wp_unslash( $comment_parent ), wp_unslash( $comment_author ) );
    	if ( $comment_author_email )
    		$dupe .= $wpdb->prepare( "OR comment_author_email = %s ", wp_unslash( $comment_author_email ) );
    	$dupe .= $wpdb->prepare( ") AND comment_content LIKE %s LIMIT 1", '%like' );
    	if ( $wpdb->get_var($dupe) ) {
    		if ( defined('DOING_AJAX') )
    			die( __('You already voted here!') );
    		wp_die( __('You already voted here!') );
    	}
    }

    FYI, the uppercase LIKE in the second $dupe line is not the comment content, it is a mySQL operator. The '%like' is the comment content to search for, the % is a wildcard character in mySQL. Everything else is nearly straight from comments.php.

    As for moving the counts, the first loop must be moved as well since it establishes the counts. Wherever the $likes and $unlikes arrays are used, they need to be within scope of the first loop or they need to be declared global. Moving the loop up on the same page will always be in scope. Calling the loop in a function would go out of scope. When out of scope, if WP_DEBUG is defined as true, you will get undefined variable warnings, not to mention the count numbers will not display.

    Have fun with the design!

  23. edow
    Member
    Posted 4 months ago #

    Thanks for your explanation. Soon I'll look after moving the counters.

    I've a small problem and I don't know if it is because of the code or something else. I use this line of code to show the images:
    <img src=\"".get_avatar_url(get_avatar( $comment, 50 ))."\" class=\"tooltip\" title=\"$like->comment_author\">

    Normally $comment should be $id_or_email, but that does nothing. If I use $comment to get the comment author avatar (I also use the plugin Local Avatar or something) every author gets the same avatar (the one who voted when he was logged in), also when they're not logged in. Perhaps I'm doing something wrong. When there's no uploaded avatar from someone he shows the standard avatar as it should be.

    I'll post my final code here, because maybe it's useful for others.

    Code to get the comment form and show the avatars:

    <div class="post-commentform">
    			<?php comments_template(); ?>
    		</div>
    
    		<div class="post-comments">
    			<div class="upvoters" id="votes">
    			<?php $comments = get_comments( array('post_id' => get_the_ID(),) );
    			$likes = array();
    			$unlikes = array();
    			foreach( $comments as $comment ) {
    				if('unlike' == $comment->comment_content ) $unlikes[] = $comment;
    					else $likes[] = $comment;
    			}
    			echo '<h3>'.count($likes).' bezoekers vinden dit leuk</h3>';
    			echo '<div class="upvoter-img">';
    			foreach( $likes as $like )
    				echo("<img src=\"".get_avatar_url(get_avatar( $comment, 50 ))."\" class=\"tooltip\" title=\"$like->comment_author\">");
    			echo '</div>';
    			?>
    			</div>
    
    			<div class="downvoters">
    			<?php
    			echo '<h3>'.count($unlikes).' bezoekers vinden dit niet leuk</h3>';
    			echo '<div class="downvoter-img">';
    			foreach( $unlikes as $unlike )
    				echo("<img src=\"".get_avatar_url(get_avatar( $comment, 50 ))."\" class=\"tooltip\" title=\"$unlike->comment_author\">");
    			echo '</div>';
    			?>
    			</div>
    
    			<div class="clearBoth"></div>
    		</div>

    Code in comments.php:

    <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
    			<fieldset>
    				<div class="comment">
    					<span class="radiobuttonleft"><input type="radio" name="comment" id="comment" value="like" data-related-item="commentinput">Ik vindt dit leuk!</span>
    					<span class="radiobuttonright"><input type="radio" name="comment" id="comment" value="unlike" data-related-item="commentinput">Ik vindt dit niet zo leuk...</span>
    				</div>
    				<div class="fields">
    					<?php $current_user = wp_get_current_user(); ?>
    					<?php
    					if ( is_user_logged_in() ) {
    						echo '';
    					} else {
    						echo '<input type="text" class="commentinput" name="author" id="author" placeholder="Naam of schuilnaam :)" value="'.$current_user->user_login.'" />
    							  <input type="text" class="commentinput" name="email" id="email" placeholder="E-mail" value="'.$current_user->user_email.'" />
    							  <input type="submit" class="commentsubmit" value="Geef je mening!" />
    							  <div class="labelemail">We willen even weten of je geen robot bent</div>';
    					}
    					?>
    				</div>
    
    				<?php comment_id_fields(); ?>
    				<?php do_action('comment_form', $post->ID); ?>
    			</fieldset>
    		</form>

    Then it looks like this, beware, it's Dutch ;)
    Without replies: http://oi59.tinypic.com/2nkt9g7.jpg
    With replies: http://oi61.tinypic.com/2ev9q49.jpg
    When you give a comment: http://oi62.tinypic.com/1zx39j8.jpg

    So there's only the little problem with the avatars. Thanks again for your help! I'm super happy with it!

  24. bcworkz
    Member
    Posted 4 months ago #

    I'm pleased you're pleased :)

    You are passing the entire comment object to get_avatar(), it wants just a user ID or email, pass $comment->comment_author_email instead of $comment.

  25. edow
    Member
    Posted 4 months ago #

    Unfortunately that isn't working either. It also gives all the voters the same avatar after a logged in user voted.

    This is the corresponding function code:

    function get_avatar_url($get_avatar){
        preg_match("/src='(.*?)'/i", $get_avatar, $matches);
        return $matches[1];
    }

    Maybe there is some error in the function code. I'm happy to open a new topic if you're done helping me ;)

  26. bcworkz
    Member
    Posted 4 months ago #

    The correction is needed anyway, though there's obviously something else at play. The problem is not extracting the URL, otherwise you would get no image at all. The problem is get_avatar() is returning the default image no matter what. It might require detailed tracing through the get_avatar() function to determine why.

    The first thing to try is to var_dump($comment->comment_author_email) to confirm an actual email is being passed. Besides a trace, other things to check is if the avatar setting on the admin screen is correct and that no plugins or even your theme is causing a conflict somehow.

    I'm not saying I'm done helping you, but I am out of ideas. It's not that I don't want to help, it's that I can't. Starting a new topic would certainly get other eyes on the problem. You also might try stackexchange. Best of luck to you.

  27. edow
    Member
    Posted 4 months ago #

    I have a question about moving the votes. Instead of moving I would like to duplicate the counter to the top of the page. So, I want the counter as where it is now and want another on top of the page. I used this code:

    <?php
    			foreach( $comments as $comment ) {
    				if('unlike' == $comment->comment_content ) $unlikes[] = $comment;
    					else $likes[] = $comment;
    			}
    			echo '<h3>'.count($likes).' people like this</h3>';
    			echo '<h3>'.count($unlikes).' people don't like this</h3>';
    			?>

    But that isn't working. This is the first loop you're talking about right? This code displays 0 people like this, even when there are likes.

    Which code do I have to use to have another counter on the same page. It would be better if the top counter calculates the difference. So if there're 10 likes and 5 dislikes the counter say +5 and if there're 2 likes and 4 dislikes is says -2.

  28. bcworkz
    Member
    Posted 4 months ago #

    You need to move (not copy) exactly this portion to above where you want the first score to appear:

    <?php $comments = get_comments( array('post_id' => get_the_ID(),) );
    		$likes = array();
    		$unlikes = array();
    		foreach( $comments as $comment ) {
    			if('unlike' == $comment->comment_content ) $unlikes[] = $comment;
    				else $likes[] = $comment;
    		}

    Leave all else where it is.

    Double check that there is no code between this and the final avatar display below that assigns a value to either $likes or $unlikes. "Assigns a value" means the variable appears to the left of a single equals = sign.

    The code to display a difference score is something like this:

    $score = $likes - $unlikes;
    echo "Net Likes-Unlikes Score: $score";

    $score must also not be assigned another value if you are going to use it as part of the avatar display below.

  29. edow
    Member
    Posted 4 months ago #

    Thanks, I had to change it to $score = count($likes) - count($unlikes); and now it works great!

    Later I have to figure out how to show the score on the category page, tag page and homepage, but for now it works great. Again, thanks a lot!

    The code which is on top of the page is now:

    <?php
    		$comments = get_comments( array('post_id' => get_the_ID(),) );
    			$likes = array();
    			$unlikes = array();
    			foreach( $comments as $comment ) {
    				if('unlike' == $comment->comment_content ) $unlikes[] = $comment;
    					else $likes[] = $comment;
    			}
    			$score = count($likes) - count($unlikes);
    			$totalvotes = count($likes) + count($unlikes);
    			if ($score > 0 )
    				{
    				echo '<span class="plusscore">+'.$score.'</span><br>';
    				}
    			elseif ($score == 0 )
    				{
    				echo '<span class="zeroscore">'.$score.'</span><br>';
    				}
    			elseif ($score < 0 )
    				{
    				echo '<span class="minusscore">'.$score.'</span><br>';
    				}
    			if ($score == 1 )
    				{
    				echo '<span class="totalvotes">Score uit <a href="#comments">'.$totalvotes.' stem</a></span>';
    				}
    			elseif ($score == -1 )
    				{
    				echo '<span class="totalvotes">Score uit <a href="#comments">'.$totalvotes.' stem</a></span>';
    				}
    			elseif ($score == 0 )
    				{
    				echo '<span class="totalvotes"><a href="#comments">Nu stemmen!</a></span>';
    				}
    			else
    				{
    				echo '<span class="totalvotes">Score uit <a href="#comments">'.$totalvotes.' stemmen</a></span>';
    				}
    		?>
  30. bcworkz
    Member
    Posted 4 months ago #

    Good catch with count()! My bad :(

    I'm pleased everything is otherwise working well, you're most welcome.

    To have this code on various archive pages, I suggest you make a template tag function out of your code, and store it either on functions.php or in a simple plugin. Then where the code currently exists, replace the entire code with a call to your new template tag. You can use it in a similar manner inside of any loop. including the loops on archive pages.

    The one problem with this scheme is you cannot then use values internal to the function farther down the page. One way around this is to have the function return a value (or array of values) that can be assigned to a local variable for use elsewhere on the page.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.