Wordpress/woocommerce css error - wordpress

I've followed: https://wordpress.stackexchange.com/questions/67247/how-to-display-product-specific-to-a-category-with-woocommerce-plugin
This code is placed in CustomPageT1, and has this code:
<?php /* Template Name: CustomPageT1 */
get_header(); ?>
<div id="content" class="site-content container">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<ul class="products">
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 4, 'product_cat' => 'skydd-mot-djur', 'orderby' => 'rand' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<li class="post-18 product type-product status-publish product_cat-skydd-mot-manniskor first instock shipping-taxable purchasable product-type-simple" style="width: 25%;float:left">
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>" class="woocommerce-LoopProduct-link">
<?php woocommerce_show_product_sale_flash( $post, $product ); ?>
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" class="woocommerce-placeholder wp-post-image" height="300px" />'; ?>
<h3><?php the_title(); ?></h3>
<span class="price"><?php echo $product->get_price_html(); ?></span>
</a>
<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
</li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul><!--/.products-->
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
This page is created by adding /* Template Name: CustomPageT1 */ and then add it from the "add page" function. Then copy-paste from page.php into this file.
I can edit and all, the logo, menu, and some design works great. Without the Woocommerce one, in style.css I can get the css. But from the theme it doesnt fetch the css.
Which means that it looks bad, without the css.
Anyone knows why?

Because you have created a page without a link to the header file.
By creating a page with this code
/* Template Name: CustomPageT1 */
means create a page with template CustomPageT1.
The new page has no means to connect to the CSS file.
create the header-CustomPageT1.php file with the link to the CSS file andd upload to it's corresponding theme folder.
Also change this code: get_header() to get_header(CustomPageT1)

Related

how to add pagination in wordpress

I have posts in different custom taxonomies. I need to display posts for one taxonomy in a page. Now I'm getting the all the posts in all taxonomies in a single page. I have a foreach loop for taxonomy and inside the loop all the posts corresponding to that taxonomy is displaying through post method.I have never used pagination before. How can I add pagination in this case?
I am enclosing my code below
<div class="main">
<section class="brands-sec product-sec">
<div class="container">
<?php
$siteurl = home_url('/');
$tax = 'product'; // slug of taxonomy
$terms = get_terms($tax);
foreach ($terms as $term) {
$id = $term->term_id;
$slug = $term->slug;
$description = $term->description;
$image_url = z_taxonomy_image_url( $id, NULL, TRUE ); // category image display
$link = "<a href='$siteurl?$tax=$slug' ><h1> $term->name </h1></a>";
echo '<img src="' . $image_url . '">'; ?>
<div class="col-md-8 pull-right col-sm-10 pull-right col-xs-12 brnd prdct">
<img src="<?php echo $image_url ; ?>" class="img-responsive pdt-logo" alt="loyd"/>
<div class="brand-logos pdt">
<p><?php echo $description ; ?></p>
<h4>Product</h4>
<?php $args = array("posts_per_page" => "-1", "product"=>$slug ,"post_type" => "products" );
$posts = get_posts($args);
foreach($posts as $data){
$thumb = wp_get_attachment_url( get_post_thumbnail_id($data ->ID) );
$custom_fonts = get_post_custom($data->ID);$custom_fonts_key= $custom_fonts['category'];$custom_fonts_array = $custom_fonts_key[0]; ?>
<div class="row mb40">
<div class="col-md-4 col-sm-4 col-xs-12 brand-single product-single">
<img src="<?php echo $thumb; ?>" class="img-responsive" alt="allegro products"/>
<h5><?php echo $data->post_title; ?></h5>
<p><?php echo $data->post_content; ?></p>
</div>
<div class="col-md-8 col-sm-8 col-xs-12 brand-single product-detail">
<ul class="products">
<?php
$attachments = new Attachments( 'my_attachments',$data->ID ); /* pass the instance name */ ?>
<?php if( $attachments->exist() ) : ?>
<?php while( $attachments->get() ) : ?>
<li><img src="<?php echo $attachments->url(); ?>" class="img-responsive" alt="allegro products"/></li>
<?php endwhile; ?>
<?php endif; ?>
</ul>
</div>
</div>
<?php } ?>
</div><!--end brand-logos-->
</div><!--end brnd-->
<?php } ?>
</div>
Here product is custom taxonomy . In that there are more than one terms say loyd,Nycofee,.... In Both these terms there are more than one posts. I need to display posts in loyd in one page and ncofee in next page. How to add pagination in this case?
Try this:
You have the post_per_page to be -1
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array("posts_per_page" => "-1", "product"=>$slug ,"post_type" => "products" );
change it to the number you would like. and add to the end
'paged' => $paged
before Ending the PHP here
</div>
<?php } ?>
</div><!--end brand-logos-->
Add
<?php if (function_exists('wp_pagenavi')) wp_pagenavi(array('query' => $args )); ?>
<?php wp_reset_postdata(); ?>
Here is the basic pagination for wordpress
<?php if ( have_posts() ) : ?>
<!-- Add the pagination functions here. -->
<!-- Start of the main loop. -->
<?php while ( have_posts() ) : the_post(); ?>
<!-- the rest of your theme's main loop -->
<?php endwhile; ?>
<!-- End of the main loop -->
<!-- Add the pagination functions here. -->
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
Soruce: https://codex.wordpress.org/Pagination "Example Loop with Pagination"
If it still show the full list.
Try this: http://callmenick.com/post/custom-wordpress-loop-with-pagination

How to properly use the <more> tag on pages in WordPress

According to the forum in this article, fixing the read more tag problem, Mark Pasay has the same difficulty as I do in using this code snippet as a solution. <?php global $more; $more = 0; ?> But the author does not elaborate on how to use this properly. I am using a page template that is called in the WP admin. The <!--more--> is added in the text editor. Here is the code for the page template.
/*
Template Name: new template
*/
get_header(); ?>
<div id="container">
<div id="content" role="main">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( is_front_page() ) { ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php } else { ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php } ?>
<div class="entry-content">
<?php global $more; $more = 0; ?>
<?php the_content('read more'); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-content -->
</div><!-- #post-## -->
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #container -->
The tag shows up in the browser but when clicked, it does not show the full post.
On click, the URL changes from localhost/domain.com/page/ to localhost/domain.com/page/#more-481.
The author explains that this is not being used properly because it is calling content of pageX from pageX. "This trick will only work when you are trying to display excerpts of pageX on pageY." Fair enough, but how is this done?

How do I display the second and third most recent posts from a category in WordPress

I am displaying previews of the three most recent news articles on my homepage. The most recent post will be displayed in a different format to the second and third most recent posts.
I am currently displaying all three the same with the following code
<?php query_posts('cat=2 && showposts=3');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="col-xs-12 col-sm-4">
<div class="column">
<div class="news-article">
<p class="news-date"><?php the_time( get_option( 'date_format' ) ); ?></p>
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('full', array( 'class' => 'img-responsive img-rounded news-img' )); } ?>
<p class="news-headline"><?php the_title(); ?></p>
</a>
<p><?php the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>">
<p class="pull-right">Read more...</p>
</a>
<span class="clearfix"></span>
</div>
</div>
</div>
<?php
endwhile;
endif;
?>
How can I add another loop which will separate the second and third most recent posts from the most recent post?
I did not want to use postID as the posts will change.
The two arguments in the WP_Query function below combine to retrieve the second most recent post, then the HTML below displays that post.
<div class="video-message">
<p>
<ul>
<!-- // Define our WP Query Parameters -->
<?php
$the_query = new WP_Query( array( 'posts_per_page' => 1,'offset' => 1 ) );
?>
<!-- // Start our WP Query -->
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<!-- // Display the Post Title with Hyperlink -->
<p><?php the_title(); ?></p>
<?php
endwhile;
wp_reset_postdata();
?>
</ul>
</p>
</div>
</div>
To display the third most recent post would require changing the offset value to 2, so that the program skips over the two most recent posts.
$the_query = new WP_Query( array( 'posts_per_page' => 1,'offset' => 2 ) );
This method is discussed in the Pagination Parameters section of the WordPress Code Reference.
Untested but you could try:
<?php
$count = 0;
query_posts('cat=2 && showposts=3');
if (have_posts()) : while (have_posts()) : the_post();
if($count == 0)
{
?>
<div class="col-xs-12 col-sm-4">
<div class="column">
<div class="news-article">
<p class="news-date"><?php the_time( get_option( 'date_format' ) ); ?></p>
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('full', array( 'class' => 'img-responsive img-rounded news-img' )); } ?>
<p class="news-headline"><?php the_title(); ?></p>
</a>
<p><?php the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>">
<p class="pull-right">Read more...</p>
</a>
<span class="clearfix"></span>
</div>
</div>
</div>
<?php
$count = 1;
}
else
{
//Some other layout here
}
endwhile;
endif;
?>
The above will check if $count is 0 and if it is, then do the layout and the count will then equal to 1. So the next time around $count won't be 0, so it will run what is in the else (which will be your layout).
I use WP_Query like this to show all posts from the fourth most recent one:
<?php
$query4 = new WP_Query( 'posts_per_page=4&offset=3' );
?>

WP-PageNavi Issues, Url changes but the posts remain the same?

The issue I am having is I have created a new blog page on its own page template page being called blog.php, I have pulled 5 posts into each page and the first page work great and link to the single posts that they are attached too.
When I try to add wp-pagenavi into my nav-below I run into an issue. What happens is I will click to go the next page and it changes the url, but the posts remain the same as before, when it should be switching them to the next set.
I don't know if you can use wp-pagenavi outside of index.php, but if anyone can let me know what I am doing wrong here and why I continue to get the same posts that would be awesome and greatly appreciated. I have one of my blogs on blog.php and that is the file I am trying to get to work. I have posted the code for it below.
<?php
/**
* Template Name: Blog Page <?php query_posts("posts_per_page=8"); ?>
*/
get_header(); ?>
<div id="content">
<?php query_posts( array( 'post_type' => 'post', 'posts_per_page=5' ) ); ?>
<?php
//THE LOOP.
if( have_posts() ):
while( have_posts() ):
the_post(); ?>
<article id="post-1" <?php post_class( 'clearfix' ); ?>>
<h2 class="entry-title"> <a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h2>
<div class="postmeta">
<span class="author"> Posted by: <?php the_author(); ?> </span>
<span class="date"> <?php the_date(); ?> </span>
<span class="num-comments">
<?php comments_number('No comments yet', 'One comment', '% comments'); ?></span>
<span class="categories">
<?php the_category(); ?>
</span>
<span class="tags">
<?php the_tags(); ?>
</span>
</div><!-- end postmeta -->
<?php if( has_post_thumbnail() ): ?>
<div class="thumb">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</div>
<?php endif; ?>
<div class="entry-content">
<?php
if( is_single() OR is_page() ):
the_content();
else:
the_excerpt();
endif;
?>
</div>
<?php comments_template(); ?>
</article><!-- end post -->
<?php
endwhile;
else: ?>
<h2>Sorry, no posts found</h2>
<?php endif; //END OF LOOP. ?>
<div id="nav-below" class="pagination">
<?php if( function_exists('wp_pagenavi') ):
wp_pagenavi();
else:
?>
<?php next_posts_link( '← Older Posts' ); ?>
<?php previous_posts_link( 'Newer Posts →' ); ?>
<?php endif; ?>
</div><!-- end #nav-below -->
</div><!-- end content -->
<?php get_footer(); ?>
After <div id="content"> have this code:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php query_posts( array( 'post_type' => 'post', 'posts_per_page=5', 'paged' => $paged ) ); ?>

get_posts doesn't work but query_posts does (Wordpress)

I'm using the following code to get posts with different types and categories assigned to them. The problem is that the main post of the page disappeared (the one you write in the Page section of the administrator menu).
I was reading the Wordpress documentation and they said that I should use get_post so that it wouldn't interfere with the main post of the page.
But everytime I change the all the query_posts to get_posts the posts don't appear:
<?php get_posts('category_name=Events&showposts=5'); ?>
page-events.php:
<?php
/**
* Template Name: Events Template
* #package WordPress
* #subpackage Twenty_Ten
* #since Twenty Ten 1.0
*/
get_header(); ?>
<div id="container">
<div id="content" role="main">
<?php // find all content that has the category of Events and then to loop through them. ?>
<?php query_posts('category_name=Events&showposts=5'); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( is_front_page() ) { ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php } else { ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php } ?>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-content -->
</div><!-- #post-## -->
<?php comments_template( '', true ); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #container -->
<div id="container">
<div id="content" role="main">
<?php // find all content that has the type of video and then to loop through them. ?>
<?php query_posts(array('post_type'=>'video')); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( is_front_page() ) { ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php } else { ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php } ?>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-content -->
</div><!-- #post-## -->
<?php comments_template( '', true ); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
The main difference about query_posts() and get_posts() is that the first is intended to be used to modify the main page loop only and the latter is used for creating multiple custom loops.
So, in order to show the posts you may use get_posts() with its own custom loop. Example:
<?php
$customposts = get_posts('category_name=Events&showposts=5' ); // note: you assign your query to a custom post object ($customposts)
foreach( $customposts as $post ) : // start you custom loop
setup_postdata($post); ?>
// do your things...
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php the_content() ?>
....
<?php endforeach; ?> // end the custom loop
To preserve your original post (the one you inserted in the Edit panel for that page), you can code, after the main loop, two custom query loops with get_posts() just like the example above (you only have to change the query arguments for the latter).
Hope it helps.

Resources