Linking an image to the post it's associated with - php

I am using 'Advanced Custom Fields' and i have created an archive page to display posts from a custom post type of 'property_sales'
this is the full template
<article <?php post_class(); ?>>
<header>
<h2 class="entry-title"><?php the_title(); ?></h2>
</header>
<div class="location">
<?php the_field('location')?>
</div>
<div class="photoframe">
<img class="responsive" src="<?php the_field('property_image')?>" />
</div>
<div class="price">£
<?php the_field('price')?>
</div>
<div class="entry-summary">
<p>Added on <?php get_template_part('templates/property-meta'); ?></p>
</div>
<div class="rightmovelink">
View Full Listing
</div>
<div class="clear">
</article>
I was wondering what code I need to put in the tag in order to link to the post each image is associated with?

Try this one
<div class="photoframe">
<img class="responsive" src="<?php the_field('property_image')?>" />
</div>

Related

Displaying wordpress page full contents

Here is LINK I am working on it. The About Us section is not displaying full contents and showing more button to go to next page whereas I want to show full contents of About Us page instead of short summary.
I checked a lot but not found any option in the theme to fix it
UPDATE:
I found this in (page-template/custom-home-page.php)
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="row">
<div class="col-lg-8 col-md-7">
<h3><?php the_title(); ?></h3>
<hr>
<p><?php the_excerpt(); ?></p>
<div class="more-btn">
<?php esc_html_e('MORE','vw-one-page'); ?>
</div>
</div>
<div class="col-lg-4 col-md-5">
<img src="<?php the_post_thumbnail_url('full'); ?>"/>
</div>
</div>
<?php $i++; endwhile;
wp_reset_postdata();?>
<?php else : ?>
<div class="no-postfound"></div>
<?php endif;
endif;?>
</div>
</section>
Best regards
That code inside your theme with high probability.
Try to search inside theme files "/wp-content/themes/your_theme_name", something like that:
<div class="col-lg-8 col-md-7">
<h3>About Us</h3> <!-- Or <?php the_title(); ?> -->
<hr>
<?php the_exerpt(); ?>
<div class="more-btn">
MORE <!-- Or something like <?php the_permalink( ... ) ?> -->
</div>
</div>
This is an example. After all, I can't know how it is done in your theme.
Then <?php the_exerpt(); ?> change to <?php the_content(); ?>. and remove or hide:
<div class="more-btn">
...
</div>
But if this is not your personal WordPress theme, then it is better to do through Child Theme

Slick Slider Wordpress Custom Post Type

I have a static slick slider which I use to run testimonials on, instead of being hard typed I want to pull them from WordPress custom post type which I have set up can someone point me in the right direction:
<section class="testimonials">
<div class="container text-center">
<div class="row">
<div class="col-md-12">
<div class="slick-testimonial">
<div class="item">
<div class="testimonial">
<img src="<?php bloginfo('template_url'); ?>/images/icons/testimonals.png" class="center-block">
<h1>What our customers say</h1>
<h3>"Fantastic service"</h3>
<p>Review Text Here</p>
<p class="name">Customer Name 1</p>
</div>
</div>
<div class="item">
<div class="testimonial">
<img src="<?php bloginfo('template_url'); ?>/images/icons/testimonals.png" class="center-block">
<h1>What our customers say</h1>
<h3>"Excellent"</h3>
<p>Review Text Here</p>
<p class="name">Customer Name 2</p>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
i believe i need to pull up an array for the custom post type and in the item pull the title name and text but not sure how to write it thanks.
You just need to interact with WordPress' WP_Query Class. It's the de facto way to get a handful of posts.
I'd also consider restructuring your slider a bit so the "What our Customers Say" is outside the individual slide item, but I digress:
All you have to do is set up a new WP_Query and replace the item div with a simple while loop:
<?php
$slider_args = array(
'post_type' => 'testimonials',
'posts_per_page' => 10
);
$slider_query = new WP_Query( $slider_args );
?>
<section class="testimonials">
<div class="container text-center">
<div class="row">
<div class="col-md-12">
<div class="slick-testimonial">
<?php
if( $slider_query->have_posts() ){
while( $slider_query->have_posts() ){ $slider_query->the_post(); ?>
<div class="item">
<div class="testimonial">
<img src="<?php bloginfo('template_url'); ?>/images/icons/testimonals.png" class="center-block">
<h1>What our customers say</h1>
<h3><?php the_title(); ?></h3>
<p><?php the_content(); ?></p>
<p class="name"><?php echo get_post_meta( get_the_ID(), 'reviewer_name', true ); ?></p>
</div>
</div>
<?php }
} else { ?>
<div class="item">
<div class="testimonial">
<h3>No Testimonials Found</h3>
</div>
</div>
<?php }
wp_reset_postdata();
?>
</div>
</div>
</div>
</div>
</section>
Note that this code makes a few assumptions. You'll need to replace the post_type with the name of the CPT you have registered, and you can adjust how many to get with the posts_per_page argument. I picked 10 just because.
This also assumes you're saving the Reviewer Name in a meta field named reviewer_name, but it should be enough to get you started

Wordpress - How to use Ajax Load More plugin

I'm developing a website in wordpress and I want to load more news when scrolling but I already have a html structure and when I put ajax load more it put own structure and I don' want that.
I'm using the Ajax Load More plugin.
So, How can I use Ajax load more with this html structure:
<?php
$posts = get_posts(['cat' => get_cat_ID("news")]);
foreach($posts as $post){
setup_postdata($post);
?>
<div class="col-xs-12 col-sm-6 col-md-4">
<a class="news-link" href="<?php the_permalink() ?>">
<div class="news">
<div class="image">
<?php the_post_thumbnail('thumbnail') ?>
<div class="mask">
<div class="icon">
<i class="icon-plus"></i>
</div>
</div>
</div>
<div class="title">
<span>
<?php the_title(); ?>
</span>
</div>
<div class="excerpt">
<p class="date">
<?php echo get_the_date('Y-m-d'); ?>
</p>
</div>
<div class="excerpt">
<p>
<?php the_excerpt(); ?>
</p>
</div>
</div>
</a>
</div>
<?php
wp_reset_postdata();
} ?>
If i put this shortcode it shows but not with the structure that i want.
[ajax_load_more id="7279302844" container_type="div" post_type="post" category="news"]
Thank you

Not able to get post data from ajax call - wordpress

I have an Ajax call loading more posts onto a page. Everything works and I get the HTML back from the template that I have but it's missing all the of post information so it's just the html skeleton.
I'm using the same template to load the first posts onto the page but then when using the ajax call, I can't get the Wordpress methods to display back the data.
When I var dump on my template php file, I can see all of the post information but it doesn't come through back to the inline php.
Loading the Posts:
foreach (load_posts($offset) as $post) {
include(locate_template('_includes/loop-archive-single.php'));
}
The Template:
<li>
<div class="card">
<div class="card__bd">
<div class="feature">
<div class="feature__media">
<a class="imgLink" href="<?php the_permalink(); ?>">
<img src="<?php the_field('media_image') ?>" alt="<?php the_field('media_image') ?>" />
</a>
</div>
<div class="feature__hd">
<h2 class="hdg hdg--lg">
<?php the_title(); ?>
</h2>
</div>
<div class="feature__bd">
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
</li>
Am I outside the loop or what's going on? I'd like to keep the template that way it is right now. Again, the post data is there, but it just won't show through the_permalink() or the_field('media_image') and anything like that...
You will have to pass the ID on ajax call ... of which post you need
change the template file to
<li>
<div class="card">
<div class="card__bd">
<div class="feature">
<div class="feature__media">
<a class="imgLink" href="<?php the_permalink(); ?>">
<img src="<?php the_field('media_image',$post_ID) ?>" alt="<?php the_field('media_image',$postID) ?>" />
</a>
</div>
<div class="feature__hd">
<h2 class="hdg hdg--lg">
<?php the_title(); ?>
</h2>
</div>
<div class="feature__bd">
<?php the_excerpt($postID); ?>
</div>
</div>
</div>
</div>
</li>

Wordpress - Search page for custom post type

I started to use Wordpress for a project, and using the following plugin Download Monitor
My page listings based on taxonomies all work fine, but im struggling with the search results
My form
<form role="search" method="get" class="right" id="download-form" action="<?php echo home_url( '/' ); ?>">
<div>
<input type="text" value="" name="dlm_download" id="dlm_download" placeholder="Search" />
</div>
</form>
So when i search and get the results mywebsite.com/?dlm_download=querythe home page gets show.
Than i created after research search-dlm_download.php, still get redirected to home.
Than i found this thread How to create a custom search for custom post type on wordpress exchange that does not work either.
So i am a bit stuck, could someone please point out what i am doing wrong?
EDIT:
search-dlm_download.php
<?php get_header(); ?>
<?php if (have_posts()) : ?>
<div id="page" class="border-top clearfix">
<div id="subtitle">
<h1><?php _e("Search Results for '$s'", 'framework') ?></h1>
<div id="breadcrumb"><?php the_breadcrumb(); ?></div>
<div class="hr4"><span class="seperator"></span><span class="lightborder"></span></div>
</div>
<div id="content-part">
<?php while (have_posts()) : the_post(); ?>
<div class="search-entry post-entry">
<h2><?php the_title(); ?></h2>
<div class="meta">
<?php _e('Posted on', 'framework'); ?> <strong><?php the_time('d.m.Y'); ?></strong> · <?php _e('Posted in', 'framework'); ?> <?php the_category(', ') ?>
</div>
<div class="entry">
<?php wpe_excerpt('wpe_excerptlength_blog', 'wpe_excerptmore'); ?>
</div>
<div class="entry-footer"></div>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/framework/functions/nav.php' ); ?>
</div>
<div id="sidebar" class="sidebar-right">
<?php get_sidebar(); ?>
</div>
</div>
<?php else : ?>
<div id="page" class="border-top clearfix">
<div id="subtitle">
<h1><?php _e('No Results Found', 'framework') ?></h1>
<div id="breadcrumb"><?php the_breadcrumb(); ?></div>
<div class="hr4"><span class="seperator"></span><span class="lightborder"></span></div>
</div>
<div class="wrap clearfix">
<div id="content-part">
<div class="no-search-result">
<p><?php _e("Sorry, no results found. Try different words to describe what you are looking for.", 'framework') ?></p>
</div>
</div>
<div id="sidebar" class="sidebar-right">
<?php get_sidebar(); ?>
</div>
</div>
</div>
<?php endif; ?>
<?php get_footer(); ?>
Okay, found a solution by breaking the default search to 2 parts
If anybody needs it in the future you can find it here Create multiple search templates for custom post types

Categories