I have a question im busy with a filter inside of wordpress. Now i have problem i try to explain.
If a visitor select a "single merk" url gonna be ?merk=Brand1 and than option 2 is select "Soort" than the url is gonna be "?merk=Brand1&soort=Soort1" that works.
But if you have select both, than want to change only ?merk=Brand2 than the url is "?merk=Brand2&soort=Soort1&merk=brand1" how can i make it if you switch between the "merk" that "Brand1" replaced to "Brand2".
Here is the code:
foreach ( $allemerken as $merksingle ) { ?>
<?php if(isset($_GET['merk']) && $_GET['merk'] == $merksingle->slug){?>
<i class="fa fa-times" aria-hidden="true"></i> <?php echo $merksingle->name; ?>
<?php }else{ ?>
<?php echo $merksingle->name; ?>
<?php }?>
<?php }?>
<p class="mt-30"><strong>Soort:</strong></p>
<?php
$soorten = get_terms('warmtepompcategorie');
// echo '<pre>'.print_r($allemerken,true).'</pre>';
foreach ( $soorten as $soort ) { ?>
<?php if(isset($_GET['soort']) && $_GET['soort'] == $soort->slug){?>
<i class="fa fa-times" aria-hidden="true"></i> <?php echo $soort->name; ?>
<?php }else{ ?>
<?php echo $soort->name; ?>
<?php }?>
<?php }?>
Ps. sorry for my bad English, but hope someone can help me out!
I have made a function.
And i did it like this:
function replace_get($newname,$newvalue){
$oldvars = $_GET;
$varsnew = $newname.'='.$newvalue;
foreach($oldvars as $name=> $value){
if($name != $newname){
$varsnew .= '&'.$name.'='.$value;
}
}
return $varsnew;
}
To prevent the values from duplicating I would operate on a $_GET array, or its copy for adding or removing the parameters like:
$_GET['soort'] = 'new value'; // adding, modifying value
unset($_GET['soort']); // removing value
and then using http_build_query() for building the URL-encoded query string like this:
$query = http_build_query(array('aParam' => $data));
Related
I am using WCFM plugin. Everything works fine, there is only one problem that I have not solved yet, that is the link of the product tab appearing 2 // characters, and it is wrong with some other functions on my web.
Here is the screenshot
all other tabs are fine, only the product tab appears 2 characters / as below.
ex: mydomain.com/store/storename//#tab_links_area
And I want it to turn into the following
mydomain.com/store/storename/#tab_links_area
or: mydomain.com/store/storename/product/#tab_links_area
And I have checked that the code that affects this place is in store-tabs.php file of WCFM plugin as follows
<?php do_action( 'wcfmmp_store_before_tabs', $store_user->get_id() ); ?>
<div id="tab_links_area" class="tab_links_area">
<ul class="tab_links">
<?php foreach( $store_tabs as $store_tab_key => $store_tab_label ) { ?>
<li class="<?php if( $store_tab_key == $store_tab ) echo 'active'; ?>"><?php echo $store_tab_label; ?></li>
<?php } ?>
</ul>
</div>
<div class="wcfm-clearfix"></div>
<?php do_action( 'wcfmmp_store_after_tabs', $store_user->get_id() ); ?>
I don't know anything about code, can you help me fix this issue using CSS or using code to insert to function.php in my child theme.
I am very grateful and look forward to your feedback
It seems like the store link is register with a "/" at the end in the database whereas the others are not. Maybe there was a change in the permalink structure between the creation of product page and the other pages.
First thing you can do is to go to settings->permalinks and click the "save changes" to make sure all your links will have the same structure.
If this not solve your issue, you can handle it with your code.
You can test if the last caracter of the string that contains your pages link "$store_user->get_store_tabs_url( $store_tab_key )" end up with a "/" and if it the case delete it before it is used in the anchor tag.
So, in those lines =>
<?php foreach( $store_tabs as $store_tab_key => $store_tab_label ) { ?>
<li class="<?php if( $store_tab_key == $store_tab ) echo 'active'; ?>">
<?php echo $store_tab_label; ?>
</li>
<?php } ?>
you should add the test and have something like that :
<?php foreach( $store_tabs as $store_tab_key => $store_tab_label ) { ?>
<li class="<?php if( $store_tab_key == $store_tab ) echo 'active'; ?>">
<?php
/* Get the link */
$tab_link = $store_user->get_store_tabs_url( $store_tab_key );
/* If the link end up with "/" */
if(substr($tab_link, -1) == "/"){
$tab_link = substr_replace($tab_link ,"",-1); // Delete the last caracter.
}
?>
<?php echo $store_tab_label; ?>
</li>
<?php } ?>
On Wordpress, I’m trying to add a link to single product page using Code Snippets with Advanced Custom Fields. Instead of a link, my code displays as plaintext.
I have tried this code:
function product_datasheet_below_summary() { ?>
$link = get_field('datasheet');
if( $link ):
$link_url = $link['url'];
$link_title = $link['title'];
$link_target = $link['target'] ? $link['target'] : '_self';
?>
<a class="button" href="<?php echo esc_url($link_url); ?>" target="<?php echo esc_attr($link_target); ?>"><?php echo esc_html($link_title); ?></a>
<?php
};
add_action( 'ocean_after_single_product_meta', 'product_datasheet_below_summary', 5 );
This doesn’t work. I was hoping for a link to the Datasheet, but it simply prints, in plaintext:
$link = get_field(‘datasheet’); if( $link ): $link_url =
$link[‘url’]; $link_title = $link[‘title’]; $link_target =
$link[‘target’] ? $link[‘target’] : ‘_self’; ?>
followed by a generic square button link.
What am I doing wrong here? Thanks very much for your help.
Thanks for your advice. Instead of using Code Snippets I just created a child theme and edited the relevant .php file, adding the following:
`
if( $link ):
$link_url = $link['url'];
$link_title = $link['title'];
$link_target = $link['target'] ? $link['target'] : '_self';
?>
<a class= "button" id="datasheet-button" href="<?php echo esc_url($link_url); ?>" target="<?php echo esc_attr($link_target); ?>"><?php echo esc_html($link_title); ?></a>
<?php endif; ?>`
You're getting plaintext after the first ?> because that's a php ending tag, and the Code Snippets plugin doesn't allow for multiple php statements and is simply crashing and dumping plain text rather than executing code.
You need to rewrite the whole function as one php statement and echo all the button html, along with the php variables delimited in the html with .'s. A simple example:
<?php
$var = "Hello World";
echo "<p>The value of the variable is : " . $var . "</p>";
?>
And you may need to use the more standard ACF get field construct, too:
$value = get_field( "text_field" );
Search SE for more examples of echoing html in php.
Your function is a bit all over the place, I have cleaned it up to work in the output you want it to using an object instead of echoing out multiple parts of the button code. This in my opinion is easier to manage and looks nicer as it keeps the HTML and PHP code as separate as possible:
function product_datasheet_below_summary() {
$link = get_field('datasheet');
if( $link ){
$link_url = $link['url'];
$link_title = $link['title'];
$link_target = $link['target'] ? $link['target'] : '_self';
} ob_start();?>
<?php if($link):?>
<a class="button" href="<?php echo $link_url;?>" target="<?php echo $link_target;?>"><?php echo $link_title;?></a>
<?php endif;
return ob_get_clean();
} add_action( 'ocean_after_single_product_meta', 'product_datasheet_below_summary', 5 );?>
I'm trying to display a "Top 10 Leaderboard" list of users on my Wordpress website who have earned the most points using the popular MyCred plugin. The code I found is working perfectly, however against my wishes, myself as the admin always makes the top of this points list because I am on the website helping people all the time, therefore earning points. But, I don't want to be competitive with other users as admin.
New to PHP, I'm having problems figuring out what I need to add to have it not include me — using my Wordpress user ID (#1) I assume — when it generates the "top 10" list.
Here's the complete code I'm working with that I found on GitHub, but I think the relevant small section of code I need to slightly modify is right here:
// Construct unorganized list for each row
echo '<ul class="mycred-this-weeks-leaderboard">';
foreach ($leaderboard as $position => $data) {
echo '<li>';
$user_info = get_userdata($data->user_id);
$tempname = $user_info->user_login;
$lowerstring = strtolower($tempname);
$stringwithoutspace = strtr($lowerstring, ' ', '-');
$username = preg_replace('/[^a-zA-Z0-9_]/', '-', $stringwithoutspace);
?>
<?php if (!empty($username)) { ?>
<div class="leaderboard-info-block">
<span class="leaderboard-avatar"><?php echo $avatar = get_avatar($data->user_id, 49); ?></span> <span class="leaderboard-profile-link"><?php echo $data->display_name; ?></span> <br>
<span class="leaderboard-user-points"><?php echo $mycred->format_creds($data->total); ?></span>
</div>
<?php
}
echo '</li><br>';
}
echo '</ul>';
Thank you for any help you can give me! :-)
Just skip the code inside loop if the $data->user_id is 1 (your user ID)
if($data->user_id == 1){
continue;
}
To implement that code to yours:
echo '<ul class="mycred-this-weeks-leaderboard">';
foreach ($leaderboard as $position => $data) {
if($data->user_id == 1){
continue;
}
echo '<li>';
$user_info = get_userdata($data->user_id);
$tempname = $user_info->user_login;
$lowerstring = strtolower($tempname);
$stringwithoutspace = strtr($lowerstring, ' ', '-');
$username = preg_replace('/[^a-zA-Z0-9_]/', '-', $stringwithoutspace);
?>
<?php if (!empty($username)) { ?>
<div class="leaderboard-info-block">
<span class="leaderboard-avatar"><?php echo $avatar = get_avatar($data->user_id, 49); ?></span> <span class="leaderboard-profile-link"><?php echo $data->display_name; ?></span> <br>
<span class="leaderboard-user-points"><?php echo $mycred->format_creds($data->total); ?></span>
</div>
<?php
}
echo '</li>';
}
echo '</ul>';
i have a code like this, to display a custom field on my Page...
<?php
global $wp_query;
$postid = $wp_query->post->ID;
if($immopress_property['assistedLiving']): ?>
<li class="assistedLiving">
<span class="attribute" style="width:200px;display:block;float:left;"><?php echo 'Seniorengerechtes Wohnen' ; ?><span class="wpp_colon">:</span></span>
<span class="value"><?php if (get_post_meta($post->ID, 'assistedLiving' , true)) echo "Ja"; else echo "Nein"; ?> </span>
</li>
<?php wp_reset_query(); ?>
<?php endif; ?>
But when the custom field NAME & VALUE not exist it shall skip to the next Value and Name. I try different ways to do that but no one works.
Hope someone can help me with that.
changed to this and it works...
if ( get_post_meta($post->ID, 'assistedLiving', true) ) { ?>
I am using custom code to print the comments but the problem is whatever i do, i cant print the comment reply link under any comment....
here is the code
<?php // Do not delete these lines
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('Please do not load this page directly. Thanks!');
if (!empty($post->post_password)) { // if there's a password
if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
?>
<p class="nocomments">This post is password protected. Enter the password to view comments.</p>
<?php
return;
}
}
/* This variable is for alternating comment background */
/*$oddcomment = 'class="alt" ';*/
$oddcomment = 'alt';
?>
<!-- You can start editing here. -->
<?php if ($comments) : ?>
<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>
<ol class="commentlist">
<?php foreach ($comments as $comment) : ?>
<!--<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">-->
<li class="<?php echo $oddcomment; ?> <?php if ($comment->comment_author_email == get_the_author_email()) { echo 'author_comment'; } ?>" id="comment-<?php comment_ID() ?>">
<?php echo get_avatar( $comment, 32 ); ?>
<cite><?php comment_author_link() ?></cite> Says:
<?php if ($comment->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
<br />
<small class="commentmetadata"><?php comment_date('F jS, Y') ?> at <?php comment_time() ?> <?php edit_comment_link('edit',' ',''); ?>
</small>
<?php comment_text() ?>
<div class="reply">
<?php comment_reply_link( array ( 'reply_text' => 'Reply this comment' ) );
?>
</div>
</li>
<?php
/* Changes every other comment to a different class */
/*$oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : '';*/
$oddcomment = ( empty( $oddcomment ) ) ? 'alt' : '';
?>
<?php endforeach; /* end for each comment */ ?>
</ol>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
But when i use wp_list_comments functions i can see the reply link appear automatically i am using wordpress 3.2.1
It can be helpful to read the source for comment_reply_link (http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/comment-template.php#L1061), as there are multiple conditions that can lead to the link not appearing. Work through each one at a time, and you'll likely find your answer.
The one that tripped me up, is that the link will not appear if comments are closed. So it can be helpful to review the comment settings on the blog to make sure that providing replies is actually allowed on this post.
Try this:
comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth'])))
Thanks to the following codex-entry (http://codex.wordpress.org/Function_Reference/comment_reply_link), I managed to find the actual use of the comment_reply_link() on the following link: http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/comment-template.php#L1061
This leaves me with the following question - did you try adding either the second or the third parameter for the function? I think there might be something fishy going on under the hood, making the comment-link not know where to actually link.
Try removing the following snippet
comment_reply_link( array ( 'reply_text' => 'Reply this comment' ) );
and instead use the following one
comment_reply_link( array('reply_text' => 'Reply this comment'), comment_ID(), the_ID() );
Let me know if it works out for you!
Enable nested comments in Admin > Settings > Discussion:
Enable threaded (nested) comments levels deep