Multiple custom fields causing double posts on page - php

I am using Magic Fields to create categorized image galleries. I have created 3 different custom fields (port_thumb, illustration_thumb, photo_thumb) so that I can post my thumbnail image to one of 3 different sections. Is there something I can do to keep each post separate to its designated field? Essentially what happens when I create a post for say 'port_thumb,' the thumbnail image loads up and everything is fine in that section. But then lower on the page in both of the other 2 sections an invisible link for the port_thumb shows up as well as loading in the css for that section. Is there some code I can add to prevent each post from showing up 3 times on the page?
<?php get_header();
/*Template Name: Portfolio*/
?>
<div id="main">
<!--TYPOGRAPHY-->
<div class="typography">
<div class="title1">
</div>
<ul>
<?php query_posts( 'category_name=portfolio' ); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php //the_title_attribute(); ?>">
<li><?php echo get_image('port_thumb');?></li>
</a>
<?php endwhile; ?>
<?php //next_posts_link('Older Entries') ?>
<?php //previous_posts_link('Newer Entries') ?>
<?php else : ?>
<?php endif; ?>
</ul>
<!--end typography-->
</div>
<!------ BEGIN ILLUSTRATION-->
<div class="illustration">
<div class="title2">
</div>
<ul>
<?php query_posts( 'category_name=portfolio' ); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>">
<li><?php echo get_image('illustration_thumb');?></li>
</a>
<?php endwhile; ?>
<?php //next_posts_link('Older Entries') ?>
<?php //previous_posts_link('Newer Entries') ?>
<?php else : ?>
<?php endif; ?>
</ul>
<!--end ILLUSTRATION-->
</div>
<!--- PHOTOGRAPHY--->
<div class="photography">
<div class="title3">
</div>
<ul>
<?php query_posts( 'category_name=portfolio' ); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>">
<li><?php echo get_image('photo_thumb');?></li>
</a>
<?php endwhile; ?>
<?php //next_posts_link('Older Entries') ?>
<?php //previous_posts_link('Newer Entries') ?>
<?php else : ?>
<?php endif; ?>
</ul>
<!--end image-->
</div>
<!--end main-->
</div>
<!--content end-->

I am not sure what you are asking, and I am not even good at this (PHP).
But if I look at you question, you are trying to post a thumnail image into three different divs/wrappers/files, and then your problem is that the thumnail image you post into that three different "things" are not as how you expect. I think the solution is to have a look to each class or id of them then solve their CSS style.

Related

Customise wordpress theme search.php to include product image

I want my search results to show an image of the product. Currently the search results only show a text link. My wordpress theme is Intuition Pro and the website is https://heritagecountrypottery.com. I am also using the Ivory search wordpress plugin
<?php get_header(); ?>
<div id="main" class="main">
<div class="container">
<section id="content" class="content">
<?php do_action('cpotheme_before_content'); ?>
<?php if(have_posts()): while(have_posts()): the_post(); ?>
<article class="search-result" id="post-<?php the_ID(); ?>">
<h4 class="search-title heading">
<?php the_title(); ?>
</h4>
<div class="search-byline">
<?php the_permalink(); ?>
</div>
</article>
<?php endwhile; ?>
<?php cpotheme_numbered_pagination(); ?>
<?php endif; ?>
<?php do_action('cpotheme_after_content'); ?>
</section>
<?php get_sidebar(); ?>
</div>
</div>
<?php get_footer(); ?>
I have searched online for a solution but have not found one that works with my theme
You can get the post thumbnail like this
<?php if ( has_post_thumbnail() ): ?>
<div class="search-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</div>
<?php endif; ?>
You can add it before the heading, but you need to figure out the CSS rules you have to apply to make it looks good.

How to load the next page using ajax in a WordPress loop?

I want to load page2 with AJAX in my dynamic posts loop. I searched for some possible ways and found this guide https://unicorntears.dev/snippets/load-more-posts/ but it didn't come out to be working.
I want to load the next page in the post loop by AJAX, by simply clicking a load more button.
Archive.php I am currently using is
<?php get_header(); ?>
<main class="main-content">
<div class="inner">
<?php if(have_posts()): ?>
<ul class="product-list">
<?php while(have_posts()):the_post(); ?>
<li class="list-product">
<a href="<?php the_permalink(); ?>">
<div class="product-thumbnail">
<img class="lazyload" data-src="<?php the_post_thumbnail_url(); ?>" />
</div>
<h2 class="product-title"><?php the_title(); ?></h2>
<span class="product-price"><?php if($product->is_type('variable')){echo variable_price_html();}elseif($product->is_type('simple')){echo simple_price_html();} ?></span>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
</div>
</main>
<?php get_footer(); ?>
Since I am not familiar with JS, I want someone's help. Please someone help me make this happen.

Wordpress WP_query returns only the current page regardless of arguments

In my wordpress frontpage I'm using query_posts to show posts from the blog.
However, I head that using query_posts is a bad practice, so I'm rewriting the code using WP_query. The problem is that WP_query only returns the current page when I do this, regardless of the fact that I explicitly tell wordpress to look for posts, not pages:
<?php $que = new WP_query(array('post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>2));
if(have_posts()): while(have_posts()): the_post(); ?>
<a href="<?php the_permalink(); ?>">
<p class="date">
<?php the_date();?>
</p>
<h4>
<?php the_title();?>
</h4>
</a>
<?php endwhile; endif;?>
Your code is incorrect, try this instead (do you notice the difference?):
<?php
$the_query = new WP_Query(array('post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>2));
if($the_query->have_posts()): while($the_query->have_posts()): $the_query->the_post(); ?>
<a href="<?php the_permalink(); ?>">
<p class="date">
<?php the_date();?>
</p>
<h4>
<?php the_title();?>
</h4>
</a>
<?php endwhile; endif;?>
Try this :
<?php $que = new WP_query(array('post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>2));
if($que->have_posts()): while($que->have_posts()): $que->the_post(); ?>
<a href="<?php the_permalink(); ?>">
<p class="date">
<?php the_date();?>
</p>
<h4>
<?php the_title();?>
</h4>
</a>
<?php endwhile; endif;?>

WP - Archive.php - Not showing all posts in a category

I am not finding out why archive.php only shows maximum 10 posts in a category... Could you please help to find where the bug is?
<div id="blogg_header" class="col col-lg-12 col-sm-12"><div class="well">
<?php if (is_category()) {?>
<h1 class="title">Kategori: <i><?php single_cat_title(); ?> </i></h1>
<?php } elseif (is_month()) { ?>
<h2 clss="title"><?php the_time('F, Y'); ?></h2>
<?php } ?>
</div></div>
<div id="blogg_innlegg_left" class="col col-lg-8 col-sm-8"><div class="well">
<ul>
<?php if (have_posts()) :?>
<?php while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<a class id="linkforside" href="<?php the_permalink(); ?>">
<?php get_the_post_thumbnail($header_thumb->ID);?><br/>
</a>
<p class id="infotekst"><?php the_time('d.m.Y') ?></p>
<p class="blogg_innlegg_teksten"><?php echo substr(strip_tags($post->post_content), 0, 250);?></p>
<?php endwhile; ?>
<?php else : ?>
<h2>Ingenting ble funnet.</h2>
<?php endif; ?>
</ul>
</div></div>
I guess I may need to insert the following:
<?php wp_get_archives('type=postbypost&limit=none'); ?>

Wordpress pagination issue with post_type('page')

I am having a great problem with pagination using a custom template(page-location.php).
I created a custom loop in that template to query child pages. Everything looks great so far except the pagination's not showing up. I tried both with plugins and wordpress default pagination functions. What am I doing wrong here? Can you please give me a moment and explain why it's not showing up? Thanks in advance! Please have a look at the codes! I tried every solutions out there.. This site is my last hope. ***Please note that post_type = 'page', not POST.
<?php
/*
Template Name: Location Template
*/
?>
<?php get_header(); ?>
<?php $options = get_option('katerina_custom_settings'); ?>
<div class="container main-content">
<h1><?php wp_title(''); ?></h1>
<div class="row">
<?php $this_page_id=$wp_query->post->ID; ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$my_query = new WP_Query("post_type=page&post_parent=$this_page_id&posts_per_page=2&paged=$paged");
if ($my_query->have_posts() ) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('article span4 clearfix'); ?>>
<?php if (has_post_thumbnail()) : ?>
<figure class="article-preview-image">
<?php the_post_thumbnail(); ?>
</figure>
<?php endif; ?>
<article class="content clearfix">
<?php if (get_the_title() != '') : ?>
<h2><?php the_title(); ?></h2>
<?php else : ?>
<?php _e('Permalink to the post', 'adaptive-framework'); ?>
<?php endif; ?>
<?php the_content(); ?>
Details
</article>
<div class="meta-data clearfix">
<ul class="meta-comments pull-left">
<li class="article-meta-comments">
<?php
// Only show the comments link if comments are allowed and it's not password protected
if (comments_open() && !post_password_required()) {
comments_popup_link('0', '1', '%', 'article-meta-comments');
}
?>
</li>
<li class="article-meta-like">10</li>
</ul>
<ul class="social-share pull-right">
<li class="fb">Share on Facebooks</li>
<li class="google">Share via Google</li>
<li class="twitter">Share via Twitter</li>
</ul>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</div>
<!-- end row -->
</div>
<div class="container">
<div class="pagination pull-right">
<?php if(function_exists('tw_pagination'))
tw_pagination();
?>
</div>
</div>
<!-- end main-content -->
<?php get_footer(); ?>
You should try this
<div class="pagination pull-right">
<?php if(function_exists('tw_pagination'))
tw_pagination($my_query);
?>
</div>

Categories