Taxonomy image
page image
Here, I have categorized my page with different page. In that, I categorized with taxonomy and slug. All the title have different taxonomy as shown in the image. But here I am getting multiple image because it have multiple taxonomy.
So, I just want 8 images as the Business theme are as shown in images and have to display as per the taxonomy.
As you can see the taxonomy count that is 4,4 and 5, So I am getting record like that, but I want to get record as per Business theme, as they are eight but as per taxonomy.
Here what I have tried:
<div class="portfolio-items">
<?php
$terms = get_terms('portfolio_cat');
foreach($terms as $row)
{
$args = array('post_type' => 'portfolio','tax_query' => array(
array(
'taxonomy' => 'portfolio_cat',
'field' => 'slug',
'terms' => array( $row->slug ),
)
));
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) :
while ( $loop->have_posts() ) : $loop->the_post();
$i=1;
?>
<div class="portfolio-item <?php echo $row->slug; ?> col-xs-12 col-sm-4 col-md-3">
<div class="recent-work-wrap">
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?>
<?php $large_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'large' ); ?>
<img class="img-responsive" src="<?php echo $url; ?>" alt="">
<div class="overlay">
<div class="recent-work-inner">
<h3><?php the_title(); ?></h3>
<?php $content = get_the_content(); ?>
<p><?php echo $content; ?></p>
<a class="preview" href="<?php echo $large_url; ?>" rel="prettyPhoto"><i class="fa fa-eye"></i> View</a>
</div>
</div>
</div>
</div><!--/.portfolio-item-->
<?php
// End of the loop.
$i++;
endwhile;
endif;
WP_Reset_Query();
}
?>
</div>
Related
I am developing custom Woo shop theme. I want to display in front-page.php NEW COLLECTION products, it should be one block, and inside few smaller blocks with products ant their another vcategories, because, they will have common category NEW and another category depends BEDROOM/BATHROOM/CLOTHING, for now i have reahced display by one category.
<div class="col-md-12 row">
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 4,
'product_cat' => 'clothing'
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
$colors = explode(',',$product->get_attribute('color'));
$price = $product->get_price_html();
?>
<div class="col-md-3 d-flex flex-column">
<div class="homepage__single-product">
<a href="<?php the_permalink(); ?>">
<img src="<?php echo the_post_thumbnail_url(); ?>">
<p class="homapage__single-product-title"><?php the_title(); ?></p>
<p class="homapage__single-product-price"><?php echo $price ?></p>
<p class="homepage__single-product-color">
<?php foreach ($colors as $color) {
echo '<span class="attribute-color '. strtolower(trim($color)) .'"></span>';
}
?>
</p>
</a>
</div>
</div>
<?php
endwhile;
wp_reset_query();
?>
</div>
I hope that my question will be clear, i am adding image with design for better understanding. I think that it should be somethimg like this code, but this code should have NEW as product_cat in $args, and then inside loop somehow do same block but with other categories.
design shows how it should be
You can use tax_query to get products from multiple categories. check below code.
<div class="col-md-12 row">
<?php
$prod_categories = array( 'bedroom', 'bathrooms', 'clothing'); //category slugs
$args = array(
'post_type' => 'product',
'posts_per_page' => 4,
);
if (!empty($prod_categories)) {
$args['tax_query'] = array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $prod_categories,
'operator' => 'IN',
));
}
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
$colors = explode(',',$product->get_attribute('color'));
$price = $product->get_price_html();
?>
<div class="col-md-3 d-flex flex-column">
<div class="homepage__single-product">
<a href="<?php the_permalink(); ?>">
<img src="<?php echo the_post_thumbnail_url(); ?>">
<p class="homapage__single-product-title"><?php the_title(); ?></p>
<p class="homapage__single-product-price"><?php echo $price ?></p>
<p class="homepage__single-product-color">
<?php foreach ($colors as $color) {
echo '<span class="attribute-color '. strtolower(trim($color)) .'"></span>';
}
?>
</p>
</a>
</div>
</div>
<?php
endwhile;
wp_reset_query();
?>
</div>
Working on a WordPress theme issue, I have an archive page that has a featured post at the top that displays a featured image, post date, and excerpt along with other posts below it.
Running into an issue where the featured post has the correct title, correct image, but incorrect excerpt. It pulls in a different post's text instead.
Any clue as to what is incorrect with the code below?
<?php
$args = array(
'numberposts' => '1' ,
'post_type' => 'post',
'meta_key' => 'post_featured',
'meta_compare' => '=',
'meta_value' => 1
);
$recent_posts = wp_get_recent_posts( $args );
$fID = 0;
foreach( $recent_posts as $recent ) : ?>
<?php $fID = $recent["ID"]; ?>
<div class="blog-listing featured_post">
<a class="blog-image-lg" href="<?php echo get_permalink($recent["ID"]); ?>" style="background-image: url('<?php echo get_the_post_thumbnail_url( $recent["ID"], 'full' ); ?>');">
<span>FEATURED POST</span>
<?php echo get_the_post_thumbnail( $recent["ID"], 'post-thumbnails-big' ); ?>
</a>
<div class="blog-info pull-left">
<h3 class="blog-title"><?php echo $recent["post_title"]; ?></h3>
<span class="blog-date"><?php echo strtoupper(get_the_date('F j, Y')); ?></span>
<p><? echo the_excerpt(); ?></p>
<p class="readmore-wrapper"><a class="readmore" href="<?php echo get_permalink($recent["ID"]); ?>">READ MORE »</a></p>
</div>
</div>
Change <? echo the_excerpt(); ?> to <?php echo get_the_excerpt($recent["ID"]); ?>.
the_excerpt() does not work in your case as you are not inside a WP Loop, just a regular for loop.
I'm new in wordpress. I'm trying load custom field of post from function.php. Below is code for function post grid layout function where I use custom field:
$args = array(
'post_type' => 'post',
'category_name' => 'category',
'posts_per_page' => -1,
'orderby' => 'ID',
'order' => 'ASC'
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
$c = 1;
$bpr = 5;
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<div class="member">
<div class="div-block-image">
<?php the_post_thumbnail(); ?>
</div>
<div class="div-block-29 w-clearfix">
<div class="text-block-21"><?php the_title(); ?></div>
<div class="text-block-22">subTitle</div>
<div class="text-block-23">Text...</div>
<a href="<?php the_permalink() ?>" class="more w-inline-block">
<div class="text-block-24">More</div>
</a>
<p><?php echo get_post_meta($post->ID, 'linkedin', true); ?></p> // custom-field
<p><?php echo get_post_meta($post->ID, 'bio', true); ?></p>
<a href="#" target="_blank" class="link-block w-inline-block">
<div class="biotxt">bio</div>
</a>
<a href="#" target="_blank" class="link-block w-inline-block">
<div class="text-block-20"></div>
</a>
</div>
</div>
<?
if( $c == $bpr ) {
echo '<div class="clear"></div>';
$c = 0;
}
$c++;
endwhile;
} else {
_e( '<h2>Oops!</h2>', 'rys' );
_e( '<p>Sorry, seems there are no post at the moment.</p>', 'rys' );
}
wp_reset_postdata();
I want to load this function from template page. All is loading normally except custom field:
<p><?php echo get_post_meta($post->ID, 'linkedin', true); ?></p>
If run function code from template page its running normal. Any ideas?
$post->ID is not correct, as it's picking up the ID from the global $post object, which just happens to be the same when you're on the template page, but not necessarily when you're using it in a function in functions.php. Use get_the_ID() instead.
Within your custom loop, you will want to update those to use: get_the_ID() and not $post->ID.
<p><?php echo get_post_meta(get_the_ID(), 'linkedin', true); ?></p>
This will get the ID from the current loop.
Ref: https://developer.wordpress.org/reference/functions/get_the_id/
i'm building a recent posts function into a wordpress site, i've got it to call up two different featured images but they are both linking to the same post, can anyone see where i am going wrong?
<?php
$args = array(
'posts_per_page' => 2,
'order_by' => 'date',
'order' => 'desc'
);
$post = get_posts( $args );
if($post) {
$post_id = $post[0]->ID;
if(has_post_thumbnail($post_id)){
?>
<div class="grid_24">
<div class="grid_12">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php
echo get_the_post_thumbnail($page->ID, 'medium');
?>
</a>
</div>
<div class="grid_12">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php
echo get_the_post_thumbnail( $post_id,'medium');
?>
</a>
</div>
</div>
<?php
}
}
?>
you can use echo get_the_permalink($post->ID) to get the uri for the posts
So it looks like in your case you'd need
echo get_the_permalink($post[0]->ID);
and
echo get_the_permalink($post[1]->ID);
in the href
However you're probably better off creating a foreach loop to go through the posts from the get_posts function
https://developer.wordpress.org/reference/functions/get_the_permalink/
https://developer.wordpress.org/reference/functions/get_posts/
Okay, first of all, you are not looping the query you have made ( e.g $posts = get_posts( $args ); ) you are just displaying the 1st post's thumbnail and the thumbnail of the current page.
You need to loop the post like this :
<?php
$args = array(
'posts_per_page' => 2,
'order_by' => 'date',
'order' => 'desc'
);
$posts = get_posts( $args );
?>
<?php if ( !empty( $posts ) ) :?>
<div class="grid_24">
<?php foreach ( $posts as $post ) : ?>\
<?php if( has_post_thumbnail( $post->ID ) ) ?>
<div class="grid_12">
<a href="<?php echo esc_url( get_permalink( $post->ID ) ) ?>">
<?php echo get_the_post_thumbnail( $post->ID, 'size_here'); ?>
</a>
</div>
<?php endif; ?>
<?php endforeach?>
</div>
<?php endif;
So basically, I'm working on a custom wordpress theme. What i'm trying to do is to set an icon for each category. If the loop starts and the post has a category, It'll show up with the icon that it has assigned. Right now it shows the correct icons, but the title and exerpt of the post keeps changing to the name of the page. Here is an example I have three posts math, english and history all of them have the correct icon, but display the name blog post page instead of math, english, or history.
<?php /* Template Name: News Blog Page */ get_header(); ?>
<div id="blog-post-wrapper" class="section_wrapper">
<div class="column three-fourth">
<?php $currentPage = get_query_var('paged');
$args = array(
'post_type' => 'post',
'order' => 'DESC',
'posts_per_page' => 9,
'paged' => $currentPage
);
$the_query = new WP_Query($args);
if($the_query -> have_posts()):
while ($the_query -> have_posts()): $the_query -> the_post();
get_template_part('postloopcontent', get_post_format());
endwhile;
echo "<div class='pagination'>";
echo paginate_links(array(
'total' => $the_query -> max_num_pages
));
echo "</div>";
endif;
?>
</div>
<div class="column one-fourth">
<?php get_sidebar(); ?>
</div>
</div>
<?php get_footer(); ?>
the top one is my basic layout and it grabs my loop. the bottom one is my loop
<?php
// Standard Post Format
?>
<?php $bgImage = get_the_post_thumbnail_url(); ?>
<div class="column one-third" style="background-image:url(<?php echo $bgImage; ?>);">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="nws-img">
<?php
// Find the first category the post is in.
$categories = get_the_category();
$category = $categories[ 0 ]->term_id;
$imgargs = array(
'cat' => $category,
'post_status' => 'inherit',
'post_type' => 'attachment',
'posts_per_page' => '1'
);
$imgquery = new WP_Query( $imgargs );
if ( $imgquery->have_posts() ) {
while ( $imgquery->have_posts() ) { $imgquery->the_post(); ?>
<div class="category-featured-image">
<?php echo wp_get_attachment_image( $post->ID, 'thumbnail' ); ?>
</div>
<?php
}
}
// Reset postdata to restore ordinal query.
wp_reset_postdata();
?>
</a>
<div id="content-box">
<h1> <a href="<?php the_permalink(); ?>" > <?php the_title(); ?> </a> </h1>
<?php the_excerpt(); ?>
</div>
</div>
In your loop file, you're resting post data i.e. wp_reset_postdata(); outside the $imgquery loop/condition. If you could wrap the postdata rest function inside the condition, I think that should work.
You code must look like this
<?php
// Standard Post Format
?>
<?php $bgImage = get_the_post_thumbnail_url(); ?>
<div class="column one-third" style="background-image:url(<?php echo $bgImage; ?>);">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="nws-img">
<?php
// Find the first category the post is in.
$categories = get_the_category();
$category = $categories[ 0 ]->term_id;
$imgargs = array(
'cat' => $category,
'post_status' => 'inherit',
'post_type' => 'attachment',
'posts_per_page' => '1'
);
$imgquery = new WP_Query( $imgargs );
if ( $imgquery->have_posts() ) {
while ( $imgquery->have_posts() ) { $imgquery->the_post(); ?>
<div class="category-featured-image">
<?php echo wp_get_attachment_image( $post->ID, 'thumbnail' ); ?>
</div>
<?php
}
// Reset postdata to restore ordinal query.
wp_reset_postdata();
}
?>
</a>
<div id="content-box">
<h1> <a href="<?php the_permalink(); ?>" > <?php the_title(); ?> </a> </h1>
<?php the_excerpt(); ?>
</div>
</div>