Wordpress show featured image sorted by subtitle - php

I try to sort this array by the subtitle. I want to show only featured images, where the subtitle is "anwesend". I tried different things, but nothing is working. Could you please support me in this task?
here is the code of this array.
<?php
$args = array(
'parent' => $post->ID,
'post_type' => 'page',
'post_status' => 'publish',
);
$pages = get_pages($args); ?>
<div style="max-width:1240px;">
<?php foreach( $pages as $page ) { ?>
<div class="box">
<a href="<?php echo get_permalink($page->ID); ?>" rel="bookmark" title="<?php echo $page->post_title; ?>">
<span class="tagesplan_title"><?php echo $page->post_title; ?></span>
<center><span class="thumbnail_box"><?php echo get_the_post_thumbnail($page->ID, 'small-thumb'); ?></span></center>
<span class="status2"><?php echo get_the_subtitle($page); ?></span>
<span class="desc"><?php echo get_post_meta($page->ID, 'desc', true); ?></span>
</a>
</div>
<?php } ?>

Related

Wordpress loop showing blank page

I'm using the code below to display an Owl Carousel of pages that have the same parent page as the current page, it works but the first item in the loop is blank.
Any Ideas? Thanks
<?php
// [service_page_carousel]
function service_page_carousel_func() {
global $post;
$direct_parent = $post->post_parent;
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $direct_parent,
'order' => 'ASC',
'orderby' => 'menu_order',
'post__not_in' => array( $post->ID ),
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) : ?>
<div class="service-page-owl-carousel owl-carousel owl-theme owl-loaded owl-drag">
<?php while ( $query->have_posts() ) : $query->the_post();
// Featured image
$feat_image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), "full", true);
?>
<div class="item">
<div class="service">
<a href="<?php the_permalink(); ?>">
<div class="featured-img" style="background-image: url(<?php echo $feat_image[0]; ?>);"></div>
</a>
<a href="<?php the_permalink(); ?>">
<h3 class="brand-secondary"><?php the_title(); ?></h3>
</a>
<div class="text"><?php the_excerpt(); ?></div>
<p class="learn-more"><a class="btn primary" href="<?php the_permalink(); ?>">Learn More</a></p>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
<?php endif;
}
add_shortcode( 'service_page_carousel', 'service_page_carousel_func' );
i think you missed to add active class if only one page/post in owl carousel
<?php
// [service_page_carousel]
function service_page_carousel_func() {
global $post;
$direct_parent = $post->post_parent;
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $direct_parent,
'order' => 'ASC',
'orderby' => 'menu_order',
'post__not_in' => array( $post->ID ),
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) : ?>
<div class="service-page-owl-carousel owl-carousel owl-theme owl-loaded owl-drag">
<?php
$index = 0;
while ( $query->have_posts() ) : $query->the_post();
// Featured image
$feat_image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), "full", true);
?>
<div class="item <?php echo ($index == 0) ? 'active' : ''; ?>">
<div class="service">
<a href="<?php the_permalink(); ?>">
<div class="featured-img" style="background-image: url(<?php echo $feat_image[0]; ?>);"></div>
</a>
<a href="<?php the_permalink(); ?>">
<h3 class="brand-secondary"><?php the_title(); ?></h3>
</a>
<div class="text"><?php the_excerpt(); ?></div>
<p class="learn-more"><a class="btn primary" href="<?php the_permalink(); ?>">Learn More</a></p>
</div>
</div>
<?php endwhile;
$index++;
wp_reset_query(); ?>
</div>
<?php endif;
}
add_shortcode( 'service_page_carousel', 'service_page_carousel_func' );

Wordpress featured images won't display

I am creating a widget in wordpress that pulls through child pages content (thumbnail/Featured image, title and excerpt) from the 'About Page' and displays them on the 'Homepage'. All content except the thumbnail/featured displays correctly. The thumbnail/featured image displays in grey, is is viable in other post and in the back end. when I inspect the code the url for the image does not seem to be pulling through.
Can anyone assist with this issue?
$pgs = array(
'parent' => '344',
'post_type' => 'page',
'post_status' => 'publish',
'posts_per_page' => 99,
'orderby' => 'menu_order'
);
$pages = get_pages( $pgs );
echo $args['before_widget'];
?>
<div class="text-center">
<h2 class="blessed-widget-title">title</h2>
<div class="text-center" id="services">
<?php foreach( $pages as $page ) { ?>
<div class="our-services-post-box col-md-4 col-sm-6 col-xs-6" id="child-<?php the_ID(); ?>">
<a href="<?php echo get_permalink($page->ID); ?>" rel="bookmark" title="<?php echo $page->post_title; ?>">
<div class="service-thumbnail background-image" style="background-image: url(<?php echo blessed_get_attachment($page->ID) ?>) ">
<img class="image-invisible" src=" <?php echo blessed_get_attachment($page->ID); ?> ">
</div>
<h2><?php echo $page->post_title; ?></h2>
</a>
<p><?php echo get_the_excerpt($page->ID) ?></p>
</div><!--services-->
<?php } ?>
</div>
</div>
<?php
echo $args['after_widget'];
I found 2 missed semicolons.
1st was here:
<div class="service-thumbnail background-image" style="background-image: url(<?php echo blessed_get_attachment($page->ID) ?>) ">
2nd was here:
<p><?php echo get_the_excerpt($page->ID) ?></p>
Maybe it caused the problem. Also Quotes are not necessary in an url, but I added it to see what will be the result.
Try to use the following one instead.
$pgs = array(
'parent' => '344',
'post_type' => 'page',
'post_status' => 'publish',
'posts_per_page' => 99,
'orderby' => 'menu_order'
);
$pages = get_pages( $pgs );
echo $args['before_widget'];
?>
<div class="text-center">
<h2 class="blessed-widget-title">title</h2>
<div class="text-center" id="services">
<?php foreach( $pages as $page ) { ?>
<div class="our-services-post-box col-md-4 col-sm-6 col-xs-6" id="child-<?php the_ID(); ?>">
<a href="<?php echo get_permalink($page->ID); ?>" rel="bookmark" title="<?php echo $page->post_title; ?>">
<div class="service-thumbnail background-image" style="background-image: url('<?php echo blessed_get_attachment($page->ID); ?>') ">
<img class="image-invisible" src=" <?php echo blessed_get_attachment($page->ID); ?> ">
</div>
<h2><?php echo $page->post_title; ?></h2>
</a>
<p><?php echo get_the_excerpt($page->ID); ?></p>
</div><!--services-->
<?php } ?>
</div>
</div>
<?php
echo $args['after_widget'];
Also try to review your CSS Classes related to Featured images.

Woocommerce sub categories

I am making a custom loop for my site using Woocommerce, I am using sub categories as a additional text field for the products but I can't find a function to just show sub categories, all are showing main and sub categories.
Can anyone help ?
<?php echo $product->get_categories(); ?>
Much appreciated :)
Here is the full code
<ul class="row-fluid">
<?php
$args = array ( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => 4, 'product_cat' => 'news', 'orderby' => 'date','order' => 'DESC' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<li class="span">
<a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?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="65px" height="115px" />'; ?>
<h3><?php the_title(); ?></h3>
<?php echo $product->get_categories(); ?>
<p class="price"><?php echo $product->get_price_html();?></p>
<a class="button add_to_cart_button product_type_simple"href="<?php the_permalink(); ?>">More...</a>
</a>
<div class="wer"><?php the_excerpt(); ?></div>
<span class="Cart"><?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?></span>
</li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul>

Target first post in wordpress PHP

Can anybody help i need to add an image to the first post in this loop but can't figure it out, so i want to go through the loop and only have an image in the first post and just display the rest as normal. Below is the code, cheers
<div class="trinary-content content ten columns">
<?php
$catObj = get_category_by_slug('news-and-views');
$category_id = $catObj->term_id;
$args = array(
'sort_order' => 'DESC',
'sort_column' => 'post_date',
'hierarchical' => 0,
'exclude' => '',
'include' => '',
'meta_key' => '',
'meta_value' => '',
'authors' => '',
// 'parent' => $post->ID,
'category' => $category_id,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 3
);
$pages = get_posts($args);
?>
<div class="widget widget-newsandviews">
<h2><?php echo $catObj->name; ?></h2>
<img class="news-image" src="/wp-content/themes/quentin/images/motorbike-accident/biker-full.png" />
<div class="items">
<?php $i = 0; ?>
<?php foreach($pages as $page): ?>
<div class="item <?php if($i)echo 'last'; ?>">
<a class="item-title" href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a>
<p class="summary"><?php echo $page->post_except; ?></p>
<a class="read-more" href="<?php echo get_page_link( $page->ID ); ?>">Find out more »</a>
<div class="clear"></div>
</div>
<?php $i++; ?>
<?php endforeach; ?>
</div>
</div>
</div>
Try an if statement, you can move that block to wherever you want in your code. Also you may want to use the_post_thumbnail() to retrieve the image from the post itself
<?php foreach($pages as $page): ?>
<?php if ($i==0){ ?>
<img class="news-image" src="/wp-content/themes/quentin/images/motorbike-accident/biker-full.png" />
<?php } ?>
<div class="item <?php if($i)echo 'last'; ?>">
<a class="item-title" href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a>
<p class="summary"><?php echo $page->post_except; ?></p>
<a class="read-more" href="<?php echo get_page_link( $page->ID ); ?>">Find out more »</a>
<div class="clear"></div>
</div>
<?php $i++; ?>
<?php endforeach; ?>

WordPress: Not able to get current ID.

I'm very new to WordPress, and I've been pulling hair trying to figure this one out.
I have a custom theme, the theme is very simple, which contains an image carousel built up from a collection of images in a gallery.
If I remove the carousel include file, the post ID on the rest of the page returns correctly, as soon as I add the carousel back, it uses the ID of the last category pulled in the code.
I removed all 'global' references, as I assumed this will override the ID for the rest of the page, but it's still wrong.
The code from the carousel.php file:
<div id="carousel">
<?php
$args = array(
'post_type' => 'gallery',
'post_status' => 'publish',
'name' => $wp_query->query_vars['name'],
'posts_per_page' => 1
);
$second_query = new WP_Query($args);
$gllr_options = get_option('gllr_options');
$gllr_download_link_title = addslashes(__('Download high resolution image', 'gallery'));
if ($second_query->have_posts()) : while ($second_query->have_posts()) : $second_query->the_post(); ?>
<div class="carousel-holder">
<?php
the_content();
$galleries = get_posts(array(
'showposts' => -1,
'what_to_show' => 'posts',
'post_status' => 'inherit',
'post_type' => 'attachment',
'orderby' => $gllr_options['order_by'],
'order' => $gllr_options['order'],
'post_mime_type' => 'image/jpeg,image/gif,image/jpg,image/png',
'post_parent' => $post->ID
));
if (count($galleries) > 0) { ?>
<ul id="carousel-gallery">
<?php foreach ($galleries as $attachment) {
$key = 'gllr_image_text';
$link_key = 'gllr_link_url';
$alt_tag_key = 'gllr_image_alt_tag';
$image_attributes = wp_get_attachment_image_src( $attachment->ID, 'photo-thumb' );
$image_attributes_large = wp_get_attachment_image_src( $attachment->ID, 'large' );
$image_attributes_full = wp_get_attachment_image_src( $attachment->ID, 'full' );
if ( 1 == $gllr_options['border_images'] ) {
$gllr_border = 'border-width: ' . $gllr_options['border_images_width'] . 'px; border-color:' . $gllr_options['border_images_color'] . '';
$gllr_border_images = $gllr_options['border_images_width'] * 2;
} else {
$gllr_border = '';
$gllr_border_images = 0;
}
if (($url_for_link = get_post_meta($attachment->ID, $link_key, true)) != "") { ?>
<li>
<img alt="<?php echo get_post_meta($attachment->ID, $alt_tag_key, true); ?>" title="<?php echo get_post_meta( $attachment->ID, $key, true ); ?>" src="<?php echo $url_for_link; ?>" />
</li>
<?php } else { ?>
<li rel="gallery_fancybox<?php if ( 0 == $gllr_options['single_lightbox_for_multiple_galleries'] ) echo '_' . $post->ID; ?>">
<img alt="<?php echo get_post_meta($attachment->ID, $alt_tag_key, true); ?>" title="<?php echo get_post_meta( $attachment->ID, $key, true ); ?>" src="<?php echo $image_attributes_large[0]; ?>" />
</li>
<?php }
$count_image_block++;
} ?>
</ul>
<div class="clearfix"></div>
<div id="arrows" class="arrows">
<a id="prev" class="prev" href="#"></a>
<a id="next" class="next" href="#"></a>
</div>
<div id="paginator" class="paginator"></div>
<?php } ?>
</div>
<?php endwhile; else: endif;?>
</div>
The code that is returning the erroneous ID:
<div class="left sidebar">
<?php echo the_ID(); ?>
</div>
This is within a template page, that looks like this:
<?php
/**
* Template Name: 2 Column Left
*/
get_header();
?>
<div id="maincontent">
<div id="content" class="site-content" role="main">
<div class="left sidebar">
<?php
echo the_ID();
?>
</div>
</div>
</div>
<?php get_footer(); ?>
Carousel.php is defined within header.php, and then gets called when get_header(); is called.
So, assuming I'm on the About page, with an ID of 16, and the carousel calls a gallery with page ID of 8, the echo in left-sidebar always returns 8.
I'm at a loss here, I've search high and low for an answer to this problem, but I've come up with nothing.
Try resetting the loop using the wp_reset_query() method.
Place this right after your carousel loop ends.
<?php wp_reset_query(); ?>

Categories