So this is driving me kind of crazy, I just can't seem to get the page navigation to work. I installed a plugin wp-pagenavi but it still doesn't work. Is there anyone that could help me getting it to work. Here is my code (the loop):
<?php $args = array(
'post_type' => 'portfolio',
'posts_per_page'=> 10,
'orderby' => 'ID',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'foto_video_type',
'field' => 'slug',
'terms' => 'foto'
)
)
);
$products = new WP_Query( $args );
if( $products->have_posts() ) {
while( $products->have_posts() ) {
$products->the_post();
?>
<?php $naam = get_field('naambedrijf');
$soort = get_field('soort_uitje');
$foto = get_field('flickr_fotoset'); ?>
<div class="col s12">
<div class="title">
<h2 class="truncate" style="line-height:20px;"><?php echo $naam; ?> | <?php echo $soort; ?></h2>
<a class="fotos" href="https://www.flickr.com/photos/../sets/<?php echo $foto; ?>" target="_blank"><small>Bekijk alle foto's</small></a>
</div>
<div class="flickrphotoset">
<?php echo do_shortcode('[slickr-flickr id="" search="sets" set="' . $foto . '" size="large" items="9" bottom="10" responsive="on" type="thumbnail" galleria_options="lightbox:true;thumbnail:lazy"]'); ?>
</div>
</div>
<?php
}
}
else {
echo 'There seems to be a problem, please try searching again or contact customer support!';
} ?>
<?php wp_pagenavi(); ?>
And this is my archive code:
<section id="collaps">
<div class="row">
<div class="col s12 offset-s0 m12 l7 offset-l5">
<ul class="collapsible z-depth-1" data-collapsible="accordion">
<li>
<div class="collapsible-header"><i class="fa fa-camera" aria-hidden="true"></i><p>Foto</p></div>
<div id="portfolio" class="collapsible-body">
<div class="row">
<?php get_template_part('loop-foto'); ?>
<div class="col s12">
</div>
</div>
</div>
</li>
<li>
<div class="collapsible-header"><i class="fa fa-video-camera" aria-hidden="true"></i><p>Video</p></div>
<div id="portfolio" class="collapsible-body">
<div class="row">
<?php get_template_part('loop-video'); ?>
</div>
</div>
</li>
</ul>
</div>
</div>
</section>
When i add the "older" Wordpress code:
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries', '1000') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »', '1000') ?></div>
</div>
It kind of works. But page/2/ give a 404 error... What am I doing wrong?
I'm not sure if it is your case, but as I faced a similar case, I'm going to post my solution here:
In my case the problem was that I had a page with a permalink equal to the post type, so just changing the page slug solved the problem.
Related
Currently child comments are not shown under parent comments
Below is the code
<ul class="comments-list">
<?php foreach ($comments as $comment): ?>
<li>
<div class="my-4">
<div class="comment-author-image">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/images/avatar.jpg" alt="search" class="search-icon-white">
</div>
<div class="comment-text">
<div class="comment-text-author"><?php echo $comment->comment_author; ?></div>
<div class="comment-text-content"><?php echo $comment->comment_content; ?></div>
<div class="comment-text-date"><?php display_human_readable_time($comment->comment_date); ?></div>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
This can be done by following code:
$args = array(
'parent' => $comment_ID,
'hierarchical' => true,
);
$child_comments = get_comments($args);
You can also refer this documentation.
I'm trying to add a custom field to my Wordpress page but it's not working. When I set its value nothing happens on the HTML.
I read the Wordpress documentation and I tried to follow the steps there but something went wrong.
Everything else it's working, like the_title(), the_post_thumbnail()...it's just this custom field that I it's not Working :(
https://wordpress.org/support/article/custom-fields/
https://codex.wordpress.org/Function_Reference/register_post_type
Custom Field:
Functions.php
$supports = array (
'title',
'editor',
'thumbnail',
'custom-fields'
);
HTML
<?php
$args = array ('post_type' => 'produtos');
$loop = new WP_Query( $args );
if ($loop->have_posts() ) {
while ($loop->have_posts() ) {
$loop->the_post();
?>
<div class="col-xl-2 col-lg-3 col-md-3 col-sm-4 col-md-3 col-12">
<div class="produtos-head">
<div class="img-fluid produtos-img">
<?php the_post_thumbnail(); ?>
</div>
</div>
<div class="produtos-titulo d-flex align-items-center justify-content-center">
<?php the_title(); ?>
</div>
<div class="preco-original"> Price:R$
<?php $original_price = get_post_meta($post->ID, 'original_price', true);
if($original_price){ ?>
<p>
<? echo $original_price; ?>
</p>
<?php
}else{
}
?>
</div>
<div class="preco-promocional"> <span> Sale: </span>
<span class="preco-promocional-number"> $ </span>
</div>
<button class="btn-vendedor"> Contact </button>
</div>
<?php
}
}
?>
</div>
</div>
use get_the_ID() instead of $post->ID and need to change <? echo $original_price; ?> to <?php echo $original_price; ?>
I'm messing around with my code. My goal is to display 4 custom post type on the homepage in the HTML layout I've created. Here's my code. Actually I can get the href but I can't loop the code not even achieve my scope.
<div class="roundedframe ">
<div class="container-fluid">
<div class="row">
<div class="col-lg-4 col-sm-6">
<a class="portfolio-box" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<div class="portfolio-box-caption">
<div class="portfolio-box-caption-content">
<div class="project-category text-faded">
Category
</div>
<div style="background-image: url('<?php the_post_thumbnail_url(); ?>');">
<div class="project-name"> <?php // WP_Query arguments
$args = array(
'name' => 'case-studies',
'nopaging' => true,
'posts_per_page' => '4',
);
// The Query
$query = new WP_Query( $args );
while ( $query->have_posts() ) : $query->the_post();
?>
Project Name
</div>
</div>
</div>
</a>
</div>
</div>
</div>
</div>
Assuming the post type you want is case-studies you should name the key post_type and not name. You also have to place the column inside the loop and close it afterwards. You also missed a </div> tag.
<?php $query = new WP_Query( [
'post_type' => 'case-studies',
'nopaging' => true,
'posts_per_page' => '4',
] ); ?>
<?php if ( $query->have_posts() ) : ?>
<div class="roundedframe ">
<div class="container-fluid">
<div class="row">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="col-lg-4 col-sm-6">
<a class="portfolio-box" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<div class="portfolio-box-caption">
<div class="portfolio-box-caption-content">
<div class="project-category text-faded">
Category
</div>
<div style="background-image: url('<?php the_post_thumbnail_url(); ?>');">
<div class="project-name">
<h2><?php the_title(); ?></h2>
</div>
</div>
</div>
</div>
</a>
</div>
<?php endwhile; ?>
</div>
</div>
</div>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
You should put your code in the looping area. What i can see, you missed the endwhile also.
<div class="roundedframe ">
<div class="container-fluid">
<div class="row">
<?php // WP_Query arguments
$args = array(
'name' => 'case-studies',
'nopaging' => true,
'posts_per_page' => '4'
);
// The Query
$query = new WP_Query($args);
while ($query->have_posts()):
$query->the_post(); ?>
<div class="col-lg-4 col-sm-6">
<a class="portfolio-box" href="<?php
get_the_permalink();
?>" title="<?php
get_the_title();
?>">
<div class="project-category text-faded">
Category
</div>
<div style="background-image: url('<?php
the_post_thumbnail_url();
?>');">
<div class="project-name">
Project Name
</div>
</div>
</a>
</div>
<?php
endwhile;
?>
</div>
</div>
</div><!--.roundedframe-->
Try this and let me know. It may help you. Before that you should learn about wp_query
https://codex.wordpress.org/Class_Reference/WP_Query
i've got a own wordpress template (still in progress). It includes of course search.php template which looks like this:
<?php
get_header(); ?>
<section class="row page_intro">
<div class="row m0 inner">
<div class="container">
<div class="row">
<h5><?php
/* translators: %s: search query. */
printf( esc_html__( 'Search Results for: %s', 'vetsandpets' ), '<span>' . get_search_query() . '</span>' );
?></h5>
<h1><?php _e('News and veterinary advices', 'vetsandpets'); ?></h1>
</div>
</div>
</div>
</section>
<section class="row breadcrumbRow">
<div class="container">
<div class="row inner m0">
<?php
if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('
<p id="breadcrumbs">','</p>
');
}
?>
</div>
</div>
</section>
<section class="row content_section">
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-8 blog_list">
<?php
global $post;
setup_postdata( $post );
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
'post_type' => 'post', // You can add a custom post type if you like
'posts_per_page' => '6',
'paged' => $paged
));
if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="row m0 blog blog2">
<div class="image_row row m0">
<?php the_post_thumbnail('looppostthumbnail', array( 'class' => "img-responsive loop-post-image")); ?>
</div>
<h3><?php echo get_the_title(); ?></h3>
<div class="row m0 meta"><?php _e('Posted on', 'vetsandpets'); ?>: <?php the_time('j F Y'); ?></div>
<p><?php echo excerpt(50); ?></p>
<?php _e('Read more', 'vetsandpets'); ?>
</div> <!--Single Post-->
<?php endwhile; ?>
<?php echo wpse247219_custom_pagination(); ?>
<?php else : ?>
<div class="center"><?php _e('Nope:( no posts yet.', 'vetsandpets'); ?></div>
<?php endif; wp_reset_postdata(); ?>
</div>
<div class="col-sm-12 col-md-4 sidebar">
<div class="row m0 widget categories">
<h5 class="widget_heading"><?php _e('Categories', 'vetsandpets'); ?></h5>
<ul class="list-unstyled">
<?php
$args = array(
'orderby' => 'count',
'depth' => 0,
'title_li' => '',
'use_desc_for_title' => '',
'order' => 'DESC',
'hide_empty' => 0
);
wp_list_categories($args);
?>
</ul>
</div>
<div class="row m0 widget recent_posts">
<h5 class="widget_heading"><?php _e('Recent posts', 'vetsandpets'); ?></h5>
<?php
// the query
$the_query = new WP_Query( array(
'posts_per_page' => 3
));
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="media recent_post">
<div class="media-left">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail('recentpostthumbnail', array( 'class' => "img-responsive recentpostimage")); ?>
</a>
</div>
<div class="media-body">
<h5><?php the_title(); ?></h5>
<p><?php _e('Posted on', 'vetsandpets'); ?>: <?php the_time('j F Y'); ?></p>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e('Nope:( no posts yet.', 'vetsandpets'); ?></p>
<?php endif; ?>
</div>
</div>
</div>
</div>
</section>
<?php
get_sidebar();
get_footer();
?>
And that's it. Then I have a search form which is included always in a navigation modal. Below you can check the php code:
<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
<div>
<input class="form-control" type="search" value="<?php get_search_query(); ?>" id="example-search-input" name="s" id="s" />
<button type="submit" class="btn searchbtn" id="searchsubmit"><?php _e('Submit', 'vetsandpets') ?></button>
</div>
</form>
but it doesnt work - meaning: it always displays all posts.. what im doing wrong? it is somehow linked to arguments in this code/loop?
The problem is that you reset the global $post object by the query_posts() call. As it is stated in the WordPress Docs: This function will completely override the main query and isn’t intended for use by plugins or themes. Its overly-simplistic approach to modifying the main query can be problematic and should be avoided wherever possible.
So, you should delete these lines:
query_posts(array(
'post_type' => 'post',
'posts_per_page' => '6',
'paged' => $paged
));
The first while loop <?php while ( have_posts() ) : the_post(); ?> will already iterate over the search results.
I have a problem with a custom wordpress template.
I've made a categories page. Works fine on the firs view.
But when I make click on 2nd page for older posts, the browser shows me a 404 error.
I think my query needs something more, but I don't know what is or if this is the problem.
Can somebody help, please?
This is my code:
<?php
/**
* The template for displaying Category pages
*/
?>
<?php get_header(); ?>
<?php get_template_part( 'partials/linea-content', 'page' ); ?>
<div class="index categories">
<div class="col-xs-12 pre-content">
<div class="container">
<?php //Para añadir contenido se interesa ?>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-xs-12 categories-title">
<h2>Categoria: <span><?php echo get_category(get_query_var('cat'))->name; ?></span></h2>
</div>
<div id="posts" class="col-xs-12 col-sm-9">
<?php
// set the "paged" parameter (use 'page' if the query is on a static front page)
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
// Cambiamos los argumentos para buscar desde la última
$args = array(
'posts_per_page' => 2,
'orderby' => 'date',
'order' => ASC,
'category__in' => get_category(get_query_var('cat'))->cat_ID,
'paged' => $paged
);
// '&orderby=date&order=ASC&category=' . get_category(get_query_var('cat'))->cat_ID;
// volvemos a crear la consulta principal
$aux = query_posts( $args );
$cont_items = 1;
?>
<?php if ( have_posts() ) : ?>
<div class="row items-row">
<div class="col-xs-12">
<?php while ( have_posts() ) : the_post(); ?>
<!-- post -->
<div id="post-id-<?php echo $post->ID; ?>" class="item col-xs-12 col-sm-6">
<div class="row">
<div class="col-xs-12 text-center item-content">
<span class="meta-category">
<span class="meta-category-inner">
<?php
$cat = get_the_category($post->ID);
?>
<?php echo $cat[0]->name; ?>
</span>
</span>
<?php
global $wpdb;
$ppbv_tablename = $wpdb->prefix . 'popular_by_views';
$currentRow = $wpdb->get_row("SELECT * FROM {$ppbv_tablename} WHERE post_id = {$post->ID}");
$curView = 0;
if(isset($currentRow))
{
$curView = $currentRow->views;
}
?>
<div class="item-title-content">
<a href="<?php the_permalink(); ?>" title="Popsicase">
<h2 class="item-title col-xs-10 col-xs-offset-1"><?php the_title(); ?></h2>
</a>
</div>
<p class="date-cat">
<small class="col-xs-12">
<i class="fa fa-link"></i> <strong><?php the_author(); ?></strong> | <span><i class="fa fa-calendar"></i> <?php echo get_the_date();?> | <i class="fa fa-eye"></i> <?php echo $curView; ?></span>
</small>
</p>
<?php
$img_url = get_template_directory_uri() . '/assets/img/podcast.jpg';
if (get_the_post_thumbnail())
{
$img_url = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
}
?>
<a href="<?php the_permalink(); ?>" title="Popsicase">
<div class="item-thumbnail" style="background:url(<?php echo $img_url; ?>) no-repeat center center;">
</div>
</a>
<div class="row">
<div class="col-xs-6 text-right">
<?php /*<span class="comment"> Comentarios: <?php comments_number( '0','1','%'); ?></span>*/ ?>
</div>
</div>
<div class="item-excerpt text-left">
<div class="col-xs-12">
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
</div>
<?php if ($cont_items % 2 == 0) : ?>
</div>
</div>
<div class="row items-row">
<div class="col-xs-12">
<?php
endif;
$cont_items++;
?>
<?php endwhile; ?>
</div>
</div>
<!-- End of the main loop -->
<!-- Add the pagination functions here. -->
<?php
the_posts_pagination( array(
'mid_size' => 4,
'prev_text' => __( 'Artículos antiguos', 'textdomain' ),
'next_text' => __( 'Artículos nuevos', 'textdomain' ),
) );
?>
<?php /*
<div class="nav-previous alignleft"><?php next_posts_link( 'Artículos antiguos' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Artículos nuevos' ); ?></div>
*/ ?>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>
<div class="hidden-xs col-sm-3 sidebar">
<div class="row">
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('main-sidebar')) : ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="col-xs-12 pos-content">
<div class="container">
<?php //Para añadir contenido se interesa ?>
</div>
</div>
<div class="clearfix"></div>
</div>