Having two RSS Feed URLs for WordPress - wordpress

I am using MailChimp for my self hosted WordPress blog. MailChimp fetches RSS feeds for it's email templates. I want to add small thumbnail with excerpts in RSS feed so that they appear on MailChimp's email template but I do not want to modify the original RSS feed URL. I want to have a different URL for feeds modified for MailChimp like this: mysite.com/mailchimpfeed where as the original mysite.com/feed remains unchanged.
What will be the best way to do this?

Basic MailChimp feed:
Here's one simple idea:
/**
* Basic MailChimp feed
*
* Example: domain.com/mailchimpfeed
*/
function mailchimp_feed()
{
add_feed( 'mailchimpfeed', 'do_feed_rss2' );
}
add_action('init', 'mailchimp_feed' );
to reuse the native RSS2 feed, under a different url.
MailChimp feed with featured images:
If we want to add the featured images to the MailChimp feed, we can use:
/**
* MailChimp feed with featured images
*
* Example: domain.com/mailchimpfeed
*/
add_action('init', 'mailchimp_feed' );
function mailchimp_feed()
{
add_feed( 'mailchimpfeed', 'mailchimp_feed_template' );
}
function mailchimp_feed_template()
{
add_action( 'rss2_item', 'mailchimp_media_item' );
add_action( 'rss2_ns', 'mailchimp_ns' );
do_feed_rss2();
}
function mailchimp_ns()
{
print 'xmlns:media="http://search.yahoo.com/mrss"';
}
function mailchimp_media_item()
{
if( has_post_thumbnail( get_the_ID() ) )
$image = array_shift( wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'large' ) ) );
else
$image = sprintf( '%s/default.jpg', get_site_url() );
printf( '<media:content url="%s/default.jpg" medium="image" />', $image );
}
We can then modify the featured image size to our needs and the default image if there's no one set.
Flush rewrite rules once to activate:
In both cases we just have to remember to flush the permalinks settings to activate the custom MailChimp feed.
--
Hope this helps.

Related

Add blocks to custom location on shop page?

On my woocommerce shop page I want to remove the description/blocks from the all-in-one woocommerce product grid block. Then add them back above it separately for layout reasons.
So I've removed the description like this:
remove_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description', 10 );
Then I thought I could just add it back in with a shortcode block in the archive-product.html template.
add_shortcode('shop_description', 'woocommerce_product_archive_description');
The problem is, this adds it to the very top of document even before the <html> tag, instead of where I put the shortcode block...
I realised the woocommerce_product_archive_description function uses echo and to make it work with a shortcode it needs to instead use return.
So I made a new function for the shortcode and boiled it down to be:
$shop_page = get_post( wc_get_page_id( 'shop' ) );
$allowed_html = wp_kses_allowed_html( 'post' );
$description = wc_format_content( wp_kses( $shop_page->post_content, $allowed_html ) );
if ( $description ) {
return $description;
}

Can I create custom post type just for documents like PDF, Video, images? WordPress

What I Have done until now, I am creating a WordPress plugin to add menu page for the document management in WordPress
<?php
/**
*
*
*
* #wordpress-plugin
* Plugin Name: doc management
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/** Step 2 (from text above). */
add_action( 'admin_menu', 'my_plugin_menu' );
/** Step 1. */
function my_plugin_menu() {
add_menu_page( 'My Plugin Options', 'docs Management', 'manage_options', 'my_unique_identifier2', 'my_plugin_options','',4 );
}
/** Step 3. */
function my_plugin_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
$file = plugin_dir_path( __FILE__ ) . 'view/main.php';
include_once $file;
}
?>
but I need to add functionality just like in WordPress Post and pages menu. So I am thinking instead of creating a new plugin for the functionality can I do it with custom post type. instead of adding pages or post I just want to add a document. that it's nothing else means instead of adding a new page. add a new document and list all those documents. bulk delete and all.
Is there any specific need that you are trying to build a custom plugin?
I recommend, you may try using https://wordpress.org/plugins/custom-post-type-ui/

WP woocommerce change "Proceed to checkout" buttons URL

I want to change to URL of the "Proceed to checkout" button. I wanna do this to to check if there's a need for my product, so my customers shouldn't be able to really buy it. Therefore I want to direct them not to the checkout but to a customized page of mine.
Thanks a lot.
Josh
It should be available at below path
wp-content/plugins/woocommerce/templates/cart/proceed-to-checkout-button.php
the best way is the woocommerce hooks
Try to use this code (put it in your functions.php theme file).
add_filter( 'woocommerce_get_checkout_url', 'my_change_checkout_url', 30 );
function my_change_checkout_url( $url ) {
$url = "your checkout url ";
return $url;
}
You can customize it by adding some conditions to change the checkout url
for example:
add_filter( 'woocommerce_get_checkout_url', 'my_change_checkout_url', 30 );
function my_change_checkout_url( $url ) {
$allowed_countries = array('FR');
$customer_country = WC()->customer->get_default_country();
if( !in_array( $customer_country , $allowed_countries ) ) {
$url = wc_get_page_permalink( 'other-checkout' );
}
return $url;
}
Change Proceed To Checkout Text In WooCommerce
* Change Proceed To Checkout Text in WooCommerce
* Place this in your Functions.php file
This is the new method, for version 2.3.8 of WooCommerce and forward.
<?php
function woocommerce_button_proceed_to_checkout() {
$checkout_url = WC()->cart->get_checkout_url();
?>
<?php _e( 'Check On Out', 'woocommerce' ); ?>
<?php
}

Customize the search results page in a Wordpress Genesis child theme

I am using Wordpress and the Genesis framework for a site. I'm using a child theme (Ayoshop - not that it matters much) for the theme. I would like to customize the search results page by removing the 'post info' area where it shows the date, author, and 'leave a comment' link, and instead show the featured image for that post. The theme is using the search.php page from the Genesis theme, so I'm not really sure how to proceed in how to customize it.
Here is the code from the Genesis theme search.php:
add_action( 'genesis_before_loop', 'genesis_do_search_title' );
/**
* Echo the title with the search term.
*
* #since 1.9.0
*/
function genesis_do_search_title() {
$title = sprintf( '<div class="archive-description"><h1 class="archive-title">%s %s</h1></div>', apply_filters( 'genesis_search_title_text', __( 'Search Results for:', 'genesis' ) ), get_search_query() );
echo apply_filters( 'genesis_search_title_output', $title ) . "\n";
}
genesis();
It actually did matter that it was the Ayoshop theme, there was a custom filter that was added in a file called theme-tweaks.php that removed the original post info and added a custom post info, so I needed to remove that custom action.
All of the changes were done in the functions.php file.
I made sure to remove the genesis_post_info, and then removed the custom action that Ayoshop added.
remove_action( 'genesis_before_post_content', 'genesis_post_info' );
remove_action( 'genesis_before_post_content', 'ayo_post_info' );
I then added an action to add the image to the post.
add_action ( 'genesis_before_post_content', 'jl_post_info' );
function jl_post_info()
if ( has_post_thumbnail() ) {
printf( '<div class="post-info">' . get_the_post_thumbnail() . '</div>');
}
}

Only show images/attachments within the gallery?

When i create a page, add a gallery, and browse this gallery on the front-end it will browse all the attachments that are associated with that page, instead of just the images within that gallery. Is there a way to filter all the other attachments and only show the images within a certain gallery? So that, for instance, when I delete the gallery and add a new gallery on the same page > only the new gallery is shown?
Any ideas?
This might not be the most elegant way, but i've found it very usefull.
Passing a post ID to the function below will load a gallery from the post_content of that post. So you would create a gallery and insert it into your post content, then in the template you run this function and will be returned with an array of attachments in that gallery which you are free to to whatever with, i.e slideshows and the likes.
function wp_load_gallery($post_id) {
$post = get_post( $post_id );
$regx = '/' . get_shortcode_regex() . '/';
preg_match( $regx, $post->post_content, $matches );
$ids = shortcode_parse_atts( $matches[3] );
$gallery = array( );
foreach( explode( ',', $ids['ids'] ) as $id ) {
if($id) {
$gallery[] = get_post( $id );
}
}
return $gallery;
}
Note that the shortcode is not cut from the content, so when you display the content you should run it through the strip_shortcodes function, i.e:
echo strip_shortcodes( get_the_content() );
This allows you to update the gallery whenever you want with whatever you want.
EDIT:
To simply display all images:
$gallery = wp_load_gallery($YOUR_POST_ID);
foreach($gallery as $image) {
echo wp_get_attachment_image($image->ID);
}

Resources