How can I display estimated reading time in blog sidebar of wordpress? - blogs

$item = get_post($id);
$thumb = get_post_meta( $id, '_thumbnail_id', true );
?>
<div class="post-img post-single-img"><?php echo wp_get_attachment_image($thumb, ''); ?>
<div>
<span class="cat_name"><?= $cat; ?></span>
<h4><?php echo esc_html(single_post_title()); ?></h4>
<span calss="time-reading">
<i class="fa fa-clock-o"></i>
<?= do_shortcode('[rt_reading_time]') ?>
</span>
</div>
</div>
<?php endwhile;
?>
Here I could add the reading time in single blog page
but I couldn't find blog sidebar to add this short code.

Related

Showing random post from specific category on Wordpress

I’m using the below code to show two images (which I've set up with Advanced Custom Fields) from a random post from in the category ‘homepage’ on each refresh. It doesn’t appear to be working however and when I google it there are so many different ways to do it! Does anybody know if mine looks correct? I’m concerned I might be missing a closing tag or something minor.
<div class="feature-container">
<?php
$args = array(
'posts_per_page' => 1,
'orderby' => 'rand',
'category_name' => 'homepage',
);
$loop = new WP_Query($args);
while ($loop->have_posts()) : $loop->the_post();
if( have_rows('images') ):
while ( have_rows("images") ) :
the_row();
if ( get_sub_field( 'image' ) ): ?>
<a href="<?php echo $link['url']; ?>" target="<?php echo $link['target']; ?>">
<div class="image feature-item">
<div class="overlay" style="background-color:<?php the_sub_field('hover_colour');?>">
<div class="caption pm-big">
<?php
$link = get_sub_field('link');
if( $link ): ?>
<?php echo $link['title']; ?>
<?php endif; ?>
</div>
</div>
<img src="<?php the_sub_field('image');?>" alt="" style="display: block;">
</div>
</a>
<?php else: ?>
<!-- no images found -->
<?php endif;
endwhile;
else :
// no images found
endif;
endwhile; ?>
</div>

magento homepage and other pages headers are different

In magento backend, I though no matter homepage or other pages should use the same header file. However, when I change the logo picture for header in backend, only homepage's header picture was changed successfully, other pages are not showing the picture correctly.
Basically what I did is, there are two rows in header, so I put half of the logo on left of the first row and and the other half of the logo on left of the second row, so it seems like a bigger logo.
homepage pic
what it should be
catalog and product view page
in catalog and product view page(bottom part of the logo is not changed)
in secondary catalog page, the upper part of the logo is missing, and bottom part of the logo is not changed.
code path: design/frontend/theme/template/page/html/header.phtml
<div class="header-top">
<img src="media/images/logoUp.jpg" style="width:500px;height:60px;">
<div class="header-top-search-wrapper">
<?php echo $this->getChildHtml('topSearch') ?>
<?php /*TODO: ?><a class="advanced-search-link" href="<?php echo Mage::getURL('') ?>catalogsearch/advanced/"><?php print $this->__('Advanced Search') ?></a><?php */?>
</div>
<?php echo $this->getChildHtml('currency') ?>
<?php echo $this->getChildHtml('store_language') ?>
<?php if ($tmp_html = $this->getChildHtml('i_block_header_top_help')): ?> <?php //Predefined CMS block ?>
<div class="header-top-help-wrapper"><?php echo $tmp_html; ?></div>
<?php endif; ?>
<?php if ($tmp_html = $this->getChildHtml('i_block_header_top_links')): ?> <?php //Predefined CMS block ?>
<div class="header-top-links-wrapper"><?php echo $tmp_html; ?></div>
<?php endif; ?>
</div>
//<?php if ($this->getIsHomePage()):?>
<h1 class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><img src="media/images/logoDown.jpg" style="width:500px;height:60px;"></h1>
//<?php else:?>
// <strong><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" />
// <?php endif?>
<div class="header-left">
<?php if ($tmp_html = $this->getChildHtml('i_block_header_contact')): ?> <?php //Predefined CMS block ?>
<div class="header-contact-wrapper"><?php echo $tmp_html; ?></div>
<?php endif; ?>
<?php if ($tmp_html = $this->getChildHtml('i_block_header_banner')): ?> <?php //Predefined CMS block ?>
<div class="header-banner-wrapper"><?php echo $tmp_html; ?></div>
<?php endif; ?>
</div> <!-- end: header-left -->
<div class="header-right">
<div class="header-right-secondary">
<p class="welcome-msg"><?php echo $this->getWelcome() ?> <?php echo $this->getAdditionalHtml() ?></p>
<?php echo $this->getChildHtml('topContainer'); ?>
</div>
<div class="user-menu">
<?php // Show custom link, if enabled ?>
<?php if ($themeHelper->getCfg('header/links_custom_link_enabled')): ?>
<?php
$_customLinkPath = $themeHelper->getCfg('header/links_custom_link_path');
$_customLinkAnchor = $themeHelper->getCfg('header/links_custom_link_anchor');
$_customLinkTitle = $themeHelper->getCfg('header/links_custom_link_title');
?>
<ul>
<li class="user-menu-item user-menu-custom">
<?php echo $_customLinkAnchor; ?>
</li>
</ul>
<?php endif?>
<?php echo $this->getChildHtml('topLinks') ?>
<?php // If customer is not logged in: show "Sign Up" link, if enabled ?>
<?php if (Mage::getSingleton('customer/session')->isLoggedIn() == false): ?>
<?php if ($themeHelper->getCfg('header/links_signup_enabled')): ?>
<ul>
<li class="user-menu-item user-menu-signup">
<?php echo $this->__('Sign Up') ?>
</li>
</ul>
<?php endif?>
<?php endif?>
<ul>
<li id="mini-cart" class="user-menu-item user-menu-cart">
<?php echo $this->getChildHtml('cart_sidebar') ?>
</li>
</ul>
</div>
</div> <!-- end: header-right -->
The above code is for header's part.
I'm quite confused, shouldn't all pages use the same header file? why they appear differently?
Thank you
I know the problem now.
The reason why secondary categories can't get the image is because the url is hostname/categoryName/image.jpg
So the url is not valid here anymore. Should have use dynamic url here.

how i can do featured post slider set category based?

my featured post slider set as a tags. i want it set category base. how i can do it?my site http://techgajot.com
my featured post slider html code?
<script type="text/javascript">
//<![CDATA[
jQuery(window).load(function() {
jQuery('#featured').flexslider({
slideshowSpeed: 6000,
directionNav:false,
pauseOnHover:true,
manualControls: '.flexslide-custom-controls li a',
controlsContainer: '.container'
});
});
//]]>
</script>
<div class="featured">
<div class="container">
<div id="featured" class="flexslider">
<ul class="slides">
<?php
$count = 1;
$featurecount = get_option('solostream_features_number');
$my_query = new WP_Query("tag=featured&showposts=$featurecount");
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate[] = $post->ID; ?>
<li id="narrow-feature-post-<?php echo $count; ?>"<?php echo solostream_featureclass(); ?>>
<div class="slide-container clearfix">
<?php if ( get_post_meta( $post->ID, 'video_embed', true ) ) { ?>
<div class="feature-video">
<div class="video"><?php echo get_post_meta( $post->ID, 'video_embed', true ); ?></div>
</div>
<?php } else { ?>
<div class="feature-image">
<?php solostream_feature_image(); ?>
</div>
<?php } ?>
<div class="flex-caption">
<div class="excerpt">
<h2 class="post-title"><?php the_title(); ?></h2>
<?php if ( 'post' == get_post_type() ) { ?>
<?php include (TEMPLATEPATH . "/postinfo.php"); ?>
<?php } ?>
<?php the_excerpt(); ?>
<p class="readmore"><a class="more-link" href="<?php the_permalink() ?>" rel="nofollow" title="<?php _e("Permanent Link to", "solostream"); ?> <?php the_title(); ?>"><?php _e("সম্পূর্ন অংশ", "solostream"); ?></a></p>
</div>
</div>
</div>
</li>
<?php $count = $count + 1 ?>
<?php endwhile; ?>
</ul>
</div>
<div class="controls-container clearfix">
<ul class="flexslide-custom-controls clearfix">
<?php
$count = 1;
$featurecount = get_option('solostream_features_number');
$my_query = new WP_Query("tag=featured&showposts=$featurecount");
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate[] = $post->ID; ?>
<li><?php echo $count; ?></li>
<?php $count = $count + 1 ?>
<?php endwhile; ?>
</ul>
</div>
</div>
</div>
how i can do it. my featured post slider tags now= featured. when i put "featured" any post tags option then it show featured post. now i want it like category base. i select here any category.then that category all post show featured post.
If I understood you right ( difficult ike #dda noted ) Changing this line :
$my_query = new WP_Query("tag=featured&showposts=$featurecount");
to
$my_query = new WP_Query("category_name=featured&showposts=$featurecount");
Will make the same query from tag to category using name ..
If you use ID , then
$query = new WP_Query( 'cat=2,7,23,35' );
Or all posts that share this category :
$query = new WP_Query( 'category_name=staff' );
Read more HERE ON THE CODEX

display blog posts on static page

I am rather new to Wordpress and have a question. I have created my own theme, which all seems to work fine. But, I am having one issue. I want to create my blog page (with all the posts) on a page other than my home page. So, in my theme folder, I created a page template called blog.php:
<?php
/*
Template Name: blog
*/
?>
<?php get_header(); ?>
<table id="about-table" >
<tr>
<td colspan="7">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php the_title(); ?>
<?php the_author(); ?>
<?php the_time("jS F"); ?>
<?php comments_number("0","1","%"); ?>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>
</td>
</tr>
</table>
<?php get_footer(); ?>
Then, I created a page in wordpress called "blog" as well, in the "pages" section in the dashboard. I then assigned its template to the above "blog" template. The problem is, though, that the code does not work as it should. Instead of showing me the titles, comments, etc of the posts, it displays some other info. On the other hand, if i just copy this:
<table id="about-table" >
<tr>
<td colspan="7">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php the_title(); ?>
<?php the_author(); ?>
<?php the_time("jS F"); ?>
<?php comments_number("0","1","%"); ?>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>
</td>
</tr>
</table>
to my index page, it works fine. So, how do I display all my post info on a page other than the home page?
I wanted to provide you with a simpler loop as a second option. If you use this and set Reading settings to the specific blog page this works well:
<?
/*
Template Name: Blog Template Example
*/
?>
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="next-posts"><?php next_posts_link(); ?></div>
<div class="prev-posts"><?php previous_posts_link(); ?></div>
</div>
<?php else : ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1>Not Found</h1>
</div>
<?php endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
How about you do something like this:
blog-template.php:
<?php/*
Template Name: Blog Page
*/
?>
<?php get_header(); ?>
<?php get_template_part( 'layout-page', 'blog' );?>
<?php get_footer(); ?>
layout-page-blog.php:
<?php
the_post();
$title = get_the_title();
$baselink = get_permalink();
$category = get_field('category_blog');
if( !empty($category) ){
$post_per_page = get_option('posts_per_page');
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$categoryID = get_category_id($category);
$total = get_post_count(array($categoryID));
$the_query = new WP_Query("posts_per_page={$post_per_page}&cat= {$categoryID}&paged={$paged}");
?>
<div id="wrapper">
<div id="content">
<h1 class="title"><?php echo $title; ?></h1>
<div class="content-middle">
<div class="node">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h3><?php the_title(); ?></h3>
<div class="content">
<?php echo content(150); ?>
</div>
<div class="read-more">Read more</div>
<?php endwhile; ?>
<br/><br/>
<div class="wp-paginate">
<?php
wp_reset_query();
echo paginate_links( array(
'base' => $baselink.'%_%',
'total' => ceil($total/$post_per_page),
'current' => $paged,
));
?>
</div>
</div>
</div>
</div> <!-- end content -->
<div style="clear:both"></div>
</div>
<?php
}
?>
This could all be in one file, or you can use it in two pieces as I have written it.
EDIT:
Sorry I have it set to also grab the images from the post. I think this is the functions code you need:
function get_images_by_cat($id){
$limit = 1000;
$the_query = new WP_Query("posts_per_page={$limit}&cat={$id}");
$arr = array();
while ( $the_query->have_posts() ) {
$the_query->the_post();
$title = get_the_title();
$image_src = get_field('banner_image');
$image_link = get_field('banner_link');
$arr[] = array(
"title" => $title,
"link" => $image_link,
"image" => $image_src,
);
}
wp_reset_query();
return $arr;
}

Wordpress category, get all its posts

I am currently finish of my theme for a wordpress website that I am building, I am having a problem getting my categories to work though.
I am lost as to how I can loop through the current category if I am at a URL of say "/category/category-name" how would I loop the posts that belong to the category "category name".
I I do the following on my template
<p>Category: <?php single_cat_title(); ?></p> I get the following output
Category Name
So how do I loop through that categories posts?
Category.php
<?php get_header(); ?>
<article class="content">
<section class="top">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</section>
<section class="middle">
</section>
</article>
<?php get_footer(); ?>
page-news.php
<?php get_header(); ?>
<article id="content">
<section class="top">
<?php query_posts('post_type=news'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<section class="news">
<?php the_post_thumbnail(); ?>
<h2><?php echo strtolower(the_title()); ?></h2>
<span class="posted"><?php the_date("l jS M Y"); ?></span>
<?php
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
?>
<p><?php echo substr(strip_tags($content), 0, 400).'…' ; ?>Read More</p>
<p class="tags">
<strong>Categories:</strong>
<?php
$post_categories = wp_get_post_categories( $post->ID );
$cats = array();
foreach($post_categories as $c){
$cat = get_category( $c );
$cats[] = array( 'name' => $cat->name, 'slug' => $cat->slug );
}
?>
<?php foreach($cats as $k => $v) : ?>
<?php echo $cats[$k]['name']; ?>
<?php endforeach; ?>
</p>
<p class="tags">
<strong>Tags: </strong>
<?php $tags = wp_get_post_tags($post->ID); ?>
<?php foreach ($tags as $tag) : ?>
<?php echo $tag->name; ?>
<?php endforeach; ?>
</p>
</section>
<?php endwhile; endif; ?>
<?php get_sidebar('news'); ?>
</section>
<section class="middle">
</section>
</article>
So page-news.php are where my news article reside, and the user can get the category using the link generated by <?php echo $cats[$k]['name']; ?>
I don't think you're outputting anything in category.php based on the code above. the_post() doesn't echo anything. It just puts the next record into $post. Try this...
<?php
get_header();
$cat = get_category(get_query_var("cat"));
var_dump($cat); //make sure that there really is a valid category and it's the right one
?>
<h1 class="page-title"><?php echo $cat->name?></h1>
<?php
if (have_posts()) {
while (have_posts()){
the_post();
<h2><?php the_title()?></h2>
<?php the_content()?>
<?php
}
} else {
?>
<p>No posts found!</p>
<?php
}
?>
<?php
get_footer();
?>
In page-news.php you should probably consider using the_category() to echo out the category links rather than constructing the links yourself -- that way you'll know that the links are valid....
<p class="tags"><?php the_category()?></p>
You can use this function inside your page template to loop the posts