Wordpress - Trying to show user profile images - php

I have the Custom User Profile Photo plugin and I was trying to call the profile images to a loop on the mainpage I am creating. If the user has a post, it should display the post and their profile image. I know I am probably doing something really simple wrong, but for the life of me I cannot figure it out. Right now it will show the same image and name, but the post itself is going to the users posts. Forgive me if it's something stupid. It has been quite a while since I have been in php.
<?php
$posts = get_posts('orderby=author&numberposts=10&category_name=userstories');
foreach($posts as $post){
?>
<ul class="random_user_stories">
<li>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$imgURL = get_the_author_meta('cupp_upload_meta',$author->ID);
$name = get_the_author_meta('first_name'). ' ' .get_the_author_meta('last_name');
echo '<img src="'. $imgURL .'" alt=""/><br/>';
echo "$name's Story";
?>
</a>
</li>
</ul>
<?php endwhile; endif; ?>

Related

Wordpress - Get the thumbnail of the latest post for each category in archive page

I have a custom post type archive page that lists the categories associated with that post type. I would like to include the thumbnail of the latest post in each category as the thumbnail for the said category.
So far I have managed to create the list of the categories, but my attempt at including the latest post thumbnail has resulted in the latest post for the post type as a whole being returned for all categories.
This is how I currently have it below:
<?php if ( $terms && !is_wp_error( $terms ) ) :
?>
<ol class="lister__list">
<?php foreach ( $terms as $term ) { ?>
<li class="lister__item item">
<article class="lister__article">
<a href="<?php echo get_term_link($term->slug, $taxonomy); ?>" class="item__link" title="Permalink to <?php the_title(); ?>" rel="bookmark">
<!--image-->
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumb' );?>
<?php if ( has_post_thumbnail() ) { ?>
<img src="<?php echo $thumb[0]; ?>" width="<?php echo $thumb[1];?>" height="<?php echo $thumb[2];?>" />
<?php } else { ?>
nope
<?php }?>
<h2 class="item__title"><?php echo $term->name; ?></h2>
</a>
</li>
<?php } ?>
</ol>
<?php endif;?>
any help much appreciated.

Wordpress "get_template_part" doesn't appear to be working

I'm not quite sure where I've gone wrong here. One of my template parts that I'm using for listing a bunch of posts of a certain category doesn't seem to be working.
Here is the code where I'm trying to get a template part named "content-offer.php" to display these posts, but it will not show any.
<?php query_posts('cat=3'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php static $count = 0;
if ($count == "4") { break; }
else { ?>
<?php get_template_part( 'content', 'offer', get_post_format() ); ?>
<?php $count++; } ?>
<?php endwhile;
endif;
wp_reset_query(); ?>
Here's what's actually within the template part file:
<div class="offer-box">
<div class="offer-left">
<?php
if(has_post_thumbnail()) {
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
echo '<img src="' . $image_src[0] . '" height="100%" height="auto" />';
}
?>
</div>
<div class="offer-right">
<h2 class="offer-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<p class="offer-text">
<a href="<?php the_permalink(); ?>">
<?php the_excerpt(); ?>
</a>
</p>
<a href="<?php the_permalink(); ?>">
<div class="offer-cta">Claim now!</div>
</a>
</div>
Take note that all my files are in the root folder of the wordpress theme currently, so it's surely nothing to do with sub directories.
I have another area that displays posts with the same method just fine, so I'm confused as to why this one doesn't work.
If anyone can help me out and point where I've gone wrong it would be greatly appreciated.
So, it looks like I had the "content-offer.php" file in the root wordpress folder, not the theme root folder. Oops.

How can I embed a background video into my Wordpress theme using HTML5 and without using a plugin?

I'm attempting to add a background video to a wordpress website in place of the large image that is currently there.
I understand how to set up the video with HTML5 and CSS, but am not very familiar with php and am kind of lost on where to begin when it comes to writing a function to pull the video/s (wmp and mp4) from the media library and display them.
Any guidance on how to go about this would be much appreciated. Thanks!
I know that this is the part of the code that needs to be modified:
<div class="intro-block">
<?php if ( has_post_thumbnail() ):?>
<?php the_post_thumbnail('full'); ?>
<?php else: ?>
<?php
$image = get_field('global_intro_image', 'option');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" >
<?php endif; ?>
<?php endif; ?>
<div class="text-holder">
<div class="container">
<?php if( $title = get_field( 'title' )) : ?>
<h1><?php echo $title; ?></h1>
<?php endif; ?>
<?php if( $find_btn_link = get_field( 'find_btn_link' )) : ?>
<?php echo get_field( 'find_btn_text' ); ?>
<?php endif; ?>
</div>
</div>
</div>
It currently pulls the featured image for the page and displays it.
Any suggestions on where to begin?
Thanks in advance!
First you need to find out which part is calling the image. Looks like this part:
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" >
<?php endif; ?>
Then comment out this part or just remove this part of the code and replace if with video tag and style it so it looks just as you need.
Then if you need to be able to indicate videos from wordpress back end, than you need to create options page / or only add fields if you have theme options page.
https://codex.wordpress.org/Creating_Options_Pages
Even easier is to create options pages with ACF pro

WordPress Default Featured Image

I’ve got a WordPress site and have added the following code to the Single.php file, which means if I publish a blog post without selecting a ‘Featured Image’, it will display a default ‘Featuered Image’ instead (tellymedia-temporary-image.jpg).
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/branding/tellymedia-temporary-image.jpg" alt="<?php the_title(); ?>" />
This works fine on the actual page displaying the individual blog post (which shows the default image), but I’m also using the following code in my Functions.php file, to display a ‘Featured Image’ thumbnail for each post in the Sidebar:
<span class="widget-listing-thumbnail"><?php the_post_thumbnail(); ?></span><?php get_the_title() ? the_title()+the_subtitle('<span class="widget-subtitle">', '</span class="widget-subtitle">') : the_ID(); ?>
While this works for all other posts it doesn’t work for any where I haven’t selected a ‘Featued Image’. Is there a way to tweak the code in my Functions.php file please, so it will also display a thumbnail of the default ‘Featuered Image’ in the Sidebar for posts where I haven’t selected one please?
Thanks!
try this one.
<a href="<?php the_permalink(get_the_id()); ?>">
<span class="widget-listing-thumbnail">
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/branding/tellymedia-temporary-image.jpg" alt="<?php the_title(); ?>" />
?>
</span>
<?php get_the_title() ? the_title() + the_subtitle('<span class="widget-subtitle">', '</span class="widget-subtitle">') : the_ID(); ?>
</a>

Displaying 1 post from a particular catergory if selected in wordpress

I'm trying to make a loop in wordpress that pulls in 1 post from 1 category when selected, But if not it should display the latest post from the custom post type I'm calling. e.g Testimonials, Latest News, Case Studies.
Here is what I have, do I need an ifelse; statement to query if the cat doesn't exist then display the latest post in that CPT.
Here is the code I have.
<?php
$query = new WP_Query('post_type=testimonial&catergory_name=home&showposts=1&paged=' . $paged);
$postcount = 0;
?>
<?php if ($query->have_posts()) : ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<?php $postcount++; ?>
<li>
<a href="<?php the_permalink(); ?>">
<?php
if (has_post_thumbnail()) {
// check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail('thumb-casestudy');
}else {
?>
<img src="<?php bloginfo('template_url'); ?>/assets/images/default.jpg" alt="<?php the_title(); ?>"/>
<?php } ?>
</a>
<h4><?php the_title(); ?></h4>
<p class="hm_text"><?php
//the_excerpt();
echo get_post_meta($query->post->ID, 'wpld_cf_home_page_text', true)
?></p>
</li>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
If I understand You correctly:
$query->post_count
should allow You to check if there are any post returned by query, and if not, than You can call another query.

Categories