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.
Related
The featured thumbnail image is supposed to just show the single thumbnail image of the post but instead it pulls every post image and displays them instead for every post. Instead of just the post thumbnail. This is the code for it and also what it looks like on the page:
<?php $featured_image = new WP_Query('page_id=ID'); ?>
<?php while ($featured_image->have_posts()) : $featured_image->the_post(); ?>
<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) { ?>
<?php $img_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(302, 170)); ?>
<div class="the-image">
<img src="<?php echo $img_src[0]; ?>" />
</div>
<?php }; ?>
<?php endwhile; ?>
thats the code for servering the image and heres what happens on the main page (I have 2 posts currently and a featured test image for both of them, the scaling works but as you can see, it puts both images, on both posts...)
I'm not sure if it needs to be inside my loop for the title and excerpt, or outside of it (currently inside).
Here is the full code for the recent posts sidebar:
<div class="col-lg-4 d-none d-lg-block">
<h3 style="text-align: center; font-weight: 700;">Recent Posts</h3>
<?php
$result = wp_get_recent_posts(array(
'numberposts' => 10,
'category' => '',
'post_status' => 'publish',
));
foreach( $result as $p ){
?>
<div class="paddingarea text-dark">
<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) { ?>
<?php $img_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(302, 170)); ?>
<div class="the-image">
<img src="<?php echo $img_src[0]; ?>" />
</div>
<?php }; ?>
<a class="card-title" href="<?php echo get_permalink($p['ID']) ?>" style="font-weight: 600;"><?php echo $p['post_title']?></a><br />
<p class="card-text"><?php echo excerpt(10); ?></p>
</div>
<?php
}
?>
</div>
Try this, it's simple and it's working for me:
<?php
$result = wp_get_recent_posts(array(
'numberposts' => 10,
'category' => '',
'post_status' => 'publish',
));
foreach( $result as $p ){
?>
<div class="paddingarea text-dark">
<div class="the-image">
<img src="<?php echo get_the_post_thumbnail_url($p['ID'], array(302, 170)); ?>" />
</div>
<a class="card-title" href="<?php echo get_permalink($p['ID']) ?>" style="font-weight: 600;"><?php echo $p['post_title']?></a><br />
<p class="card-text"><?php //echo excerpt(10); ?></p>
</div>
<?php
}
?>
I am working on a site with a page that has multiple sections, each section has multiple loops featuring multiple categories. I use Ajax Load More plugin to load new posts for each sections. The issue is when I click on Load More, it loads both the posts already shown and the one that hasn't been shown. I want it to load only new posts not already shown.
Here is the shortcode I used:
echo do_shortcode('[ajax_load_more container_type="div" post_type="post" posts_per_page="3" preloaded="true" preloaded_amount="4" pause="true" scroll="false" button_loading_label="Loading..." seo="true" category="church-music-news"]');
Here is the loop on on of the sections
<div class="row">
<div class="col-lg-12 col-sm-12">
<div class="music_box bg-color1">
<div class="music_box_top">
<?php
$sticky = get_option( 'sticky_posts' );
rsort( $sticky );
$args = array(
'post__in' => $sticky,
'posts_per_page' => 1,
'cat' => 34
);
$sticky_query = new WP_Query( $args );
while ( $sticky_query->have_posts() ) : $sticky_query->the_post();
?>
<a href="<?php the_permalink(); ?>">
<div class="fashion_box_thumb">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'full', array() );
}
?>
</div>
</a>
<div class="fashion_box_text">
<a href="<?php the_permalink(); ?>">
<h3><?php the_title(); ?></h3>
</a>
<p><?php the_excerpt(); ?></p>
<div class="post_cont_icons">
<span class="fa fa-comments cmnt"> <?php comments_number('0','1','%'); ?></span>
<?php echo getPostLikeLink(get_the_ID());?>
<span class="matchtime2"><i class="fa fa-clock-o"></i> <?php the_time();?><br></span>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<div class="clear"></div>
</div><!--music_box_top-->
<div class="fashion_box_bottom">
<?php
$args = array(
'post__not_in' => get_option( 'sticky_posts' ),
'posts_per_page' => 4,
'cat' => 34
);
$sticky_query = new WP_Query( $args );
$count = 0;
while ( $sticky_query->have_posts() ) : $sticky_query->the_post(); ?>
<?php $count++; ?>
<?php if ($count == 1) :
?>
<div class="fashion_box_bottom_item">
<a href="<?php the_permalink(); ?>">
<h4><?php the_title(); ?></h4>
</a>
</div>
<?php elseif ($count == 2) : ?>
<div class="fashion_box_bottom_item">
<a href="<?php the_permalink(); ?>">
<h4><?php the_title(); ?></h4>
</a>
</div>
<?php elseif ($count == 3) : ?>
<div class="fashion_box_bottom_item">
<a href="<?php the_permalink(); ?>">
<h4><?php the_title(); ?></h4>
</a>
</div>
<?php elseif ($count == 4) : ?>
<div class="fashion_box_bottom_item">
<a href="<?php the_permalink(); ?>">
<h4><?php the_title(); ?></h4>
</a>
</div>
<div class="clear"></div>
</div><!--music_box_bottom-->
</div><!--music_box-->
</div><!--col-lg-12-->
<?php else :
get_template_part( 'woodclefpro/pro_template3' );
endif;
endwhile;
wp_reset_postdata(); ?>
</div><!--row-->
<div class="row">
<?php
echo do_shortcode('[ajax_load_more container_type="div" post_type="post" posts_per_page="3" preloaded="true" preloaded_amount="4" pause="true" scroll="false" button_loading_label="Loading..." seo="true" category="church-music-news"]');
?>
</div>
This is for those that might come across the question above and are facing the same issue that I was. Here is how I solved it.
Add the code below right before endwhile
$do_not_duplicate[] = $post->ID;
Add this inside your shortcode: post__not_in="'.$post__not_in.'"
Then your final shortcode looks like this:
echo do_shortcode('[ajax_load_more ajax_load_more post__not_in="'.$post__not_in.'" container_type="div" post_type="post" posts_per_page="3" preloaded="true" preloaded_amount="4" pause="true" scroll="false" button_loading_label="Loading..." seo="true" category="church-music-news"]');
Not quite right. The fact is that on the page of one of the Addons to this plugin say that the template output single entry, for example "single.php" should be nothing but a shortcode. All content single.php should be placed in the template used by the plugin. Sorry for the crooked English.
https://connekthq.com/plugins/ajax-load-more/add-ons/single-posts/
Note: Ajax Load More will take care of loading ALL posts, including
the initial post when a user lands on the page. All that should remain
in your single.php loop is the ajax_load_more shortcode (as seen
above).
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 } ?>
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; ?>
I have a problem. I would like to show one time one post and one time 5 posts with this code but he shows two porst more than necessary. What I don't get, is that it's another site of me with the same theme does work. The completely same theme only a others website. Who can help me?! (check the wrong result http://radiozuid.com/ an websie correct result http://radiozuid.rtv-zuid.com/beta/ ) (Exact same theme)
<?php
$the_query = new WP_Query(array(
'posts_per_page' => 1
));
while ( $the_query->have_posts() ) :
$the_query->the_post();
?>
<div class="item active">
<?php if(has_post_thumbnail()): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'small-nivo-thumb'); ?>
<img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo $image[0]; ?>&w=620&h=350" class="postafbeelding" alt="<?php the_title(); ?>">
<?php else: ?>
<img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo get_template_directory_uri(); ?>/images/thumbnail.png&w=620&h=350" class="postafbeelding" alt="<?php the_title(); ?>">
<?php endif; ?>
<div class="carousel-caption">
<h3 class="titel"><?php the_title();?></h3>
<p><?php echo string_limit_words(get_the_excerpt(), 35); ?>... Lees Meer</p>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
<?php
$the_query = new WP_Query(array(
'posts_per_page' => 5,
'offset' => 1
));
while ( $the_query->have_posts() ) :
$the_query->the_post();
?>
<div class="item">
<?php if(has_post_thumbnail()): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'small-nivo-thumb'); ?>
<img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo $image[0]; ?>&w=620&h=350" class="postafbeelding" alt="<?php the_title(); ?>">
<?php else: ?>
<img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo get_template_directory_uri(); ?>/images/thumbnail.png&w=620&h=350" class="postafbeelding" alt="<?php the_title(); ?>">
<?php endif; ?>
<div class="carousel-caption">
<h3 class="titel"><?php the_title();?></h3>
<p><?php echo string_limit_words(get_the_excerpt(), 35); ?>... Lees Meer</p>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
The problem is that your query is returning sticky posts, which for whatever reason are tacked onto the post limit rather than counting as part of it. Add ignore_sticky_posts to your query and I think that will fix it.
$the_query = new WP_Query(array(
'posts_per_page' => 5,
'offset' => 1,
'ignore_sticky_posts' => true
));