I have no knowledge of PHP but I have already been hit so far that I want to put the last bit myself. As you can see below, I retrieve data from the database. Below is the part that it is about.
<div class="gp-hub-block gp-hub-block-three">
<?php if ( ghostpool_option( 'hub_fields' ) ) {
// Support for foreign characters
$char_table = array();
if ( function_exists( 'ghostpool_hub_field_characters' ) ) {
$char_table = ghostpool_hub_field_characters();
}
foreach( ghostpool_option( 'hub_fields' ) as $gp_hub_field ) {
$gp_hub_field_slug = strtr( $gp_hub_field, $char_table );
if ( function_exists( 'iconv' ) ) {
$gp_hub_field_slug = iconv( 'UTF-8', 'UTF-8//TRANSLIT//IGNORE', $gp_hub_field_slug );
}
$gp_hub_field_slug = sanitize_title( $gp_hub_field_slug );
$gp_hub_field_slug = substr( $gp_hub_field_slug, 0, 32 );
$gp_term_list = get_the_term_list( $post_id, $gp_hub_field_slug, '<table class="casino-info"><tbody><span class="aaa"><tr class="casino-info-titel"><th scope="row">' . __($gp_hub_field,'JDcustomnew') . ':</th><td scope="row" data-label="'<?php echo ($gp_hub_field ); ?>'">', ', ', '</td></tbody></table>' );
if ( ! $gp_term_list OR is_wp_error( $gp_term_list ) ) {
continue;
}
if ( ghostpool_option( 'hub_field_links' ) == 'disabled' ) {
$gp_term_list = preg_replace( '/<\/?a[^>]*>/', '', $gp_term_list );
}
echo wp_kses_post( $gp_term_list );
}
} ?>
</div>
</div>
You will see below for which part it is exactly
$gp_term_list = get_the_term_list( $post_id, $gp_hub_field_slug, '<table class="casino-info"><tbody><span class="aaa"><tr class="casino-info-titel"><th scope="row">' . __($gp_hub_field,'JDcustomnew') . ':</th><td scope="row" data-label="'<?php echo ($gp_hub_field ); ?>'">', ', ', '</td></tbody></table>' );
What I want to do is return the $gp_hub_field to the datalabel of my table. Unfortunately, I can not do this. Someone who can help me?
Don't blame me for my PHP skills please.
EDIT:
I see this with the PHP code in the data-label:
Its important for Google that the data label has the same title as the <TH> I need to see this with the good data-lable title:
Related
Jut updated wordpress and woocommerce to the latest versions. Unfortunately im getting a 500 Internal Server somewhere in the following lines:
add_action( 'woocommerce_before_shop_loop_item', 'attribute_img_loop', 20 );
function attribute_img_loop() {
global $post;
$attribute_names = array( 'pa_sertifikalar' ); // Add attribute names here and remember to add the pa_ prefix to the attribute name
// echo '<script>alert('.$attribute_names.');</script>';
foreach ( $attribute_names as $attribute_name ) {
$taxonomy = get_taxonomy( $attribute_name );
if ( $taxonomy && ! is_wp_error( $taxonomy ) ) {
$terms = wp_get_post_terms( $post->ID, $attribute_name );
$terms_array = array();
if ( ! empty( $terms ) ) {
echo '
<table class="combs" cellspacing="0">
<tbody>
<tr>
<td>
<ul class="nm-variation-control ul-control-certificate">';
foreach ( $terms as $term ) {
$thumb_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
$image_id = absint( get_term_meta( $term->term_id, 'nm_pa_image_thumbnail_id', true ) );
$img_src = ( $image_id ) ? wp_get_attachment_url( $image_id ) : '';
$archive_link = get_term_link( $term->slug, $attribute_name );
$full_line = '<li><div class="lcrap"><img id="c'. $image_id .'" data-src="'. $img_src .'" alt="" class="lazyload" alt="'. $term->name .'" /></div></li>';
array_push( $terms_array, $full_line );
}
// echo $taxonomy->labels->name . ' ' . implode( $terms_array, '-- ' );
echo implode( $terms_array, '');
echo '</ul>
</td>
</tr>
</tbody>
</table>';
}
}
}
}
Just added echo '<script>alert('.$attribute_names.');</script>'; to check the output from the $attribute_names = array( 'pa_sertifikalar' );
part and saw it returns a
function Array() {
[native code]
}
Any idea whats going on here? Using PHP 8.1
From a discussion in the comments, the fix is to change implode( $terms_array, '') to implode('', $terms_array).
Historically the order of these parameters didn't matter, however as of PHP 7.4 passing the array first was deprecated and it was completely removed in PHP 8.0.
I am using javo directory theme and I cannot seem to figure this out. On the map page where there are a list of listings (after user does a search by category). However, only the first category is being displayed and I need all the categories of each listing to be displayed. Displaying only 1 category defeats the purpose of being able to search by category. Here is the code, let me know if you need other code to better understand what I am trying to do but I know the change has to be within this area. I have looked everywhere for a solution which is why I need some help Thanks a lot!
public function get_meta( $key, $default_value=false ) {
$strOutput = get_post_meta( $this->post_id, $key, true );
return empty( $strOutput ) ? $default_value : $strOutput;
}
public function m( $key, $value=false ){
return $this->get_meta( $key, $value );
}
public function get_term( $taxonomy=false, $sep=', ' )
{
$output_terms = Array();
if( $terms = wp_get_object_terms( $this->post_id, $taxonomy, Array( 'fields' => 'names' ) ) )
{
$output_terms = is_array( $terms ) ? join( $sep, $terms ) : null;
$output_terms = trim( $output_terms );
// $output_terms = substr( $output_terms, 0, -1 );
}else{
$output_terms = '';
}
return $output_terms;
}
public function c( $taxonomy=false, $default='', $single=true, $sep=', ' )
{
$strTerms = $this->get_term( $taxonomy, $sep );
if( $single && !empty( $strTerms ) ) {
$strTerms = #explode( $sep, $strTerms );
$strTerms = isset( $strTerms[0] ) ? $strTerms[0] : '' ;
}
return empty( $strTerms ) ? $default : $strTerms;
}
public function category() {
return $this->c(
apply_filters( 'jvfrm_spot_' . get_class( $this ) . '_featured_tax', 'category', $this->post_id ),
apply_filters( 'jvfrm_spot_' . get_class( $this ) . '_featured_no_tax', __( "No Category", 'javo' ), $this->post_id )
);
}
I’ve got the following answer from a question I posted in WordPress Stack Exchange, but how do I show the currency symbol (£) before the value of $givingback_details_funds?
$giving_back = array();
$givingback_details_funds = get_post_meta( $post->ID,'givingback_details_funds', true );
if ( $givingback_details_funds ) {
$giving_back[] = $givingback_details_funds;
}
$givingback_details_days = get_post_meta( $post->ID, 'givingback_details_days', true );
if ( $givingback_details_days ) {
$giving_back[] = _n( 'one working day', $givingback_details_days. ' working days', $givingback_details_days );
}
if ( ! empty( $giving_back ) ) {
echo 'the team donated' . implode( ' and ', $giving_back );
}
What do you even mean? so you cant use this?
$giving_back = array();
$givingback_details_funds = get_post_meta( $post->ID,'givingback_details_funds', true );
if ( $givingback_details_funds ) {
$giving_back[] = $givingback_details_funds;
}
$givingback_details_days = get_post_meta( $post->ID, 'givingback_details_days', true );
if ( $givingback_details_days ) {
$giving_back[] = _n( 'one working day', $givingback_details_days. ' working days', $givingback_details_days );
}
if ( ! empty( $giving_back ) ) {
echo 'the team donated £' . implode( ' and £', $giving_back );
}
or this: EDITED
$giving_back = array();
$givingback_details_funds = get_post_meta( $post->ID,'givingback_details_funds', true );
if ( $givingback_details_funds ) {
$giving_back[] = $givingback_details_funds;
}
$givingback_details_days = get_post_meta( $post->ID, 'givingback_details_days', true );
if ( $givingback_details_days ) {
$giving_back[] = _n( 'one working day', $givingback_details_days. ' working days', $givingback_details_days );
}
$giving_back2 = array_map("mapper",$giving_back);
if ( ! empty( $giving_back2 ) ) {
echo 'the team donated' . implode( ' and ', $giving_back2 );
}
function mapper($a){
return '£'.$a;
}
Or if you are not gonna use the $giving_back again like for only having numbers you can also use this. as – Hamza Abdaoui said.
$giving_back[] = '£ '.$givingback_details_funds;
I switched from intelliJ to VIM a few days ago and I have a few problems with my syntax highlighting. I'm mainly working with php and html and in some files some of the ; are marked with a red background (maybe meaning there is an error in my syntax?). This most likely happens when the ; is followed by a comment //. I'm pretty sure there are no errors...
Also a few files do not provide php syntax highlight at all after a blockcomment /**/ until the php tag ?> gets closed.
Any idea what im missing? Also I'd appreciate suggestions on alternatives for syntax highlighting. It's hard to find useful stuff for webdev since VIM isn't that popular in that sector I guess.
Here my current vim settings:
https://github.com/raQai/.vim
I'd appreciate your help
Edit:
Here is the code thats causing the problems:
<?php namespace KF\LINKS;
defined ( 'ABSPATH' ) or die ( 'nope!' );
/**
* Plugin Name: KF Attachment Links
* Description: Adding attatchemts to post, pages and teams (Kong Foos Team Manager)
* Version: 1.0.0
* Author: Patrick Bogdan
* Text Domain: kfl
* License: GPL2
*
* Copyright 2015 Patrick Bogdan
* TODO: Settings for post_types with checkboxes
*/
new KFLinksMetaBox();
class KFLinksMetaBox {
const kfl_key = 'kf-links-information';
function __construct() {
if (is_admin ()) {
add_action ( 'admin_enqueue_scripts', wp_enqueue_style ( 'kfl-admin-style', plugins_url( 'includes/css/admin-styles.css', plugin_basename( __FILE__ ) ) ) );
add_action ( 'admin_enqueue_scripts', wp_enqueue_script ( 'kfl-admin-js', plugins_url( 'includes/js/kfl-admin-scripts.js', plugin_basename( __FILE__ ) ) ) );
add_action ( 'add_meta_boxes', array( &$this, 'kf_links_meta_box_add' ) );
add_action ( 'save_post', array( &$this, 'kf_links_meta_box_save' ) );
}
register_deactivation_hook( __FILE__, array( &$this, 'kf_links_uninstall' ) );
add_filter( 'the_content', array( $this, 'kf_links_add_to_posts' ) );
}
function kf_links_uninstall() {
delete_post_meta_by_key( self::kfl_key );
}
function kf_links_add_to_posts( $content ) {
$links = $this->kf_links_explode( get_post_meta( get_the_ID(), self::kfl_key, true ) );
if ( $links['is_active'] == '1' && count($links['items']) > 0 ) {
$links_html = '';
if ( !empty($links['title']) ) {
$links_html .= '<strong>' . $links['title'] . '</strong>';
}
foreach ( $links['items'] as $link ) {
if ( !empty( $link['name'] ) && !empty( $link['url'] ) ) {
$links_html .= '<br />» ' . $link['name'] . '';
}
}
if ( !empty( $links_html ) ) {
$content .= '<p class="attachment-links">' . $links_html . '</p>';
}
}
return $content;
}
function kf_links_meta_box_add() {
$screens = array( 'post', 'page', 'teams' );
foreach( $screens as $screen)
{
add_meta_box (
'kf_links_meta_box', // id
'Linksammlung', // title
array( &$this, 'kf_links_meta_box_display' ), // callback
$screen, // post_type
'normal', // context
'high' // priority
);
}
}
function kf_links_meta_box_display( $post ) {
wp_nonce_field( 'kf_links_meta_box', 'kf_links_meta_box_nonce' );
$this->kf_links_meta_box_display_html( $post );
}
function kf_links_meta_box_display_html( $post )
{
$post_string = get_post_meta( $post->ID, self::kfl_key, true );
$links = $this->kf_links_explode( $post_string );
?>
<div class="kf-meta-box-checkbox">
<input onClick="kfl_checkboxDivDisplay( this.id, 'kf-links' ); kfl_creaetLinksString();" <?php if ( $links['is_active'] ) echo 'checked '; ?>type="checkbox" id="kf-links-checkbox" value="1" />
<label id="kf-links-checkbox-label" for="kf-links-checkbox">Linksammlung aktivieren</label>
</div>
<div id="kf-links" <?php if ( !$links['is_active'] ) echo 'style="display:none" '; ?>>
<div class="kf-meta-box-full">
<label for="kf-links-title">Titel der Linksammlung</label>
<input onChange="kfl_creaetLinksString()" id="kf-links-title" value="<?php echo $links['title']; ?>" placeholder="Titel der Linksammlung" />
</div>
<div class="kf-links-header">
<label>Name</label>
<label>URL</label>
</div>
<div id="kf-links-items">
<?php
foreach ( $links['items'] as $ID => $arr ) {
$this->kf_links_item_display_html( $ID, $arr, $links['is_active'] );
}
if ( count( $links['items'] ) < 1 ) {
$this->kf_links_item_display_html( 0, array( 'name' => '', 'url' => '' ), false );
}
?>
</div>
<h4>+ Weiteren Link hinzufügen</h4>
<input type="hidden" id="kf-links-counter" value="<?php echo ( ( count($links['items']) < 1 ) ? 1 : count($links['items']) ); ?>" />
<input type="hidden" name="<?php echo self::kfl_key; ?>" id="<?php echo self::kfl_key; ?>" value="<?php echo $post_string; ?>" />
</div>
<?php
}
function kf_links_item_display_html( $ID, $arr, $is_active )
{
?>
<div id="kf-links-item[<?php echo $ID; ?>]" class="kf-links-item">
<input onChange="kfl_creaetLinksString();" value="<?php echo $arr['name']; ?>" <?php if ( $is_active ) echo 'required '; ?>placeholder="Name" />
<input onChange="kfl_creaetLinksString();" value="<?php echo $arr['url']; ?>" <?php if ( $is_active ) echo 'required '; ?>placeholder="http://..." />
<input onClick="kfl_deleteLink( 'kf-links-item[<?php echo $ID; ?>]' ); kfl_creaetLinksString();" value="✗" type="button" class="button button-small button-primary" />
</div>
<?php
}
function kf_links_meta_box_save($post_id)
{
if ( !isset( $_POST['kf_links_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['kf_links_meta_box_nonce'], 'kf_links_meta_box' )) {
return $post_id;
}
$post_type = get_post_type_object( $_POST['post_type'] );
if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) {
return;
}
$new_meta_value = ( isset( $_POST[self::kfl_key] ) ? $_POST[self::kfl_key] : '');
update_post_meta( $post_id, self::kfl_key, $new_meta_value );
}
function kf_links_explode( $string )
{
if ( empty($string) || !is_string($string) ) {
$links['is_active'] = 0;
return $links;
}
$explode = explode( ';$;', $string );
$links['is_active'] = ( isset( $explode[0] ) ? $explode[0] : 0 );
$links['title'] = ( isset( $explode[1] ) ? $explode[1] : '' );
$links['items'] = array();
for ( $i = 2; $i < count( $explode ); $i++ ) {
$explode2 = explode( ';?;', $explode[$i] );
$link = array(
'name' => $explode2[0],
'url' => $explode2[1]
);
$links['items'][] = $link;
}
return $links;
}
}
And here some screenshots:
https://www.dropbox.com/sh/jj3gluc7ok001hu/AABq_hRiKcbbDo1E0rKpP2Jxa?dl=0
Try :syntax sync fromstart.
If that works, add autocmd BufEnter * :syntax sync fromstart to your .vimrc
Explanation: if the syntax highlighter does not process every line of code from the beginning, it may not receive a critical piece of information to understand what type of code it's processing. E.g., if you're in an HTML file and deep within a script tag, the syntax highlighter may not look back far enough to see the script tag and therefore processes your JS code as HTML.
I got a WordPress Rating plugin from "http://www.smashingmagazine.com/2012/05/08/adding-custom-fields-in-wordpress-comment-form/"
I would like to count the total number of rating and print that number under the Blog Post. Is this possible?
I added some customisation in this code.
<?php
// Add fields after default fields above the comment box, always visible
add_action( 'comment_form_logged_in_after', 'additional_fields' );
add_action( 'comment_form_after_fields', 'additional_fields' );
function additional_fields () {
echo '<p class="comment-form-rating">'.
'<label for="rating">'. __('Rating') . '<span class="required">*</span></label>
<span class="commentratingbox">';
for( $i=1; $i <= 5; $i++ )
echo '<span class="commentrating"><input type="radio" checked name="rating" id="rating" value="'. $i .'"/>'. $i .' Star</span>';
echo'</span></p>';
}
// Save the comment meta data along with comment
add_action( 'comment_post', 'save_comment_meta_data' );
function save_comment_meta_data( $comment_id ) {
if ( ( isset( $_POST['rating'] ) ) && ( $_POST['rating'] != '') )
$rating = wp_filter_nohtml_kses($_POST['rating']);
add_comment_meta( $comment_id, 'rating', $rating );
}
// Add the filter to check if the comment meta data has been filled or not
add_filter( 'preprocess_comment', 'verify_comment_meta_data' );
function verify_comment_meta_data( $commentdata ) {
if ( ! isset( $_POST['rating'] ) )
wp_die( __( 'Error: You did not add your rating. Hit the BACK button of your Web browser and resubmit your comment with rating.' ) );
return $commentdata;
}
//Add an edit option in comment edit screen
add_action( 'add_meta_boxes_comment', 'extend_comment_add_meta_box' );
function extend_comment_add_meta_box() {
add_meta_box( 'title', __( 'Comment Metadata - Extend Comment' ), 'extend_comment_meta_box', 'comment', 'normal', 'high' );
}
function extend_comment_meta_box ( $comment ) {
$phone = get_comment_meta( $comment->comment_ID, 'phone', true );
$title = get_comment_meta( $comment->comment_ID, 'title', true );
$rating = get_comment_meta( $comment->comment_ID, 'rating', true );
wp_nonce_field( 'extend_comment_update', 'extend_comment_update', false );
?>
<p>
<label for="rating"><?php _e( 'Rating: ' ); ?></label>
<span class="commentratingbox">
<?php for( $i=1; $i <= 5; $i++ ) {
echo '<span class="commentrating"><input type="radio" name="rating" id="rating" value="'. $i .'"';
if ( $rating == $i ) echo ' checked="checked"';
echo ' />'. $i .' </span>';
}
?>
</span>
</p>
<?php
}
// Update comment meta data from comment edit screen
add_action( 'edit_comment', 'extend_comment_edit_metafields' );
function extend_comment_edit_metafields( $comment_id ) {
if( ! isset( $_POST['extend_comment_update'] ) || ! wp_verify_nonce( $_POST['extend_comment_update'], 'extend_comment_update' ) ) return;
if ( ( isset( $_POST['phone'] ) ) && ( $_POST['phone'] != '') ) :
$phone = wp_filter_nohtml_kses($_POST['phone']);
update_comment_meta( $comment_id, 'phone', $phone );
else :
delete_comment_meta( $comment_id, 'phone');
endif;
if ( ( isset( $_POST['title'] ) ) && ( $_POST['title'] != '') ):
$title = wp_filter_nohtml_kses($_POST['title']);
update_comment_meta( $comment_id, 'title', $title );
else :
delete_comment_meta( $comment_id, 'title');
endif;
if ( ( isset( $_POST['rating'] ) ) && ( $_POST['rating'] != '') ):
$rating = wp_filter_nohtml_kses($_POST['rating']);
update_comment_meta( $comment_id, 'rating', $rating );
else :
delete_comment_meta( $comment_id, 'rating');
endif;
}
// Add the comment meta (saved earlier) to the comment text
// You can also output the comment meta values directly in comments template
add_filter( 'comment_text', 'modify_comment');
function modify_comment( $text ){
$plugin_url_path = WP_PLUGIN_URL;
if( $commenttitle = get_comment_meta( get_comment_ID(), 'title', true ) ) {
$commenttitle = '<strong>' . esc_attr( $commenttitle ) . '</strong><br/>';
$text = $commenttitle . $text;
}
if( $commentrating = get_comment_meta( get_comment_ID(), 'rating', true ) ) {
$commentrating = '<p class="comment-rating"> <img src="'. $plugin_url_path .
'/ExtendComment/images/'. $commentrating . 'star.gif"/><br/>Rating: <strong>'. $commentrating .' / 5</strong></p>';
$text = $text . $commentrating;
return $text;
} else {
return $text;
}
}
It would go something like this. Appending the total for all ratings:
if( !is_admin() )
add_filter( 'the_content', 'content_so_23778986' );
function content_so_23778986( $content )
{
if( !is_single() )
return $content;
# Get all comments from current post
$comms = get_comments( array( 'post_id'=>get_the_ID() ) );
$counter = null;
if( $comms )
{
$total = count( $comms );
# Iterate all comments and add its rating to the counter
foreach( $comms as $c )
{
$rating = (int) get_comment_meta( $c->comment_ID, 'rating', true );
$counter += $rating;
}
# Calculate and print the totals
$counter = '<br />' . $counter / $total . ' de 5';
}
return $content . $counter;
}