RSS Error in feed with atom / unbound prefix - rss

I'm trying to fix my RSS feed and I can't figure out why it says unbound prefix. I tried removing it and searching for different answers. I saw that most things should be output using CDATA. But that does not seem to be the issue here. I can also see that some title's have their special characters such as ' converted, but nothing that should result in a feed failure.
Here's my code:
<?php
header( 'Content-Type: ' . feed_content_type( 'rss2' ) . '; charset=' . get_option( 'blog_charset' ), true );
$more = 1;
echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>';
do_action( 'rss_tag_pre', 'rss2' );
?>
<rss version="2.0" xmlns:hst="http://hirstart.hu/rss-mod" <?php do_action( 'rss2_ns' ); ?>>
<channel>
<title><?php // wp_title_rss(); ?> Tőzsdefórum | Minden ami tőzsde</title>
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss( 'url' ); ?></link>
<description><?php bloginfo_rss( 'description' ); ?></description>
<lastBuildDate><?php echo get_feed_build_date( 'r' ); ?></lastBuildDate>
<language><?php bloginfo_rss( 'language' ); ?></language>
<sy:updatePeriod>
<?php
$duration = 'hourly';
echo apply_filters( 'rss_update_period', $duration );
?>
</sy:updatePeriod>
<sy:updateFrequency>
<?php
$frequency = '1';
echo apply_filters( 'rss_update_frequency', $frequency );
?>
</sy:updateFrequency>
<?php
do_action( 'rss2_head' );
while ( have_posts() ) :
the_post();
?>
<item>
<title><?php the_title_rss(); ?></title>
<?php
$post_id = get_the_ID();
$kiemelt = get_field( 'kiemelt_cikk' );
if ( is_array( $kiemelt ) ) {
if ( in_array( 'igen', $kiemelt ) ) {
$output = '<hst:titlepage>1</hst:titlepage>';
echo $output;
}
}
?>
<link><?php the_permalink_rss(); ?></link>
<?php if ( get_comments_number() || comments_open() ) : ?>
<comments><?php comments_link_feed(); ?></comments>
<?php endif; ?>
<dc:creator>
<![CDATA[<?php the_author(); ?>]]>
</dc:creator>
<image>
<?php
if ( has_post_thumbnail( $post->ID ) ) {
the_post_thumbnail_url();
}
?>
</image>
<pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
<?php the_category_rss( 'rss2' ); ?>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<?php if ( get_option( 'rss_use_excerpt' ) ) : ?>
<description>
<![CDATA[<?php the_excerpt_rss(); ?>]]>
</description>
<?php else : ?>
<description>
<![CDATA[<?php the_excerpt_rss(); ?>]]>
</description>
<?php $content = get_the_content_feed( 'rss2' ); ?>
<?php if ( strlen( $content ) > 0 ) : ?>
<content:encoded>
<![CDATA[<?php echo $content; ?>]]>
</content:encoded>
<?php else : ?>
<content:encoded>
<![CDATA[<?php the_excerpt_rss(); ?>]]>
</content:encoded>
<?php endif; ?>
<?php endif; ?>
<?php if ( get_comments_number() || comments_open() ) : ?>
<wfw:commentRss><?php echo esc_url( get_post_comments_feed_link( null, 'rss2' ) ); ?></wfw:commentRss>
<slash:comments><?php echo get_comments_number(); ?></slash:comments>
<?php endif; ?>
<?php rss_enclosure(); ?>
<?php
do_action( 'rss2_item' );
?>
</item>
<?php endwhile; ?>
</channel>
When I try to validate, I get this: https://validator.w3.org/feed/check.cgi?url=https%3A%2F%2Ftozsdeforum.hu%2Ffeed%2F
Actual feed link is: https://tozsdeforum.hu/feed/
Any suggestions are appreciated.

Related

Wordpress WooCommerce add Variation on the Cart

Have long ago created a page and moved the shopping cart button into a sidebar wiget
Now I want to complement a product variants, and as I see it, the selection is not shown to me.
Since this is not inserted in the code.
Now would be my question what would I have to insert with this code that this works.
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $product;
?>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<p class="price"><?php echo $product->get_price_html(); ?></p>
<meta itemprop="price" content="<?php echo esc_attr( $product->get_display_price() ); ?>" />
<meta itemprop="priceCurrency" content="<?php echo esc_attr( get_woocommerce_currency() ); ?>" />
<link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" />
<?php if ( wc_gzd_get_gzd_product( $product )->get_tax_info() ) : ?>
<p class="wc-gzd-additional-info tax-info"><?php echo wc_gzd_get_gzd_product( $product )->get_tax_info(); ?></p>
<?php elseif ( get_option( 'woocommerce_gzd_small_enterprise' ) == 'yes' ) : ?>
<p class="wc-gzd-additional-info small-business-info"><?php echo wc_gzd_get_small_business_product_notice(); ?></p>
<?php endif; ?>
<?php if ( wc_gzd_get_gzd_product( $product )->get_shipping_costs_html() ) : ?>
<p class="wc-gzd-additional-info shipping-costs-info"><?php echo wc_gzd_get_gzd_product( $product )->get_shipping_costs_html();?></p>
<?php endif; ?>
<?php if ( wc_gzd_get_gzd_product( $product )->get_delivery_time_html() ) : ?><i class="fi fa fa-truck" style="font-size:20px;width:20px;height:20px;line-height:20px;color:#ee9b11;"></i>
<?php echo wc_gzd_get_gzd_product( $product )->get_delivery_time_html();?></p>
<?php elseif ( $product->is_type( 'variable' ) ) : ?>
<p class="wc-gzd-additional-info delivery-time-info"></p>
<?php endif; ?>
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $product;
if ( ! $product->is_purchasable() ) {
return;
}
?>
<?php
// Availability
$availability = $product->get_availability();
$availability_html = empty( $availability['availability'] ) ? '' : '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>';
echo apply_filters( 'woocommerce_stock_html', $availability_html, $availability['availability'], $product );
?>
<?php if ( $product->is_in_stock() ) : ?>
<?php do_action( 'woocommerce_before_add_to_cart_form' ); ?>
<form class="cart" method="post" enctype='multipart/form-data'>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<?php
if ( ! $product->is_sold_individually() ) {
woocommerce_quantity_input( array(
'min_value' => apply_filters( 'woocommerce_quantity_input_min', 1, $product ),
'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product ),
'input_value' => ( isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : 1 )
) );
}
?>
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />
<button type="submit" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
</form>
<?php do_action( 'woocommerce_after_add_to_cart_form' ); ?>
<?php endif; ?>
There is a file mini-cart.php which contains the markup for the mini-cart, used by the cart widget. This template can be overridden by copying the plugin file woocommerce/cart/mini-cart.php to yourtheme/woocommerce/cart/mini-cart.php.
Thereafter in between the foreach statement
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
Add
if($cart_item['variation_id'] != 0) {
// Getting attribute size selected value
$attribute_size = $cart_item['variation']['attribute_pa_sizes'];
echo $attribute_size;
}
on the variable 'attribute_pa_sizes' the 'sizes' is the variants slug

Display coupon description and id on thankyou.php

Basicly, I would like to display the coupon used on Woocommerce thankyou.php. Here is the code I have added
$coupons = $order->get_items( 'coupon' );
foreach ( $coupons as $item_id => $item ) {
echo "<span class='coupon-name'><b>".$item['name']."</b></span>";
$post = get_post( $item_id );
echo "<p class='coupon-description'>".$post->post_excerpt."</p>";
}
However, only the coupon code is shown while the description does not.
Here is where I placed my code:
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( $order ) : ?>
<?php if ( $order->has_status( 'failed' ) ) : ?>
<p class="woocommerce-thankyou-order-failed"><?php _e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction. Please attempt your purchase again.', 'woocommerce' ); ?></p>
<p class="woocommerce-thankyou-order-failed-actions">
<?php _e( 'Pay', 'woocommerce' ) ?>
<?php if ( is_user_logged_in() ) : ?>
<?php _e( 'My Account', 'woocommerce' ); ?>
<?php endif; ?>
</p>
<?php else : ?>
<?php
$coupons = $order->get_items( 'coupon' );
foreach ( $coupons as $item_id => $item ) {
echo "<span class='coupon-name'><b>".$item['name']."</b></span>";
$post = get_post( $item_id );
echo "<p class='coupon-description'>".$post->post_excerpt."</p>";
}
?>
<p class="woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>
<ul class="woocommerce-thankyou-order-details order_details">
<li class="order">
<?php _e( 'Order Number:', 'woocommerce' ); ?>
<strong><?php echo $order->get_order_number(); ?></strong>
</li>
<li class="date">
<?php _e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></strong>
</li>
<li class="total">
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>
<?php if ( $order->payment_method_title ) : ?>
<li class="method">
<?php _e( 'Payment Method:', 'woocommerce' ); ?>
<strong><?php echo $order->payment_method_title; ?></strong>
</li>
<?php endif; ?>
</ul>
<div class="clear"></div>
<?php endif; ?>
<?php do_action( 'woocommerce_thankyou_' . $order->payment_method, $order->id ); ?>
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>
<p class="woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p>
Could anyone please help me with this?
add_filter('woocommerce_get_order_item_totals','change_discount',10,3);
function change_discount($total_rows, $order, $tax_display){
if ( $order->get_total_discount() > 0 ) {
$coupons = $order->get_used_coupons();
$total_rows['discount'] = array( 'label' => __( 'Coupon code: '.implode(",",$coupons), 'woocommerce' ), 'value' => '-' . $order->get_discount_to_display( $tax_display ), );
}
return $total_rows;
}
you can get like this
if( $order->get_used_coupons() ) {
$coupons_count = count( $order->get_used_coupons() );
echo '<h4>' . __('Coupons used') . ' (' . $coupons_count . ')</h4>';
echo '<p><strong>' . __('Coupons used') . ':</strong> ';
$i = 1;
$coupons_list = '';
foreach( $order->get_used_coupons() as $coupon) {
$coupons_list .= $coupon;
if( $i < $coupons_count )
$coupons_list .= ', ';
$i++;
}
echo '<p><strong>Coupons used (' . $coupons_count . ') :</strong> ' . $coupons_list . '</p>'; }
Please use this code, I hope it will work for you:
<?php
add_action('woocommerce_thankyou', 'apply_product_on_coupon');
function apply_product_on_coupon() {
global $woocommerce;
if ( ! empty( $woocommerce->cart->applied_coupons ) ) {
$my_coupon = $woocommerce->cart->get_coupons() ;
foreach($my_coupon as $coupon){
if ( $post = get_post( $coupon->id ) ) {
if ( !empty( $post->post_excerpt ) ) {
echo "<span class='coupon-name'><b>".$coupon->code."</b></span>";
echo "<p class='coupon-description'>".$post->post_excerpt."</p>";
}
}
}
}
}
?>
If this will not work then use coupon shortcode plugin and call shortcode on the thankyou page
https://wordpress.org/plugins/woocommerce-coupon-shortcodes/
<?php echo do_shortcode('[coupon_shortcode]'); ?>

How to exclude media files from Wordpress RSS feed?

I have custom RSS template for news aggregator. Is it possible to exclude all media files like images/video from the_content_feed(); ?
I need to display a plain text.
Here is my template
header( 'Content-Type: ' . feed_content_type( 'rss-http' ) . '; charset=' . get_option( 'blog_charset' ), true );
$frequency = 1;
$duration = 'hourly';
$postimages = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'large' );
if ( $postimages ) {
$postimage = $postimages[0];
} else {
$postimage = get_stylesheet_directory_uri() . '/images/default.jpg';
}
echo '<?xml version="1.0" encoding="UTF-8"?>' ."\r\n"; ?>
<rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title><?php bloginfo_rss( 'name' ); wp_title_rss(); ?></title>
<link><?php bloginfo_rss( 'url' ) ?></link>
<description><?php bloginfo_rss( 'description' ) ?></description>
<yandex:logo></yandex:logo>
<yandex:logo type="square"></yandex:logo>
<lastBuildDate><?php echo mysql2date( 'D, d M Y H:i:s +0200', get_lastpostmodified( 'GMT' ), false ); ?></lastBuildDate>
<language><?php bloginfo_rss( 'language' ); ?></language>
<?php do_action( 'rss2_head' ); ?>
<?php while( have_posts()) : the_post(); ?>
<item>
<title><?php the_title_rss(); ?></title>
<link><?php the_permalink_rss(); ?></link>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<author><?php the_author(); ?></author>
<enclosure url="<?php echo esc_url( $postimage ); ?>" type="image/jpeg" />
<pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0200', get_date_from_gmt(get_post_time('Y-m-d H:i:s', true)), false ); ?></pubDate>
<description>
<![CDATA[<?php the_excerpt_rss(); ?>]]>
</description>
<yandex:full-text>
<![CDATA[<?php the_content_feed(); ?>]]>
</yandex:full-text>
</item>
<?php endwhile; ?>
</channel>
</rss>
I've tried to use this filter, but had no luck :(
add_filter( "the_content_feed", "excludeimg" ) ;
function excludeimg($content) {
$content = preg_replace('#(<img.*?>).*?(/>)#', '$1$2', $content);
return $content;
}
?>
Here is the solution
To show plain text from the articles in your RSS feed just change the_content_feed(); to echo wp_strip_all_tags( get_the_content() ); in your feed template.

display comments on different categories

I want to only display comments on one of the categories on my wordpress site. So for example my pear category with posts on it will have a comment function available but on my orange page the comment section will be disabled.
Any suggestions?
In the content.php file change:
<?php if ( comments_open() ) : ?>
<div class="comments-link">
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?>
</div><!-- .comments-link -->
<?php endif; // comments_open() ?>
to
<?php
$postid = get_the_ID();
$category = get_the_category( $postid );
$category = $category[0]->cat_name;
if ($category == "Pear")
{
if ( comments_open() ) : ?>
<div class="comments-link">
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?>
</div><!-- .comments-link -->
<?php endif; // comments_open()
}
?>
and in the comments.php file change:
<?php if ( have_comments() ) : ?>
to
<?php
$postid = get_the_ID();
$category = get_the_category( $postid );
$category = $category[0]->cat_name;
if ($category == "Pear")
{
if ( have_comments() ) :
?>
AND change:
<?php endif; // have_comments() ?>
<?php comment_form(); ?>
to
<?php endif; // have_comments() ?>
<?php comment_form();
}
?>
The above should only display comments in posts that are in the Pear category.

How do you get the mp3 file extension from an iTunes feed and display it in a WP loop?

I want to pull the 5 most recent podcasts from an iTunes feed and post them along with their audio to a WP page.
The code I have is below
its pulling the feed and displaying the name, details, etc fine but its using the same podcast audio for each item.
<div class="podcastfeed">
<h4>Recent Podcasts</h4>
<?php // Get $feed Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
$hpFeed=get_post_meta($post->ID, "cmb_hp_feed", true);
$feed = fetch_feed( $hpFeed );
$feed->init();
$feed->handle_content_type();
foreach ($feed->get_items() as $item)
{
if ($enclosure = $item->get_enclosure())
{
$enclosure->get_link();
}
}
if ( ! is_wp_error( $feed ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $feed->get_item_quantity( 5 );
// Build an array of all the items, starting with element 0 (first element).
$feed_items = $feed->get_items( 0, $maxitems );
endif;
$attr = array(
'src' => $enclosure->get_link(),
'loop' => '',
'autoplay' => '',
'preload' => 'none'
);
?>
<ol>
<?php if ( $maxitems == 0 ) : ?>
<li><?php _e( 'No items', 'my-text-domain' ); ?></li>
<?php else : ?>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $feed_items as $item ) : ?>
<li>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?>">
<p>
<span>
<?php echo esc_html( $item->get_title() ); ?>
</span>
<span><?php printf( __( '%s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?></span>
</p>
</a>
<?php echo wp_audio_shortcode( $attr );?>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ol>
</div>
I got it working in the end though it took some fiddling with
The page is now displaying each of the podcasts as audio.
<div class="podcastfeed">
<?php // Get $feed Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
$hpFeed=get_post_meta($post->ID, "cmb_hp_feed", true);
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( $hpFeed );
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity( 5 );
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );
endif;
?>
<?php if ( $maxitems == 0 ) : ?>
<ol style="display:none;"><?php _e( 'No items', 'my-text-domain' ); ?></ol>
<?php else : ?>
<h4>Recent Podcasts</h4>
<ol>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $rss_items as $item ) : ?>
<li>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?>">
<p>
<span>
<?php echo esc_html( $item->get_title() ); ?>
</span>
<span>
<?php printf( __( '%s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?>
</span>
</p>
</a>
<?php
if ($enclosure = $item->get_enclosure()){
$enclosure->get_link();
}
?>
<?php
$attr = array(
'src' => $enclosure->get_link(),
'loop' => '',
'autoplay' => '',
'preload' => 'none'
);
?>
<?php echo wp_audio_shortcode( $attr );?>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ol>
</div>

Resources