I have set up a blog on a subdomain. like blog.mywebsite.com
And I have set up a recent posts widget using RSS Feed on my main website's homepage.
I have managed to display the most recent 3 posts in that widget.
But now when I add a new post on the subdomain blog site that widget is not getting updated. It is showing only old posts.
I used this tutorial to set up the widget. https://www.worldoweb.co.uk/2012/display-wordpress-posts-on-another-wp-blog
The actual PHP Code I am using on my website is below.
<?php
//replace with your URL
$rss = fetch_feed('https://blog.mywebsite.com/feed/');
if (!is_wp_error($rss)) :
$maxitems = $rss -> get_item_quantity(3); //gets latest 3 items This can be changed to suit your requirements
$rss_items = $rss -> get_items(0, $maxitems);
endif;
?>
<?php
//shortens description
function shorten($string, $length) {
$suffix = '…';
$short_desc = trim(str_replace(array("\r", "\n", "\t"), ' ', strip_tags($string)));
$desc = trim(substr($short_desc, 0, $length));
$lastchar = substr($desc, -1, 1);
if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?')
$suffix = '';
$desc .= $suffix;
return $desc;
}
?>
<!--start of displaying our feeds-->
<ul class="rss-items" id="wow-feed">
<?php
if ($maxitems == 0) echo '<li>No items.</li>';
else foreach ( $rss_items as $item ) :
?>
<li class="item">
<span class="data">
<h3><a href='<?php echo esc_url($item -> get_permalink()); ?>' title='<?php echo esc_html($item -> get_title()); ?>'> <?php echo esc_html($item -> get_title()); ?></a></h3>
<span class="date-image"> </span>
<div class="rtin-date"><?php echo $item -> get_date('F j, Y'); ?></div>
<p class="rtin-content"><?php echo shorten($item -> get_description(), '120'); ?></p>
</span>
</li>
<?php endforeach; ?>
</ul>
What I want to do is.
when i add new post to my blog it should show in that RSS widget too.
Related
This is my RSS feed format:
<item>
<title></title>
<link></link>
<description></description>
<pubDate></pubDate>
<guid></guid>
<dc:date></dc:date>
</item>
I want to dipsplay the last 7 posts with CSS style, so I use this code:
<?php
$url = "**THE URL I AM SCRAPING DATA FROM**";
$rss = simplexml_load_file($url);
$i = 0;
if (!empty($rss))
{
$site = $rss
->channel->title;
$sitelink = $rss
->channel->link;
foreach ($rss
->channel->item as $item)
{
$title = $item->title;
$link = $item->link;
$description = $item->description;
$item->description = strip_tags($item->description);
$date = $item->pubDate;
$pubDate = date('d.m.Y', strtotime($date));
if ($i >= 7) break;
?>
<div class="post-item">
<div class="post-item-wrap">
<div class="post-image">
<a href="<?php echo $link;?>">
<img alt="" src="images/news/nra.jpg">
</a>
</div>
<div class="post-item-description">
<span class="post-meta-date"><?php echo $pubDate;?></span>
<h2><a href="<?php echo $link ?>" target="_blank"><?php echo $title;?>
</a></h2>
<p><?php echo implode(' ', array_slice(explode(' ', $description), 0, 30)) . "..";?></p>
learn more <i class="icon-chevron-right"></i>
</div>
</div>
</div>
<?php
$i++;
}
}
?>
Now I want each of these 7 posts to have unique id.
I need script to generate item -> title and item -> description depending on the item -> link.
(If I click first xml post for example it will take me to page where I can display the title and description according to which post I clicked)
Thanks in advance.
use this code get last 7 items
array_slice($rss->channel->item, -7);
If url is "rss.php?feed=1" or "rss.php?feed=2"
$rssSno=$_GET['feed'];
$output = array_slice($rss->channel->item, ($rssSno-1),1);
I am working with a Magento Porto theme and need the left-side category navigation (category_nav.html) to show on sub-sub-sub category pages. I managed to get it to show up on sub-sub category pages, but can't figure out how to get passed there.
Here is my current code:
<?php
$_categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('level', 2)
->addAttributeToFilter('is_active', 1);
?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php
function cmpCatPosition($a, $b) {
if ($a->position == $b->position)
return 0;
return ($a->position > $b->position) ? 1 : -1;
}
function getChildrenCategoriesHtml($_category){
$children = explode( ",", $_category->getChildren() );
//usort($children, 'cmpCatPosition');
$content = '';
$content .= '<li class="';
if(!$children[0])
$content .= 'has-no-children';
else
$content .= 'has-children';
$content .= '">';
$content .= '<a href="'.$_category->getUrl().'" ';
$content .= '>'.$_category->getName().'</a>';
if($children[0]){
$content .= '<i class="icon-plus-squared"></i>';
$content .= '<ul>';
foreach($children as $child){
$_subcat = Mage::getModel( 'catalog/category' )->load( $child );
$content .= getChildrenCategoriesHtml($_subcat);
}
$content .= '</ul>';
}
$content .= '</li>';
return $content;
}
?>
<?php if($_count): ?>
<div class="block block-category-nav">
<div class="block-title">
<strong><span><?php echo Mage::registry('current_category')->getName(); ?></span></strong>
</div>
<div class="block-content">
<ul class="category-list">
<?php foreach ($_categories as $_category): ?>
<?php
if($_category->getIsActive()){
echo getChildrenCategoriesHtml($_category);
}
?>
<?php endforeach ?>
</ul>
</div>
</div>
The code that I made actually works. I just missed adding "Is Anchor -> Yes" in the back end.
There is a code where this can be done globally, but I want control over what shows and what does not, so selecting Yes/No on the anchor solves the issue.
This was (after all the pulling my hair out trying to make it work) not a programming issue.
hi I have portfolio blog and under portfolio page, I show my images as image feed and add via gallery its show simply no hyperlink no title no caption
I want to show the only caption on every image
here is code use to display image in my theme
<?php
global $post;
$header_images = get_post_meta($post->ID, '_ebor_gallery_images', 1);
if( is_array($header_images) ) :
?>
<ul class="basic-gallery text-center">
<?php
foreach( $header_images as $id => $content ){
echo '<li>'. wp_get_attachment_image($id, 'large') .'</li> ';
}
?>
</ul>
how add caption in this help me out for this
thanks !
Try this...
<ul class="basic-gallery text-center">
<?php
$output = '';
foreach( $header_images as $id => $content ){
$output .= '<li>'. wp_get_attachment_image($id, 'large');
$image = get_post($id);
$output .= '<span class="caption>'.$image->post_excerpt.'</span>';
$output .= .'</li> ';
}
echo $output;
$output = '';
?>
</ul>
Output your caption in whatever container you want, I just used a span as an example.
In your foreach:
$attachment_title = get_the_title($id)
should get you the title.
I have Joomla v3.x.x template override that creates an isotope layout with some category filters.
The problem I have is that if an ampersand (&) is put into the title of the category, that particular category filter will not show.
Is the a way to escape or allow the ampersand (&) to show and not break the filter for that particular category?
Code:
<?php
defined('_JEXEC') or die;
JHtml::_('bootstrap.tooltip');
if (count($this->children[$this->category->id]) > 0 && $this->maxLevel != 0) : ?>
<?php foreach ($this->children[$this->category->id] as $id => $child) : ?>
<?php if ($this->params->get('show_empty_categories') || $child->numitems || count($child->getChildren())) : ?>
<?php $data_name = $this->escape($child->title); ?>
<?php $data_option = str_replace(' ', '', $data_name); ?>
<li class="btn btn-primary"><?php echo $this->escape($child->title); ?></li>
<?php if (count($child->getChildren()) > 0) : ?>
<?php
$this->children[$child->id] = $child->getChildren();
$this->category = $child;
$this->maxLevel--;
if ($this->maxLevel != 0) :
echo $this->loadTemplate('children');
endif;
$this->category = $child->getParent();
$this->maxLevel++;
?>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif;
This is the particular line that create the filters from the category titles:
<li class="btn btn-primary"><?php echo $this->escape($child->title); ?></li>
The issue is most likely tied to the rendering of the filter select. Try changing the following line:
<?php $data_name = $this->escape($child->title); ?>
to:
<?php $data_name = htmlspecialchars($child->title); ?>
And see if that resolves the issue.
I am no expert in PHP, javascript and js; so I am hoping someone can help me in easy language terms. I have just developed my first wordpress site and changed the code immensely, using this forum - thanks heaps so far!
The site: http://www.heritageglass.com.au
My request: text (description of image in media library) hovering over image.
Just like this website or this plugin, I have found several questions on this site that refer to my issue but they haven't seemed to help or I don't exactly know where to place this as it's grabbing the_title and I want the_description. Is there such a term?
PHP code in portfolio.php template:
<div data-id="post-<?php the_ID(); ?>" data-type="<?php
$categories = get_the_category();
$count = count($categories);
$i=1;
foreach($categories as $category) {
echo str_replace('-', '', $category->slug);
if ($i<$count) echo ' '; $i++;} ?>" class="post-<?php the_ID(); ?>
<?php
$categories = get_the_category();
foreach($categories as $category) {
echo str_replace('-', '', $category->slug).' '; } ?> project portfolio-item-wrap">
<div class="portfolio-item">
<?php if ( has_post_thumbnail() ) { ?>
<a class="portfolio-item-img" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail( 'portfolio-image' ); ?></a>
<?php } ?>
<h4><?php the_title(); ?></h4>
<p>
<?php
$categories = get_the_category();
$temp = array();
foreach($categories as $category) {
if ($category->category_parent == 0) continue;
$temp[] = str_replace('-', '', $category->name);
}
echo implode(", ", $temp);
?>
</p>
</div>
</div>
I found this: Text over image using jquery and css
and added the script in the header.php. And used my .portfolio-item and .portfolio-item-img instead of .wrapper and .description - but that didn't do anything.
Hoping someone can lead me in the right direction?
Thanks!
Doing a search on the WordPress forums I found this from four years ago, not sure if it's what you need, but it might point you in the right direction.
$img_desc = $image->post_excerpt;
I think it will help you....
http://www.net-kit.com/10-jquery-caption-plugins/#
http://www.inwebson.com/jquery/jquery-image-hover-effects/
When editing a post, add two custome field, one for title, one for descritption.
Our code goes like this:
$dataType = '';
$divClass = '';
$categories = get_the_category();
$count = count($categories);
$i=1;
foreach($categories as $category) {
$dataType .= str_replace('-', '', $category->slug);
$divClass .= str_replace('-', '', $category->slug).' ';
if ($i<$count) $dataType.= ' ';
$i++;
}
$metaList = get_post_meta(get_the_ID());
$title = isset($metaList['title']) ? $metaList['title'] : '';
$description = isset($metaList['description']) ? $metaList['description'] : '';
// now we have title and description for the thumb!
?>
<div data-id="post-<?php the_ID(); ?>" data-type="<?php echo $dataType;?>"
class="post-<?php the_ID(); echo $divClass;?> project portfolio-item-wrap">
<div class="portfolio-item">
<?php if ( has_post_thumbnail() ) { ?>
<a class="portfolio-item-img" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail( 'portfolio-image' ); ?>
</a>
<?php } ?>
<h4><?php the_title(); ?></h4>
<p>
<?php
$temp = array();
foreach($categories as $category) {
if ($category->category_parent == 0) continue;
$temp[] = str_replace('-', '', $category->name);
}
echo implode(", ", $temp);
?>
</p>
</div>
</div>
I have found the answer after sooooo much research.
This is the answer: How do I get the featured image description from my wordpress page?
enter the the_post_thumbnail_caption(); within the span tags and set your span tags class in css.
done.
Thanks to all of you for your help!