I created a custom template for the homepage. I want to call the content after the portfolio, but it doesn't work. I can't find where I made a mistake. It works when I call above the portfolio. Anyone know how I could accomplish this?
<section id="portfolio" class="portfolio atop">
<!-- Portfolio Filter -->
<div class="portfolio_filter">
<ul>
<?php $categories = get_categories("taxonomy=categories");
foreach ($categories as $category) : echo '<li><a data-filter=".' . $category->slug . '" href="#">' . $category->name . '</a></li>';
endforeach; ?>
<li><a class="select-cat" data-filter="*" href="#">All Works</a></li>
</ul>
</div>
<div class="container">
<div class="row masonry clearfix">
<!-- a work -->
<?php $args = array(
'post_type' => 'portfolio',
'orderby' => 'date',
'order' => 'ASC',
'posts_per_page' => 100,
);
$wp_query = new WP_Query($args);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php $portcolor = get_field('text_color_of_featured_image'); ?>
<?php $taxonomy = 'categories';
$terms = get_the_terms($post->ID, 'categories'); ?>
<?php foreach ($terms as $term) ?>
<a href="<?php echo esc_html(get_permalink()); ?>" class="col-xl-4 col-md-6 grid-item <?php echo esc_html($term->slug); ?> <?php echo esc_attr($portcolor); ?>" data-type="ajax-load">
<figure class="portfolio-item <?php $portfolio_type = get_field('portfolio_type');
echo esc_attr($portfolio_type); ?>">
<div class="image">
<?php $featured_image = get_field('portfolio_featured_image'); ?>
<img src="<?php echo esc_url($featured_image['url']); ?>" alt="<?php echo esc_attr($featured_image['alt']); ?>" />
</div>
<figcaption>
<span><?php echo esc_html($term->name); ?></span>
<h3 class="title"><?php the_title(); ?></h3>
</figcaption>
</figure>
</a>
<?php endwhile; ?>
</div>
</div> <!-- container end -->
</section>
<?php the_content(); ?>
You need to reset the global post after your custom WP_Query with wp_reset_postdata(). See below:
<section id="portfolio" class="portfolio atop">
<!-- Portfolio Filter -->
<div class="portfolio_filter">
<ul>
<?php $categories = get_categories("taxonomy=categories");
foreach ($categories as $category) : echo '<li><a data-filter=".' . $category->slug . '" href="#">' . $category->name . '</a></li>';
endforeach; ?>
<li><a class="select-cat" data-filter="*" href="#">All Works</a></li>
</ul>
</div>
<div class="container">
<div class="row masonry clearfix">
<!-- a work -->
<?php $args = array(
'post_type' => 'portfolio',
'orderby' => 'date',
'order' => 'ASC',
'posts_per_page' => 100,
);
$wp_query = new WP_Query($args);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php $portcolor = get_field('text_color_of_featured_image'); ?>
<?php $taxonomy = 'categories';
$terms = get_the_terms($post->ID, 'categories'); ?>
<?php foreach ($terms as $term) ?>
<a href="<?php echo esc_html(get_permalink()); ?>" class="col-xl-4 col-md-6 grid-item <?php echo esc_html($term->slug); ?> <?php echo esc_attr($portcolor); ?>" data-type="ajax-load">
<figure class="portfolio-item <?php $portfolio_type = get_field('portfolio_type');
echo esc_attr($portfolio_type); ?>">
<div class="image">
<?php $featured_image = get_field('portfolio_featured_image'); ?>
<img src="<?php echo esc_url($featured_image['url']); ?>" alt="<?php echo esc_attr($featured_image['alt']); ?>" />
</div>
<figcaption>
<span><?php echo esc_html($term->name); ?></span>
<h3 class="title"><?php the_title(); ?></h3>
</figcaption>
</figure>
</a>
<?php endwhile;
// reset global post data
wp_reset_postdata();?>
</div>
</div> <!-- container end -->
</section>
<?php the_content(); ?>
Related
I created a custom post type called Programs, Each program contains episodes
Episodes will be Child Post
Some programs contain more than a hundred episodes, so I want to add pagination to my child posts list
I've had a basic attempt at this using $paged = (get_query_var('page')) ? get_query_var('page') : 1; and the paged argument in the WP_Query, but my next_posts_link doesn't work. my code to show child post
<?php
$args = array(
'post_type' => 'programs',
'posts_per_page' => 60,
'post_parent' => $post->ID,
'order' => 'ASC',
);
$parent = new WP_Query( $args );
if ( $parent->have_posts() ) : ?>
<div class="penci-border-arrow penci-homepage-title penci-magazine-title style-5 pcalign-right pciconp-right pcicon-right" style="border-color: #3E68B0">
<h3 class="inner-arrow" style="background:#3E68B0;border-color: #3E68B0">
الحلقات </h3>
</div>
<ul class="penci-wrapper-data penci-grid">
<?php while ( $parent->have_posts() ) : $parent->the_post();
$featured_img_url = get_the_post_thumbnail_url(get_the_ID());
$episode_number = get_field('episode_number', get_the_ID());
?>
<li class="list-post pclist-layout">
<article id="post-<?php the_ID(); ?>" class="item hentry">
<div class="thumbnail child-thumbnail">
<a class="penci-image-holder penci-lazy" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" style="background-image: url(<?php echo $featured_img_url?>);">
</a>
</div>
<div class="content-list-right content-list-center child-content">
<div class="header-list-style">
<div class="episode-details">
<span class=""> <a class="url fn n" href="<?php the_permalink(); ?>"><?php echo $episode_number ?></a></span>
<span style="margin:0 20px"><a>|</a></span>
<span class="featc-date"><time class="entry-date published" datetime="2021-10-31T13:26:29+00:00">2021-10-31</time>
</span>
<span class='program-viewcn'><?php pvc_stats_update( get_the_ID(), 1 ); ?></span>
</div>
<h2 class="grid-title entry-title">
<?php the_title(); ?>
</h2>
</div>
<div class="item-content entry-content">
<p>
<?php the_excerpt();?>
</p>
</div>
</div>
</article>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
I created custom post type and child post , i want to add pagination to child post , I've had a basic attempt at this using $paged = (get_query_var('page')) ? get_query_var('page') : 1; and the paged argument in the WP_Query, but my next_posts_link doesn't work.
my code to show child post
<?php
$args = array(
'post_type' => 'programs',
'posts_per_page' => 60,
'post_parent' => $post->ID,
'order' => 'ASC',
);
$parent = new WP_Query( $args );
if ( $parent->have_posts() ) : ?>
<div class="penci-border-arrow penci-homepage-title penci-magazine-title style-5 pcalign-right pciconp-right pcicon-right" style="border-color: #3E68B0">
<h3 class="inner-arrow" style="background:#3E68B0;border-color: #3E68B0">
الحلقات </h3>
</div>
<ul class="penci-wrapper-data penci-grid">
<?php while ( $parent->have_posts() ) : $parent->the_post();
$featured_img_url = get_the_post_thumbnail_url(get_the_ID());
$episode_number = get_field('episode_number', get_the_ID());
?>
<li class="list-post pclist-layout">
<article id="post-<?php the_ID(); ?>" class="item hentry">
<div class="thumbnail child-thumbnail">
<a class="penci-image-holder penci-lazy" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" style="background-image: url(<?php echo $featured_img_url?>);">
</a>
</div>
<div class="content-list-right content-list-center child-content">
<div class="header-list-style">
<div class="episode-details">
<span class=""> <a class="url fn n" href="<?php the_permalink(); ?>"><?php echo $episode_number ?></a></span>
<span style="margin:0 20px"><a>|</a></span>
<span class="featc-date"><time class="entry-date published" datetime="2021-10-31T13:26:29+00:00">2021-10-31</time>
</span>
<span class='program-viewcn'><?php pvc_stats_update( get_the_ID(), 1 ); ?></span>
</div>
<h2 class="grid-title entry-title">
<?php the_title(); ?>
</h2>
</div>
<div class="item-content entry-content">
<p>
<?php the_excerpt();?>
</p>
</div>
</div>
</article>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
I'm having an issue trying to get pagination to work on the homepage of a site I'm working on.
Here is the code I'm using, simplified of course:
How to do pagination for this?
<?php $args = array('cat' => '3, 7, 10, 12', 'posts_per_page'=> 3); ?>
<?php query_posts($args); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="col-md-12">
<a href="<?php the_permalink(); ?>" >
<div class="image"><img class="img-responsive" src="<?php echo the_post_thumbnail_url( 'medium' ); ?>"></div></a>
<div class="entry entry-table">
<div class="title">
<?php the_title(); ?></h3>
<span class="cateogry<?php echo get_the_category( $id )[0]->cat_ID; ?>"><?php echo get_the_category( $id )[0]->name; ?></span>
<p><?php echo get_excerpt(228, 'content'); ?>
<a class="linkmore" href="<?php the_permalink() ?>">Czytaj dalej ...</a>
</p>
</div>
</div>
</article>
<?php endwhile; endif; ?>
<?php $args = array('cat' => '3, 7, 10, 12', 'posts_per_page'=> 3); ?>
<?php query_posts($args); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="col-md-12">
<a href="<?php the_permalink(); ?>" >
<div class="image"><img class="img-responsive" src="<?php echo the_post_thumbnail_url( 'medium' ); ?>"></div></a>
<div class="entry entry-table">
<div class="title">
<?php the_title(); ?></h3>
<span class="cateogry<?php echo get_the_category( $id )[0]->cat_ID; ?>"><?php echo get_the_category( $id )[0]->name; ?></span>
<p><?php echo get_excerpt(228, 'content'); ?>
<a class="linkmore" href="<?php the_permalink() ?>">Czytaj dalej ...</a>
</p>
</div>
</div>
</article>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
<?php endif; ?>
First of all, you must setup properly your query:
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array('cat' => '3, 7, 10, 12', 'posts_per_page'=> 3, 'paged' => $paged);
And second, you need to add pagination links out of the loop
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
Whole code can looks like this:
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array('cat' => '3, 7, 10, 12', 'posts_per_page'=> 3, 'paged' => $paged);
?>
<?php query_posts($args); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="col-md-12">
<a href="<?php the_permalink(); ?>" >
<div class="image"><img class="img-responsive" src="<?php echo the_post_thumbnail_url( 'medium' ); ?>"></div></a>
<div class="entry entry-table">
<div class="title">
<?php the_title(); ?></h3>
<span class="cateogry<?php echo get_the_category( $id )[0]->cat_ID; ?>"><?php echo get_the_category( $id )[0]->name; ?></span>
<p><?php echo get_excerpt(228, 'content'); ?>
<a class="linkmore" href="<?php the_permalink() ?>">Czytaj dalej ...</a>
</p>
</div>
</div>
</article>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
<?php endif; ?>
Problem has been solved:
<?php
global $paged, $wp_query, $wp;
$args1 = array('cat' => '3, 7, 10, 12');
$args = wp_parse_args($wp->matched_query);
if ( !empty ( $args['paged'] ) && 0 == $paged ) {
$wp_query->set('paged', $args['paged']);
$paged = $args['paged'];
}
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('paged='.$paged.'&showposts=3&cat=3,7,10,12');
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<article class="col-md-12">
<a href="<?php the_permalink(); ?>" >
<div class="image"><img class="img-responsive" src="<?php echo the_post_thumbnail_url( 'medium' ); ?>"></div></a>
<div class="entry entry-table">
<div class="title">
<?php the_title(); ?></h3>
<span class="cateogry<?php echo get_the_category( $id )[0]->cat_ID; ?>"><?php echo get_the_category( $id )[0]->name; ?></span>
<p><?php echo get_excerpt(228, 'content'); ?>
<a class="linkmore" href="<?php the_permalink() ?>">Czytaj dalej ...</a>
</p>
</div>
</div>
</article>
<?php endwhile; ?>
<?php wp_pagenavi(); ?>
<?php $wp_query = null; $wp_query = $temp;?>
I am creating a portfolio section.the live site is here, http://www.nayeemriddhi.info/testproject/portfolio/. There need three loop for showing item. But fact is that, when i open portfolio item, the right sidebar item showing item from the beginning, as i created the loop. but i want to show right sidebar item as a current item for the portfolio images. is there any idea for showing right sidebar item as a current item.
the code is below,
<?php
/*
Template Name: Portfolio
*/
get_header(); ?>
<!-- Banner -->
<section class="page-banner" >
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="page-title ">Portfolios</h1>
<span class="page-tag-line">See our recent works</span>
</div>
</div>
</div>
</section>
<div class="wave-divider-pages"></div>
<section>
<div class="container gal-container">
<?php
$args = array(
'post_type' => 'custom_portfolio',
'posts_per_page' => '-1',
);
// the query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) ?>
<?php while ( $query->have_posts() ) : $query->the_post() ; ?>
<?php $globalID = get_the_id(); ?>
<!-- Item-->
<div class="col-md-4 col-sm-6 co-xs-12 gal-item">
<div class="box">
<a class="trigger" data-iziModal-open="#modal<?php the_ID(); ?>">
<img src="<?php echo get_post_meta(get_the_ID(), 'portfolio_image', true); ?>">
</a>
</div>
</div>
<!-- Modal-->
<div id="modal<?php the_ID(); ?>" class="iziModal portfolio" data-izimodal-title="Portfolio Title" data-izimodal-subtitle="Web Design" style="max-width: 1200px important;">
<div class="col_one_third p-20">
<?php
$args2 = array(
'post_type' => 'custom_portfolio',
'posts_per_page' => '6',
);
// the query
$query2 = new WP_Query( $args2 );
// The Loop
if ( $query2->have_posts() ) ?>
<?php while ( $query2->have_posts() ) :
$query2->the_post() ; ?>
<div class="col_half p-10">
<a href="#<?php the_ID(); ?>-<?= $globalID; ?>" data-toggle="tab">
<img src="<?php echo get_post_meta(get_the_ID(), 'portfolio_image', true); ?>" class="portfolio-thumb"/>
</a>
</div>
<?php endwhile; wp_reset_query(); ?>
<div class="col_full p-10">
<div class="portfolio-links">
Launch Website
Request a Quote
</div>
</div>
</div>
<div class="col_two_third col_last">
<div class="tab-content ">
<?php
$args3 = array(
'post_type' => 'custom_portfolio',
'posts_per_page' => '-1',
);
// the query
$query3 = new WP_Query( $args3 );
// The Loop
if ( $query3->have_posts() ) ?>
<?php while ( $query3->have_posts() ) :
$query3->the_post() ; ?>
<div class="tab-pane active" id="<?php the_ID(); ?>-<?= $globalID; ?>">
<img src="<?php echo get_post_meta($globalID, 'portfolio_image', true); ?>" class="img-responsive"/>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
</div>
</div>
<!-- Item End-->
<?php endwhile; wp_reset_query(); ?>
</div>
</section>
<section>
</section>
<div class="wave-divider-common"></div>
<?php get_footer(); ?>
Thanks for help...
Modify your html for first anchor tag as
<a class="trigger" data-iziModal-open="#modal<?php the_ID(); ?>" data-id="<?php the_ID(); ?>-<?= $globalID; ?>">
<img src="<?php echo get_post_meta(get_the_ID(), 'portfolio_image', true); ?>">
</a>
Add this JS
<script type="text/javascript">
$(document).ready(function(){
$('a.trigger').on('click', function (e) {
var getDataId = $(this).data('id');
$('.iziModal a[href="#' + getDataId + '"]').tab('show');
});
});
</script>
What i am trying to do is create a timeline. What i want to happen is have the date echo in at the top of the first post of each month. So it will act like a separator to know now that the posts below are in this month.
Currently i am just querying all the posts in a category. Now what i want to happen is an if else statement. If its the first post of the the month, echo some text.
<?php $cat=get_field( 'time_taxonomy');?>
<?php global $post; $i=0; $args=array( 'numberposts'=>-1, 'offset'=> 0, 'category' => $cat ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : if ($i==1) { } else {}; setup_postdata($post); $i++; ?>
<div class="ss-container">
<div class="none"><?php echo date("F"); ?></div>
<div class="ss-row">
<div class="ss-left">
<h2 id="month"><?php echo date("F"); ?></h2>
</div>
<div class="ss-right">
<h2><?php echo date("Y"); ?></h2>
</div>
</div>
<div class="ss-row ss-medium">
<!-- Pulling in the featured post imgae and title-->
<?php $image=wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'timeline' ); ?>
<div class="ss-left">
<a href="<?php the_permalink(); ?>" class="ss-circle">
<img class="ss-circle-1" src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" />
</a>
</div>
<div class="ss-right">
<h3>
<span><?php echo date("F j, Y | g:i a"); ?></span>
<a href="#">
<?php the_title(); ?>
</a>
</h3>
</div>
</div>
</div>
<?php endforeach; ?>
<?php $cat=get_field( 'time_taxonomy');?>
<?php global $post; $i=0; $args=array( 'numberposts'=>-1, 'offset'=> 0, 'category' => $cat ); $myposts = get_posts( $args ); $prev_month = -1; foreach( $myposts as $post ) :
$post_month = date("m",strtotime($post["post_date"]));
if($post_month != $prev_month) {
// First post of the new month
} else {
// Still the same month
}
$prev_month = $post_month;
setup_postdata($post); $i++; ?>
<div class="ss-container">
<div class="none"><?php echo date("F"); ?></div>
<div class="ss-row">
<div class="ss-left">
<h2 id="month"><?php echo date("F"); ?></h2>
</div>
<div class="ss-right">
<h2><?php echo date("Y"); ?></h2>
</div>
</div>
<div class="ss-row ss-medium">
<!-- Pulling in the featured post imgae and title-->
<?php $image=wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'timeline' ); ?>
<div class="ss-left">
<a href="<?php the_permalink(); ?>" class="ss-circle">
<img class="ss-circle-1" src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" />
</a>
</div>
<div class="ss-right">
<h3>
<span><?php echo date("F j, Y | g:i a"); ?></span>
<a href="#">
<?php the_title(); ?>
</a>
</h3>
</div>
</div>
</div>
<?php endforeach; ?>