I am using Wordpress and the Roots Template.
I have created an archive page to show member profiles. - its just index.php saved out as archive-members.php so it gets the member posts, but I don't know how to change the number it displays. I want it to display all.
its not using any custom post type query, its just an archive of this post-type slug
Here is my page code.
<div class="purple row">
<div class="container">
<div class="col-lg-12">
<?php get_template_part('templates/page', 'header'); ?>
</div>
</div>
</div>
<?php if (!have_posts()) : ?>
<div class="alert alert-warning">
<?php _e('Sorry, no results were found.', 'roots'); ?>
</div>
<?php get_search_form(); ?>
<?php endif; ?>
<div class="row pagecontent">
<div class="container">
<?php while (have_posts()) : the_post(); ?>
<div class="col-sm-3">
<?php get_template_part('templates/members', get_post_format()); ?>
</div>
<?php endwhile; ?>
<?php if ($wp_query->max_num_pages > 1) : ?>
</div>
</div>
<div class="container">
<div class="col-lg-12">
<nav class="post-nav">
<ul class="pager">
<li class="next"><?php next_posts_link(__('Next Page →', 'roots')); ?></li>
<li class="previous"><?php previous_posts_link(__('← Previous Page', 'roots')); ?></li>
</ul>
</nav>
</div>
</div>
<?php endif; ?>
I believe this question has already been answered here.
The answer in that thread links to the WordPress codex on using the query_post() function.
That, or as someone else in the thread states, you can try changing the settings in the admin interface (settings -> reading). There, you'll see a box that allows you to change how many posts are displayed on a page.
Related
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
to learn wordpress development, I'm building a wordpress theme from scratch .
Now i want to add pagination on my category page but the problem is:
when i click on older-post-link the url change from "http://localhost/wordpress4/category/bloc1/" to "http://localhost/wordpress4/category/bloc1/page/2/" but it take me to a blank page instead of showing the other posts.
this is the code on the category.php
<?php get_header(); ?>
<div class="container">
<?php
$counter = 1; //start counter
$grids = 3; //Grids per row
global $query_string; //Need this to make pagination work
/*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */
query_posts($query_string . '&caller_get_posts=1&posts_per_page=4');
if(have_posts()) : while(have_posts()) : the_post();
?>
<?php
//Show the left hand side column
if($counter == 1) :
?>
<div class="row">
<div class="col-md-4">
<div class="center">
<div class="postimage">
<?php the_custom_logo(); ?>
</div>
<h2><?php the_title(); ?></h2>
<h4><?php the_category(); ?></h4>
</div>
</div>
<?php
elseif($counter == 2) :
?>
<div class="col-md-4 border2">
<div class="center">
<div class="postimage">
<?php the_custom_logo(); ?>
</div>
<h2><?php the_title(); ?></h2>
<h4><?php the_category(); ?></h4>
</div>
</div>
<?php
elseif($counter == $grids) :
?>
<div class="col-md-4">
<div class="center">
<div class="postimage">
<?php the_custom_logo(); ?>
</div>
<h2><?php the_title(); ?></h2>
<h4><?php the_category(); ?></h4>
</div>
</div>
</div>
<div class="clear"></div>
<?php
$counter = 0;
endif;
$counter++;
endwhile;
?>
<div class="row">
<div class="col-xs-6 text-left">
<?php next_posts_link('<< Older post'); ?>
</div>
<div class="col-xs-6 text-right">
<?php previous_posts_link('Newer post >>'); ?>
</div>
<?php
endif;
?>
</div>
</div>
<?php get_footer(); ?>
I noticed that if i add the code below to my index.php the pagination work also on the category page.
but the second category page("http://localhost/wordpress4/category/bloc1/page/2/") will take the markup of index.php so the posts will not be in a grid format like the first category page.
global $query_string; //Need this to make pagination work
/*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */
query_posts($query_string . '&caller_get_posts=1&posts_per_page=4');
also on the category page the older post-link show up between rows instead of showing at the bottom of the pages.
finally this is the code on my index.php
<?php get_header(); ?>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-8">
<?php
if(have_posts()):
while(have_posts()): the_post(); ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<h3><?php the_title(); ?></h3>
<small><?php the_category(); ?></small>
</a>
<p><?php the_content(); ?></p>
<hr/>
<?php endwhile;
endif;
?>
</div>
<div class="col-xs-12 col-sm-4">
<?php get_sidebar(); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
Thank You.
Use this code, may be it will solve your problem
<?php
// the query to set the posts per page to 3
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => 3, 'paged' => $paged );
query_posts($args); ?>
<!-- the loop -->
<?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
<!-- rest of the loop -->
<!-- the title, the content etc.. -->
<?php endwhile; ?>
<!-- pagination -->
<div class="row">
<div class="col-xs-12>"
<div class="col-xs-6 text-left"><?php next_posts_link(); ?></div>
<div class="col-xs-6 text-right"><?php previous_posts_link(); ?></div>
</div>
</div>
<?php else : ?>
<!-- No posts found -->
<?php endif; wp_reset_postdata(); ?>
for more details, check this link https://codex.wordpress.org/Pagination
After a lot of searching i was able to find a solution .
The problem was that the The "Blog pages show at most" in the wordpress reading settings was interfering with the "posts_per_page=4" that i declared through the query_posts().
The solution :
I deleted the "query_posts()" because it is best to use the WP_Query() or the pre_get_posts filter.
for me even with using wp_query i couldnt get the pagination to work so i tried using the pre_get_posts filter and it worked .
so in the category.php i deleted the query_posts and used just the normal loop.
this is my new code in the category.php
<?php get_header(); ?>
<div class="container">
<?php
$counter = 1; //start counter
$grids = 3; //Grids per row
if(have_posts()) :
while(have_posts()) : the_post();
?>
<?php
//Show the left hand side column
if($counter == 1) :
?>
<div class="row">
<div class="col-md-4">
<div class="center">
<div class="postimage">
<?php the_custom_logo(); ?>
</div>
<h2><?php the_title(); ?></h2>
<h4><?php the_category(' '); ?></h4>
</div>
</div>
<?php
elseif($counter == 2) :
?>
<div class="col-md-4 border2">
<div class="center">
<div class="postimage">
<?php the_custom_logo(); ?>
</div>
<h2><?php the_title(); ?></h2>
<h4><?php the_category(' '); ?></h4>
</div>
</div>
<?php
elseif($counter == $grids) :
?>
<div class="col-md-4">
<div class="center">
<div class="postimage">
<?php the_custom_logo(); ?>
</div>
<h2><?php the_title(); ?></h2>
<h4><?php the_category(' '); ?></h4>
</div>
</div>
</div>
<div class="clear"></div>
<?php
$counter = 0;
endif;
?>
<?php
$counter++;
endwhile;
?>
<div class="row">
<div class="col-xs-12 text-left ">
<?php next_posts_link('<< Older post'); ?>
</div>
<div class="col-xs-12 text-right ">
<?php previous_posts_link('Newer post >>'); ?>
</div>
</div>
<?php
endif;
?>
</div>
<?php get_footer(); ?>
Then I added the pre_get_posts action on my function.php
this is the code:
add_action( 'pre_get_posts', function ( $q )
{
if ( !is_admin() // Very important, otherwise back end queries will be affected as well
&& $q->is_main_query() // Very important, we just need to modify the main query
&& $q->is_category() // Only target category pages
) {
$q->set( 'posts_per_page', 2 );
}
});
I hope my answer will help someone who have the same problem i had even if my answer is not so well explained.
for more info search for something like this:
using pagination with the wp_query
using pre_get_posts to set pagination for a custom page.
It will be so nice if a developer could explain my solution in more details and give us more information about using pre_get_posts to set pagination for a custom page.
I'm trying to structure a wordpress search page to include a sidebar within a container that has the "row" class from the bootstrap css. My goal is for the posts to show up on the left side of the container and the sidebar I want to show up on the right. Currently, if the row container is within the loop, I get the same number of sidebars as I have posts. If I move the row container out of the loop, either the sidebar is at the bottom and the <"hr"> lines between each post are pushed to the right side of the container or if I use float on the sidebar containers, I don't get any <"hr"> lines at all.
Any insight is appreciated in pushing the <"hr"> lines to the left with their respective posts and keeping the sidebar on the right at full screen size. For reference, the sidebar is located within the include.php file at the bottom of the row container.
search page code:
<?php get_header(); ?>
<?php if ( have_posts() ) : ?>
<div class="row">
<div class="col-lg-12">
<h1 class="page-header"><?php printf( __( 'Search Results for: %s' ), esc_html( get_search_query() ) ); ?></h1>
<ol class="breadcrumb">
<li>Home
</li>
<li class="active">Blog</li>
</ol>
</div>
</div>
<div class="row">
<?php
// Start the loop.
while ( have_posts() ) : the_post(); ?>
<div class="col-lg-8">
<h3>
<?php the_title(); ?>
</h3>
<p>Posted on <?php the_time('F j, Y'); ?> by <?php the_author_posts_link(); ?>
</p>
<p><?php the_excerpt(); ?></p>
<a class="btn btn-primary" href="<?php the_permalink(); ?>">Read More <i class="fa fa-angle-right"></i></a>
</div>
<hr>
<?php endwhile; ?>
<?php include 'include.php'; ?>
</div>
<div class="navigation"><p><?php posts_nav_link('','« Newer Posts','Older Posts »'); ?></p></div>
<?php else: ?>
<p><?php _e('Sorry, there are no posts.'); ?></p>
<?php endif; ?>
<?php get_footer(); ?>
Thanks for any help and insight :)
You need to move your <div class="col-lg-8"> outside of your while() statement so that you only have one grid column instead of each blog post being inside of its own grid column.
This is assuming that your sidebar had the class col-lg-4.
I did this to show 5 posts of a diferent category in my wordpress page:
<?php $archive_query = new WP_Query('category_name=anc&showposts=5');
while ($archive_query->have_posts()) : $archive_query->the_post(); ?>
<div class="collection">
See All
</div>
<div class="row">
<div class="col s12">
<div class="card">
<div class="card-image">
<img src="<?php echo catch_that_image(); ?>">
<span class="card-title"><?php the_title(); ?></span>
</div>
<div class="card-content">
</div>
<div class="card-action">
Ver más
</div>
</div>
</div>
</div>
<?php endwhile; ?>
It worked, however, now my another pages don´t work, they show posts from that category when i click on those pages instead of showing their respectives posts, what could be the issue?
You can reset data in the global $post object after endwhile;
<?php
while( $your_query->have_posts() ):
...
endwhile;
wp_resest_postdata(); ?>
I came to a solution, after the following line:
<?php endwhile;?>
I wrote this:
<?php wp_reset_query();?>
It resets the query so like that the main loop ( because it´s depend of the main loop ) can work perfectly, i hope this helps everyone, this code is an easy way to show any post of a different category.
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