I'm creating a one-page theme for WordPress. In my index.php I'm listing all pages underneath each other:
<?php $args = array(
'sort_order' => 'ASC',
'sort_column' => 'menu_order', //post_title
'hierarchical' => 1,
'exclude' => '',
'child_of' => 0,
'parent' => -1,
'exclude_tree' => '',
'number' => '',
'offset' => 0,
'post_type' => 'page',
'post_status' => 'publish'
);
$pages = get_pages($args);
//start loop
foreach ($pages as $page_data) {
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
$slug = $page_data->post_name;
?>
<div id='<?php echo "$slug" ?>' class="section">
<div id="inner-content" class="wrap cf">
<div id="main" class="m-all cf" role="main">
<div class="content">
<h2 class="section-title"><?php echo "$title" ?></h2>
<?php echo "$content" ?>
<?php the_post_thumbnail('full'); ?>
</div>
</div>
</div>
<?php } ?>
However, my thumbnail does not show up... There is no error message, but as well no thumb. Any ideas?
Try this code
<?php $args = array(
'sort_order' => 'ASC',
'sort_column' => 'menu_order', //post_title
'hierarchical' => 1,
'exclude' => '',
'child_of' => 0,
'parent' => -1,
'exclude_tree' => '',
'number' => '',
'offset' => 0,
'post_type' => 'page',
'post_status' => 'publish'
);
$pages = get_pages($args);
//start loop
foreach ($pages as $page_data) {
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
$slug = $page_data->post_name;
?>
<div id='<?php echo "$slug" ?>' class="section">
<div id="inner-content" class="wrap cf">
<div id="main" class="m-all cf" role="main">
<div class="content">
<h2 class="section-title"><?php echo "$title" ?></h2>
<?php echo "$content" ?>
<?php echo get_the_post_thumbnail( $page_data->ID, 'thumbnail' ); ?>
</div>
</div>
</div>
<?php } ?>
Related
I have a pizza sales site which offers 'Ingredients' of which these are simple products, for example: Pizza Napolí is a bundle product, this product has ingredients grouped together.
What I'm looking for is to show in a custom loop (wp_query) the children products or ingredients of this pizza, which are 'Cheese(Queso)', 'Bacon(Tocineta)', etc.
Images reference here:
My code:
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'orderby' => 'date',
'order' => 'ASC',
'meta_key' => '_stock_status',
'posts_per_page' => 10,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'terms' => array('pizzas'),
'field' => 'name',
'operator' => 'IN'
)
)
);
// End query
$products = new WP_Query( $args, 'woocommerce'); ?>
<div class="menu-grid-pizzas">
<?php if ($products->have_posts()): ?>
<div class="container">
<ul class="grid-pizzas-list">
<?php while ($products->have_posts()): $products->the_post(); ?>
<li class="grid-pizzas-content">
<div class="content-left">
<div class="grid-img">
<a href="<?php the_permalink();?>">
<?php the_post_thumbnail('medium');?>
</a>
</div>
</div>
<div class="content-right">
<div class="grid-product-title">
<a href="<?php the_permalink();?>">
<h4><?php the_title();?></h4>
</a>
</div>
<div class="grid-product-content">
<?php $content = get_the_content();?>
<p><?php echo mb_strimwidth($content, 0, 120, "...");?></p>
</div>
<div class="grid-product-ingredints">
<!-- HERE get DATA items bundles -->
</div>
<div class="grid-product-price">
<?php $precio = get_post_meta( get_the_ID(), '_price', true );?>
<p><?php echo wc_price( $precio ); ?></p>
</div>
<div class="grid-product-add-to-card">
<?php do_action('woocommerce_after_shop_loop_item' , 'woocommerce_template_loop_add_to_cart' , 10 );?>
</div>
</div>
</li>
<?php endwhile;?>
<?php wp_reset_postdata();?>
</ul>
</div>
<?php endif;?>
</div>
As you can see, it is a custom loop from which I call all products with the category 'Pizza' with a wp_query.
I hope you can help me, thank you.
I tried to display all my product categories inside slider
<div id="category-wrapper">
<div id="owl1" class="owl-carousel">
<div class="item">
<?php echo do_shortcode('[product_category category="main-cat"]'); ?>
</div>
<div class="item">
<?php echo do_shortcode('[product_category category="cat2"]'); ?>
</div>
<div class="item">
<?php echo do_shortcode('[product_category category="cat3"]'); ?>
</div>
<div class="item">
<?php echo do_shortcode('[product_category category="cat4"]'); ?>
</div>
...
</div>
</div>
but it outputs products in these categories instead of categories.
I need to do this:
link image Each box represents one product category in root.
I did it myself, but in subcategories are images not working:
<div id="kategorie-nahlad">
<?php
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 0;
$pad_counts = 0;
$hierarchical = 1;
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$all_categories = get_categories( $args ); ?>
<div id="owl1" class="owl-carousel">
<?
foreach ($all_categories as $cat) {
$thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
$image_alt = get_post_meta( $image->id, '_wp_attachment_image_alt', true );
if ($cat->category_parent == 0) {
$category_id = $cat->term_id;
echo '<div class="item text-center">';
echo '<br><img src="' . $image . '" alt="' . $image_alt . '">'. $cat->name .'';
echo '</div>';
$args2 = array(
'taxonomy' => $taxonomy,
'child_of' => 0,
'parent' => $category_id,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$sub_cats = get_categories( $args2 );
if($sub_cats) {
foreach($sub_cats as $sub_category) {
$thumbnail_id_sub = get_term_meta( $cat->term_id, 'thumbnail_id', true );
$image_sub = wp_get_attachment_url( $thumbnail_id_sub );
echo '<div class="item text-center">';
echo '<br><img src="' . $image . '" alt="' . $image_alt . '">'. $sub_category->name .'';
// echo apply_filters( 'woocommerce_subcategory_count_html', ' <div class="cat-count">' . $sub_category->count . '</div>', $category );
echo '</div>';
}
}
}
}
?>
</div><!-- KONIEC OWL1 -->
</div>
I'm having an issue with a custom product loop for featured products. It worked fine before a update.
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 4,
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
),
),
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
$currency = get_woocommerce_currency_symbol();
$price = get_post_meta( get_the_ID(), '_regular_price', true);
$sale = get_post_meta( get_the_ID(), '_sale_price', true);
if($sale) {
echo '
<div class="pickproductsitem">
<div class="pickprodimage" style="background-image: url(' . get_the_post_thumbnail_url() . ');"></div>
<div class="prodname">'.get_the_title().'</div>
<div class="prodinfo">'. get_the_excerpt() .'</div>
<div class="prodprice"><span style="text-decoration: line-through;">Only '.$currency.$price.'</span><span style="color: green;"> SALE '.$currency.$sale.'</span></div>VIEW</div>';
}
elseif($price)
{
echo '
<div class="pickproductsitem">
<div class="pickprodimage" style="background-image: url(' . get_the_post_thumbnail_url() . ');"></div>
<div class="prodname">'.get_the_title().'</div>
<div class="prodinfo">'. get_the_excerpt() .'</div>
<div class="prodprice">Only '.$currency.$price.'</div>VIEW</div>';
}
endwhile;
wp_reset_query();
?>
I've tried fixing the Permalinks but it hasn't sorted the issue. I'm no expert at Woo or even Wordpress but this loop did work.
Thank you for any help.
If you want to display featured products then do use below code in your query args it will solve the issue.
<?php
$meta_query = WC()->query->get_meta_query();
$meta_query[] = array(
'key' => '_featured',
'value' => 'yes'
);
$args = array(
'post_type' => 'product',
'posts_per_page' => 4,
'meta_query' => $meta_query
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
$currency = get_woocommerce_currency_symbol();
$price = get_post_meta( get_the_ID(), '_regular_price', true);
$sale = get_post_meta( get_the_ID(), '_sale_price', true);
if($sale) {
echo '
<div class="pickproductsitem">
<div class="pickprodimage" style="background-image: url(' . get_the_post_thumbnail_url() . ');"></div>
<div class="prodname">'.get_the_title().'</div>
<div class="prodinfo">'. get_the_excerpt() .'</div>
<div class="prodprice"><span style="text-decoration: line-through;">Only '.$currency.$price.'</span><span style="color: green;"> SALE '.$currency.$sale.'</span></div>VIEW</div>';
}
elseif($price)
{
echo '
<div class="pickproductsitem">
<div class="pickprodimage" style="background-image: url(' . get_the_post_thumbnail_url() . ');"></div>
<div class="prodname">'.get_the_title().'</div>
<div class="prodinfo">'. get_the_excerpt() .'</div>
<div class="prodprice">Only '.$currency.$price.'</div>VIEW</div>';
}
endwhile;
wp_reset_query();
?>
I have used taxonomy template texonomy-blog_category.php file.
But gives 404 error when i moved to page 2 .
Below is my code
<?php
get_header('newheader');
$tax = get_query_var('taxonomy');
$term = get_query_var('term');
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$count_args=array( 'post_type' => 'blog_post',
'tax_query' => array(
array(
'taxonomy' => $tax,
'field' => 'slug',
'terms' => $term,
),
),
);
$count_detail=query_posts($count_args);
//echo count($count_detail);exit;
$posts_per_page = 2;// get_option( 'posts_per_page' );
$max_page=ceil(count($count_detail)/$posts_per_page);
//wp_reset_query();
$args = array( 'post_type' => 'blog_post',
'tax_query' => array(
array(
'taxonomy' => $tax,
'field' => 'slug',
'terms' => $term,
),
),
'posts_per_page'=>$posts_per_page,
'paged' => $paged,'page'=>$paged,
'max_num_pages'=>$max_page,
);
$post_detail=query_posts($args);
?>
<div class="container">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 main-conten">
<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12 blog-main">
<ul class="blog_listing">
<?php
for($i=0;$i<count($post_detail);$i++)
{
$postId=$post_detail[$i]->ID;
$ttl=get_the_title($postId);
$url=$post_detail[$i]->guid;
//print_r($post_detail[$i]);
?>
<li>
<a href="<?php echo $post_detail[$i]->guid; ?>" ><h1><?php echo get_the_title($postId); ?></h1></a>
<div class="blog-img">
<a href="<?php echo $post_detail[$i]->guid; ?>" >
<?php //$retina = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) ?>
<?php echo get_the_post_thumbnail( $postId,array(760,331), $attr ); ?>
</a>
</div>
<span>
<?php echo date('d F , Y',strtotime($post_detail[$i]->post_date)); ?>
</span>
<p>
<?php echo $post_detail[$i]->post_excerpt; ?>
</p>
<a class="read-more" href="<?php echo $post_detail[$i]->guid; ?>">Read More</a> </li>
</li>
<?php }?>
</ul>
<div class="case_blog">
<?php
//wp_reset_postdata();
if (function_exists(custom_pagination)) {
custom_pagination($max_page,"",$paged);
}
?>
</div>
<?php //$custom_query = $temp; ?>
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 blog_right_list blog-side">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Blog Sidebar") ) : ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php get_footer();
?>
I don't know what is going wrong.please help me to get out of this.
Thanks in advance
Remove page parameter from $args, your code look like this.
$args = array( 'post_type' => 'blog_post',
'tax_query' => array(
array(
'taxonomy' => $tax,
'field' => 'slug',
'terms' => $term,
),
),
'posts_per_page'=>$posts_per_page,
'paged' => $paged,
'max_num_pages'=>$max_page,
);
i have this code:
<?php
$valid_ext = array("pdf", "doc");
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'application/pdf',
'numberposts' => 40,
'post_status' => null,
'post_parent' => null, // any parent
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $post) {
$ext = getFileExt(wp_get_attachment_url($post_id, false));
if(in_array($ext, $valid_ext)) {
?>
<li>
<div class="entry-date">
<abbr class="published" title="<?php the_time('Y-m-d\TH:i:sO')?>">
<?php unset($previousday); printf( __( '%1$s – %2$s', 'sandbox' ), the_date( '', '', '', false ), get_the_time() )?>
</abbr>
</div>
<div id="post-<?php the_ID()?>" class="<?php sandbox_post_class()?> " style="padding:0; margin:0;">
<p style="font-size:11px; text-transform:uppercase;">
<?php setup_postdata($post);the_attachment_link($post_id, true);?>
</p>
</div>
</li>
<?php
}
}
}
?>
it gives me as output a date and a link with the document name.
<li>
<div class="entry-date">
<abbr title="2011-06-15T17:30:29+0200" class="published">
15 giugno 2011 – 17:30
</abbr>
</div>
<div style="padding:0; margin:0;" class="hentry p11 attachment inherit author-daniela-santanch category-senza-categoria untagged y2011 m06 d15 h17 " id="post-2158">
<p style="font-size:11px; text-transform:uppercase;">
<a title="la_stampa_07_06_2011" href="http://www.mpli.it/wp/wp-content/uploads/2011/06/la_stampa_07_06_2011.pdf">la_stampa_07_06_2011</a> </p>
</div>
i'd like to get the post title linking directly to the document.
any help?
Try this:
<?php
$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null );
$attachments = get_posts( $args );
if ($attachments) {
foreach ( $attachments as $post ) {
setup_postdata($post);
the_title();
the_attachment_link($post->ID, false);
the_excerpt();
}
}
?>