Why does not go to the product page? - wordpress

Brought the goods, when you click on the product, does not go into the card of this product, the link is formed correctly, but the content of the page does not change, that's how I brought the product:
<?php get_header(); ?>
<div class="content-about">
<div class="wrap">
<div class="wrap-product">
<h2 class="about-title">Мои товары</h2>
<div class="product-list">
<?php
$custom_query = new WP_Query( array( 'post_type' => 'product'));
if ($custom_query->have_posts()) : while ($custom_query->have_posts()) : $custom_query->the_post();
global $product;
?>
<div class="item-product">
<div class="img-prod">
<?php the_post_thumbnail(); ?>
</div>
<div class="name-prod"><?php the_title(); ?></div>
<div class="rating-prod"></div>
<div class="price-prod"><?php echo $product->get_price_html(); ?></div>
<div class="add-cart">
<?php woocommerce_template_loop_add_to_cart(); ?>
</div>
</div>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
<?php /*woocommerce_content();*/ ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
When you click on the name of the product does not go to this product:
enter image description here

Related

Custom template for category WordPress

Hello I'm new in WordPress custom templates. Can anybody tell me how I can load a different template for a category.
Here is the index.php file
<?php
/**
* The main template file
*
* No comment for now
*
* #package WordPress
* #subpackage site
* #since site
*/
get_header(); ?>
<?php
$strFr='Featured';
$strFinancial='Financial Reports';
$strResearch='Research';
?>
<div id="page-body" role="main">
<div class="container">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12 SearchTop">
<form role="search" method="get" id="searchform" class="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-search"></i></div>
<input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" class="form-control customsearchfiled" placeholder="Search of anything related to Site" />
</div>
</form>
</div><!-- SearchTop -->
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="col-md-12 col-sm-12 col-xs-12 mb20 no-gutter">
<div class="col-md-12 col-sm-12 col-xs-12 no-gutter">
<?php if (have_posts()) : ?>
<?php /* Start the Loop */ ?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('content', get_post_format()); ?>
<?php endwhile; ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<?php if (current_user_can('edit_posts')) :
// Show a different message to a logged-in user who can add posts.
?>
<header class="entry-header">
<h1 class="entry-title mt20"><?php _e('No posts to display', 'twentytwelve'); ?></h1>
</header>
<!--<div class="entry-content">
<p><?php //printf(__('Ready to publish your first post? Get started here.', 'twentytwelve'), admin_url('post-new.php')); ?></p>
</div> .entry-content -->
<?php else :
// Show the default message to everyone else.
?>
<header class="entry-header">
<h1 class="entry-title"><?php _e('Nothing Found', 'twentytwelve'); ?></h1>
</header>
<div class="entry-content">
<p><?php _e('Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve'); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
<?php endif; // end current_user_can() check ?>
</article><!-- #post-0 -->
<?php endif; // end have_posts() check ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
As far I know the index file is calling content php file that shows the post layout but don't know how to do this. Tried a lot of things but only get php error. I don't know php syntax much
<?php
/**
* Custom template with better structure than WP default.
*
* Used for both single and index/archive/search.
*
* #package WordPress
* #subpackage site
* #since Site 1.0
*/
# for one post
if (is_single()) {
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php if(function_exists('pf_show_link')){echo pf_show_link();} ?>
<p class="text-center topcategory">
<?php foreach((get_the_category()) as $category) {
echo $category->cat_name . ' ';
}
?>
</p>
<h1 class="entry-title"><?php the_title(); ?></h1>
<p class="postmetadown">By :<span class="bluecolor"><?php the_author(); ?></span> | <span><?php the_date() ?></span></p>
</header>
<div class="entry-content col-md-9 col-sm-9 col-xs-12">
<?php the_content(__('Continue reading <span class="meta-nav">→</span>', 'twentytwelve')); ?>
<?php wp_link_pages(array('before' => '<div class="page-links">' . __('Pages:', 'twentytwelve'), 'after' => '</div>')); ?>
</div>
<div class="col-md-3 col-sm-3 col-xs-12">
<?php get_sidebar(); ?>
</div>
<?php if (comments_open()) : ?>
<!--<div id="disqus_thread"></div>

<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'site'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function () {
var dsq = document.createElement('script');
dsq.type =
'text/javascript';
dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')
[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/? ref_noscript">comments powered
by Disqus.</a></noscript>
comments powered by <span class="logo- disqus">Disqus</span>-->
<?php endif; ?>
<footer class="entry-meta col-md-12">
<?php if ($googlePlusAcc = get_the_author_meta('googleplus')) { ?>
<?php hr_single_entry_meta(); ?>
<?php } else { ?>
<?php twentytwelve_entry_meta(); ?>
<?php } ?>
<?php edit_post_link(__('Edit', 'twentytwelve'), '<span class="edit-link">', '</span>'); ?>
<?php if (is_singular() && get_the_author_meta('description') && is_multi_author()) : // If a user has filled out their description and this is a multi-author blog, show a bio on their entries. ?>
<div class="author-info">
<div class="author-avatar">
<?php
/** This filter is documented in author.php */
$author_bio_avatar_size = apply_filters('twentytwelve_author_bio_avatar_size', 68);
echo get_avatar(get_the_author_meta('user_email'), $author_bio_avatar_size);
?>
</div>
<!-- .author-avatar -->
<div class="author-description">
<h2><?php printf(__('About %s', 'twentytwelve'), get_the_author()); ?></h2>
<p><?php the_author_meta('description'); ?></p>
<div class="author-link">
<a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>"
rel="author">
<?php printf(__('View all posts by %s <span class="meta-nav">→</span>', 'twentytwelve'), get_the_author()); ?>
</a>
</div>
</div>
</div>
<?php endif; ?>
</footer>
</article>
<?php
#for listing page
} else {
$category = get_the_category();
if (!empty($category))
$category = $category[0];
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php //if (is_sticky() && is_home() && !is_paged()) : ?>
<!--<div class="featured-post">
<?php //_e('Featured post', 'twentytwelve'); ?>
</div>-->
<?php //endif; ?>
<div class="col-md-4 col-sm-4 col-xs-12 categoryimg no-gutter">
<?php if (has_post_thumbnail()) { ?>
<div class="post-thumbnal-wrapper-multiple">
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
</div>
<div class="col-md-8 col-sm-8 col-xs-12 categoryContent">
<header class="entry-header">
<h1 class="entry-title">
<?php the_title(); ?>
</h1>
</header>
<?php if (is_search()) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div>
<?php else : ?>
<div class="entry-content">
<?php the_excerpt_more(); ?>
</div>
<?php endif; ?>
<div class="col-md-12">
<footer class="entry-meta">
<?php twentytwelve_entry_meta(); ?>
<?php edit_post_link(__('Edit', 'twentytwelve'), '<span class="edit-link">', '</span>'); ?>
</footer>
</div>
</div><!-- categoryContent -->
</article>
<div class="clearfix"></div>
<?php
}
If you want a template for the category page, see https://codex.wordpress.org/Category_Templates. If you want a different template for the content, based on the category, you could use (in your content.php)
<?php if (is_category('Category A')) : ?>
<p>This is the text to describe category A</p>
<?php elseif (is_category('Category B')) : ?>
<p>This is the text to describe category B</p>
<?php else : ?>
<p>This is some generic text to describe all other category pages,
I could be left blank</p>
<?php endif; ?>
If there's a lot of difference between categories, I would place this in index.php, and create different templates for every category
Check out this page Template Hierachy. Basically if you want to target a specific category you create a file like so category-{slug}.php {slug} being the category slug you want to target.
I suggest you to read about Wordpress Template Hierarchy in https://developer.wordpress.org/themes/basics/template-hierarchy/
To answer your question, you need to create a category-{id}.php or category-{slug}.php file. in your theme folder (Choose only one)
id = your category ID
slug = your category slug
After creating the file, then you can put your custom code if you want.
Add your code inside archive.php which will list all the posts in the category and add the detail page template inside single.php .
https://codex.wordpress.org/Category_Templates

not getting the content part in post only thumbnail and title is display

<div class="row" id="content">
<?php
$args = array( 'posts_per_page' =>3, 'category' =>3 );
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) :
?>
<div class="col-md-8">
<h2 style="text-transform:uppercase;font-size: 19px;font-weight:bold;"><?php the_title();?></h2>
<div class="col-md-6">
<div class="thumbnails">
<?php the_post_thumbnail('full');?>
</div>
</div>
<div class="col-md-6">
<?php echo the_content(); ?>
<?php echo the_excerpt(); ?>
</div>
<div class="bar3"></div>
</div>
<?php endforeach; ?>
<div class="col-md-4">
<?php get_sidebar(); ?>
</div>
</div>
This is my code .i did not get the content from the the post the thumbnail and the title are display ..please anybody help me to solve the problem.sorry for my poor english.
Replace your code with this...
<div class="row" id="content">
<?php
$args = array( 'posts_per_page' =>3, 'category' =>3 );
$rand_posts = new WP_Query( $args );
if ( $rand_posts->have_posts() ) :
while ( $rand_posts->have_posts() ) : $rand_posts->the_post();
?>
<div class="col-md-8">
<h2 style="text-transform:uppercase;font-size: 19px;font-weight:bold;"><?php the_title();?></h2>
<div class="col-md-6">
<div class="thumbnails">
<?php the_post_thumbnail('full');?>
</div>
</div>
<div class="col-md-6">
<?php the_content(); ?>
<?php the_excerpt(); ?>
</div>
<div class="bar3"></div>
</div>
<?php
endwhile;
endif;
wp_reset_query();
?>
<div class="col-md-4">
<?php get_sidebar(); ?>
</div>
</div>
I hope it will work...
Try this:
<div class="row" id="content">
<?php
$args = array( 'posts_per_page' =>3, 'category' =>3 );
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : setup_postdata($post);
?>
<div class="col-md-8">
<h2 style="text-transform:uppercase;font-size: 19px;font-weight:bold;"><?php the_title();?></h2>
<div class="col-md-6">
<div class="thumbnails">
<?php the_post_thumbnail('full');?>
</div>
</div>
<div class="col-md-6">
<?php the_content(); ?>
<?php the_excerpt(); ?>
</div>
<div class="bar3"></div>
</div>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<div class="col-md-4">
<?php get_sidebar(); ?>
</div>
</div>
You are missing setup_postdata( $post );
Also when you use the_content(); you don't need to add "echo", same with the other queries start with "the_"
Please check the get_posts query here : http://codex.wordpress.org/Template_Tags/get_posts
Cheers!

404 page errors with custom post type pagination in wordpress

This is my events template page in wordpress that displays 2 events at a time, but when you click on the previous posts link to show older event posts I keep getting this 404 page error in my custom post type. Any help would be appreciated. Here's my complete code on my template page:
<?php
/*
Template Name: Events Page
*/
?>
<?php get_header(); ?>
<div id="wrapper">
<section id="main-content">
<div class="signup">
Sign up for our mailing list
</div>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article>
<?php the_content(); ?>
</article>
<?php endwhile; endif; ?>
<section id="event-listings">
<?php
$args = array(
'post_type' => 'events',
'posts_per_page' => 2,
'paged' => get_query_var('paged')
);
$global_posts_query = new WP_Query($args);
?>
<?php if ($global_posts_query->have_posts()) : while ($global_posts_query->have_posts()) : $global_posts_query->the_post(); ?>
<article class="post">
<div class="date">
<p><?php the_field('date'); ?><br><span class="year"><?php the_field('year'); ?></span></p>
</div>
<h2><?php the_field('headline'); ?></h2>
<p class="location"><?php the_field('location'); ?> ♥ <?php the_field('time'); ?></p>
<p class="coordinator">Created by: <span class="name"><?php the_field('author'); ?> on <time datetime="<?php echo date(DATE_W3C); ?>" pubdate class="updated"><?php the_time('F jS, Y') ?></time></span></p>
<p class="about-content"><?php the_field('about'); ?></p>
</article>
<?php endwhile; else: ?>
<p>No events posted at this time.</p>
<?php endif; ?>
<div class="navigation">
<div class="next-posts"><?php next_posts_link('« Older Entries', $global_posts_query->max_num_pages) ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Entries »', $global_posts_query->max_num_pages) ?></div>
</div>
</section>
</section><!--End Main Content-->
</div><!--End Wrapper-->
<?php get_footer(); ?>

What would make the_date function in wordpress only show up on random posts

I am working on a website for a client and I specifically needed to modify a given wordpress template. The template uses the get_template_part function to call the content. So for the loop on the index page it should be showing the_date under the header but for some reason it is showing up on some of the posts and not all.
index.php
<?php get_header(); ?>
<!-- Content -->
<div class="container contentarea">
<div class="row">
<div class="column-content">
<div id="content" role="main">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<!-- Call content.php -->
<?php get_template_part( 'content' ); ?>
<?php endwhile; ?>
<div class="clearfix"></div>
<div class="paging">
<?php if(function_exists('lugada_kriesi_pagination')) : lugada_kriesi_pagination(); else: ?>
<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link(__( '<span class="meta-nav">«</span> Older posts', 'newzeo' )) ?></div>
<div class="nav-next"><?php previous_posts_link(__( 'Newer posts <span class="meta-nav">»</span>', 'newzeo' )) ?></div>
</div>
<?php } endif; ?>
</div>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title">Nothing Found</h1>
</header>
<div class="entry-content">
<p>Sorry, we can't find post you request. Please try search for a related post.</p>
</div>
</article>
<?php endif; ?>
</div> <!-- #content -->
</div> <!-- .column-content -->
<div class="column-sidebar nomargin">
<?php get_sidebar(); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
content.php
<div class="content-box bucket">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?> itemscope itemtype="http://schema.org/Article" >
<h2 class="entry-header">
<div class="entry-meta clearfix" >
<!-- Sticky post -->
<?php if (is_sticky()) : ?>
<div class="sticky-label"></div>
<?php endif; ?>
<!-- Post title -->
<?php the_title(); ?>
</div> <!-- .entry-meta -->
</h2> <!-- .header -->
<!-- Content -->
<div class="entry-content clearfix" itemprop="description">
<?php the_date('','<p><strong>','</strong></p>',true); ?>
<?php the_content('Continue reading'); ?>
<div class="clearfix"></div>
<?php wp_link_pages( array('before' => '<div class="page-link"> <span> Pages: </span>', 'after' => '</div>')); ?>
</div>
<div class="entry-meta footerbox" >
<!-- Category -->
<span class="cat-links">
<span>Posted in</span>
<?php echo get_the_category_list(', '); ?>
</span>
<!-- If single & have tag -->
<!-- Tag -->
<?php if ( is_single() ): if (has_tag()) : ?>
<span class="sep"> | </span>
<span class="tag-links">
<span>Tagged</span>
<?php echo get_the_tag_list('',', ',''); ?>
</span>
<?php endif; ?>
<?php edit_post_link('Edit', '<span class="edit-link"><span class="sep"> | </span>', '</span>'); ?>
<div class="socialshareboxsingle clearfix">
Share this post, let the world know <?php lugada_social_button();?>
</div>
<?php endif; ?>
</div> <!-- .footer -->
</div> <!-- article -->
</div>
<hr class="post-shadow"/>
<!-- If its single, a user has filled out their description and this is a multi-author blog, show a bio on their entries -->
<?php if ( is_single() ) : ?>
<?php if ( get_the_author_meta( 'description' ) && ( ! function_exists( 'is_multi_author' ) || is_multi_author() ) ) : ?>
<div class="content-box">
<div id="author-info">
<div id="author-avatar">
<?php echo get_avatar( get_the_author_meta( 'user_email' ), 80 ); ?>
</div>
<div id="author-description">
<h2 >About <?php echo get_the_author(); ?></h2>
<?php the_author_meta( 'description' ); ?>
</div>
<div id="author-link" class="clearfix">
<?php if ( get_the_author_meta( 'user_url' )) : ?>
<span>Add my circles on Google+ : </span>
<span itemprop="author"><?php echo get_the_author(); ?></span>
<br/>
<?php endif; ?>
<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">
View all posts by <?php echo get_the_author(); ?><span class="meta-nav">→</span>
</a>
</div>
</div>
</div>
<hr class="post-shadow"/>
<?php endif; endif; ?>
They're not random posts. Read the Codex:
When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or get_the_date() (since 3.0) with a date-specific format string.
Change:
<?php the_date('','<p><strong>','</strong></p>',true); ?>
To:
<p><strong><?php the_time('F j, Y'); ?></strong></p>

How to make Wordpress show only one post on the front page with comments, and comment form?

I did the following to display a single post in my home page:
home.php:
<?php
get_header();
query_posts('posts_per_page=1'); //returns only the front page
?>
<div id="content">
<?php
/* Run the loop to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-index.php and that will be used instead.
*/
get_template_part( 'loop', 'index' );
?>
</div>
<div id="sidebar">
<?php get_sidebar(); ?>
</div>
<div id="footer">
<?php get_footer(); ?>
But I still ahave to click Comments in order to see the comments and the form to leave a comment. How can I automatically show immediately?
Load the comments template using <?php comments_template(); ?> - that'll display all comments for the current post.
<?php get_header(); ?>
<div class="blog">
<section>
<div class="container">
<div class="row">
<div class="blog-sidebar">
<?php get_sidebar(); ?>
</div>
<div class="span8">
<?php $articles = new WP_Query(array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 1
));?>
<?php while ($articles->have_posts()): $articles->the_post(); ?>
<article id="post-<?php the_ID(); ?>" role="article">
<header>
<?php the_post_thumbnail( 'wpbs-featured' ); ?>
<section class="post_content clearfix" >
<?php the_content(); ?>
</section>
</article>
<?php endwhile; ?>
<?php comments_template('',true); ?>
</div>
</div>
</div>
</section>
</div>
<?php get_footer(); ?>

Resources