I have two WordPress installations, one is main domain and the other one is sub-domain. Also, both sites use different database. Now I want to automatically post content from subdomain to Main Domain.Is there a way to show the most recent post from the second(sub-domain) site on my first(main domain) sites?
Thanks
I'm Able to solve this.
here is the way:
Step 1: Copy the following code wherever you want to display your original WordPress posts:
<?php
include_once(ABSPATH . WPINC . '/feed.php');
$rss = fetch_feed('http://my-subdomain.com/feed/');
if(!empty($rss)):
$maxitems = $rss->get_item_quantity(4);
$rss_items = $rss->get_items(0, $maxitems);
endif;
?>
Step 2: Add this to your code (preferably right after the snippet above):
<ul>
<?php if ($maxitems == 0) echo 'No news.';
else
foreach ( $rss_items as $item ) : ?>
<li><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></li>
<?php endforeach; ?>
</ul>
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 } ?>
I used the following code in my FUNCTIONS file:
add_action('rss2_item', 'add_my_rss_node');
function add_my_rss_node() {
global $post;
if(has_post_thumbnail($post->ID)):
$thumbnail = get_attachment_link(get_post_thumbnail_id($post->ID));
echo("<image>{$thumbnail}</image>");
endif;
}
Now I try to call that image and display it from site A to my site B with a custom RSS tempalte. This is the code of the template.
<?php get_header(); ?>
<?php include_once(ABSPATH.WPINC.'/feed.php');
$rss = fetch_feed('https://notrealurl.net/categoryname-feed/');
$maxitems = $rss->get_item_quantity(30);
$rss_items = $rss->get_items(0, $maxitems);
?>
<ul>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<li>
<a href="<?php echo $item->get_permalink(); ?>">
<?php echo $item->get_title(); ?>
<?php echo $item->get_date('j F Y # g:i a'); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php get_footer(); ?>
I see the image url in my rss feed now ( thanks to that functions script) and it is in a tag.
Looks like this: https://www.mywebsite./url-of-the-image/
They dont have a .jpg or .png extension at the end of the url. Not sure if that is how it needs to be. When I open that link I can see the image, and it works.
Can somebody please help me to figure this out ? I'm working on this thing for 2 days and can't figure it out. My PHP isn't great so that is most likely the reason why I can't figure it out.
Thanks in advance :)
I think you want your function to get the attachment src instead of the link, and echo that src into a <url> tag inside the <image> RSS element (see here).
Try this:
function add_my_rss_node() {
global $post;
if(has_post_thumbnail($post->ID)):
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID));
echo("<image><url>{$thumbnail}</url></image>");
endif;
}
i have a website in joomla, and forum: MYBB,
i installed simplepie to show last posts on my home page,
It works,
But i have only 2 little problems
The update links are posting on a new line so it becmes double, i want it to be updated
The RE: before every reply, i want this to be deleted
example: http://i.imgur.com/MHDAl7A.png
code:
<?php require_once('php/autoloader.php');
$feed = new SimplePie();
$feed->set_feed_url('http://localhost//forum/syndication2.php');
$feed->enable_cache(false);
$feed->init();
$feed->handle_content_type();
?>
<?php foreach ($feed->get_items(0, 10) as $item): ?>
<li><?php echo $item->get_title(); ?></li>
<?php endforeach; ?>
as a newbie in wordpress i m searching over to create link of my 'new-category.php' file to display my product category only & 'category.php' will be default for others. So anyone please tell me how to change the default permalink to link-up my static 'new-category.php' file ?
Here below code displaying the default category page:
<?php $categories=getCategory ();
foreach ($categories as $category) { ?>
<li> <a href=" <?php echo get_category_link( $category->term_id );?>">
<?php echo $category->cat_name; ?> </a></li>
<?php } ?>
Create your page like :
<?php /* Template Name: my_category*/ ?>
<?php get_header(); ?>
//my_category page
<?php get_footer(); ?>
and access it like : http://yourdomain.com/my_category
Template Name: plays important role here.
I have a question regarding RSS feeds. I am using wordpress ver 3.2.1 and using other website rss feeds in my website. My requirement is to fetch the feeds month wise and to show in my website side bar.
Currently i am using rss widget and showing the feeds in sidebar but they are coming in below format:
Thu 9-29 4:30pm Elementary Quest - Parent Information Night
Thu 10-6 -All Day- Half-Day: Elementary Conferences
I will be very thankful for your help. Thanks in advance.
Update: Mar 13 2012
This code is present in index.php
<h2><?php _e('Recent news from Some-Other Blog:'); ?></h2>
<?php // Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/feed.php');
// Get a SimplePie feed object from the specified feed source.
//$rss = fetch_feed('http://example.com/rss/feed/goes/here');
$rss = fetch_feed('http://lakewashington.intand.com/index.php?type=export&action=rss&schools=48&groups=884,876,874,996');
print_r($rss);
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;
?>
<ul>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<li>
<a href='<?php echo esc_url( $item->get_permalink() ); ?>'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo esc_html( $item->get_title() ); ?></a>
</li>
<?php endforeach; ?>
</ul>
You can do it manually.
Just use wordpress native function fetch_feed.
You even have an example in there:
<h2><?php _e('Recent news from Some-Other Blog:'); ?></h2>
<?php // Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/feed.php');
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed('http://example.com/rss/feed/goes/here');
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;
?>
<ul>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<li>
<a href='<?php echo esc_url( $item->get_permalink() ); ?>'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo esc_html( $item->get_title() ); ?></a>
</li>
<?php endforeach; ?>
</ul>
You just need to put that in your sidebar.php, wherever you need to show the feed.
Edit the line:
$rss = fetch_feed('http://example.com/rss/feed/goes/here');
...and point the url to the correct feed.
And:
$maxitems = $rss->get_item_quantity(5);
...to specify how many items to show (five in the example)
Then check the foreach inside the UL, there you can style how the feed are shown.
By default, fetch_feed function will cache the feeds for 12 hours.
If you need to do it every 30 days, you can use the wordpress's Transients API to accomplish that without hassle.