Wordpress. "the_post()" loop doesn't iterate on all posts - wordpress

Loop on my front page not showing results.
<?php define('WP_USE_THEMES', false); get_header(); ?>
<div class="site-row clear">
<div class="center">
<?php get_sidebar(); ?>
<div class="showcase">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
echo '1';
endwhile;
endif;
?>
</div>
</div>
</div>
<?php get_footer(); ?>
It's show '1', but i have lot posts. People, tell me please what i do wrong?
UPD.
This code is in front-page.php . On local server all posts showing, but on hosting didn't show. Instead Echo '1' i use the_content(). echo '1' just for debugging.

Related

Comment 'get_sidebar();' have no effect: remove sidebar from theme

I'm trying to remove the sidebars from a WordPress site;
should be a pretty straight-forward action to do, but I have a problem:
I've commented every get_sidebar() I've found in my theme PHP page (including index.php, page.php etc) but seem that have no effect on the site.
Here is an example from my index.php:
<?php get_header(); ?>
<div id="page-wrapper" class="container">
<div class="row">
<div id="page-content" class="col-sm-7 col-md-8">
<?php if ( have_posts() ) : ?>
<?php get_template_part( 'templates/page-title' ); ?>
<?php $blog_layout = vw_get_option( 'blog_layout' ); ?>
<?php if ( 'classic' == $blog_layout ) : ?>
<div class="row archive-posts post-box-list">
<?php while ( have_posts() ) : the_post(); ?>
<div class="col-sm-12 post-box-wrapper">
<?php get_template_part( 'templates/post-box/classic', get_post_format() ); ?>
</div>
<?php endwhile; ?>
</div>
<?php else: ?>
<div class="row archive-posts vw-isotope post-box-list">
<?php while (have_posts()) : the_post(); ?>
<div class="col-sm-6 post-box-wrapper">
<?php get_template_part( 'templates/post-box/large-thumbnail', get_post_format() ); ?>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
<?php get_template_part( 'templates/pagination' ); ?>
<?php comments_template(); ?>
<?php else : ?>
<h2><?php _e( 'Sorry, no posts were found', 'envirra' ) ?></h2>
<?php endif; ?>
</div>
<!--aside id="page-sidebar" class="sidebar-wrapper col-sm-5 col-md-4">
<?php // get_sidebar(); ?>
</aside-->
</div>
</div>
<?php get_footer(); ?>
in the example above you can see both html / PHP comment, but I've also tried with only HTML comment / only PHP comment.
may notice that i'm using a Child theme, but I've found the get_sidebar() only in the father theme.
I'm probably missing something stupid, should i remove the entire line? i'm not an WordPress expert so i'd like to do the less intrusive modification.
Thanks!
Usually there is an option within the most of WP themes to turn off the sidebar(s), also theme authors care to give you a simple checkbox for that in the single Page, Post, or even Category template, but sometimes there is no easy way out.
I suggest you check this guide back from 2017 and a bit more fresh one from 2019 here, most likely you will find your way without additional plugin in the first reference.

How to show extra content with a slug?

This is a single.php and for example url is
http://url.com/sample-post/
I added some extra content with Advanced Custom Fields plugin and show it in the content. Everything is all right here but I want to show this extra content like http://url.com/sample-post/extra-content/
Is it possible? If yes how can I make it? I've been searching for hours but I have not found anything.
I hope you understand me and so sorry for my bad english. Thank you everyone who will help.
<?php get_header(); ?>
<main class="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php the_field('some-extra-content'); ?> // Extra Content
<?php endwhile; ?>
</main>
<?php get_footer(); ?>
please try below code for ACF
<?php get_header(); ?>
<main class="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php echo get_field('some-extra-content', $post->ID); ?>
<?php endwhile; ?>
</main>
<?php get_footer(); ?>
Not exactly the same url but you could use a query string.
http://url.com/sample-post?extra=true
<?php
if($_GET['extra'] === 'true'){
the_field('some-extra-content');
}
?>

How To make pagination work correctly in WordPress?

I am new to wordpress. I have a problem with pagination when I click to the next post it shows "not found". I installed the plugin wp pagenavi, and I put code in my blog post <?php wp_pagenavi(); ?>. It shows the pagination, but I have a problem with the link to the next post. Example when I click to the next post — http://westecmedia.com/events/page/2/ — it shows:
Something went Wrong!
404
-->
You can see at: http://westecmedia.com/events/
And this is my code in event-page.php:
<?php
/*
* Template Name: Page - Events Page
*/
?>
<?php get_header(); ?>
<div id="content-events">
<div id="head-event"><h3>EVENTS</h3></div>
<div id="main-event">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="part-event">
<div id="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div id="event-dess">
<h2><?php the_title(); ?></h2>
<p>
<?php
$content = get_the_content();
$content = strip_tags($content);
echo substr($content, 0, 300);
?>
</p>
<div id="read-more">Read More</div>
</div>
</div>
<div id="line-bottom"></div>
<?php endwhile; else: endif; ?>
<?php wp_pagenavi(); ?>
</div>
</div>
<?php get_footer(); ?>
Who can help me please?
https://codex.wordpress.org/Function_Reference/paginate_links
Please try using this instead of plugin. Also add this code before the if loop ends.

Wordpress Search result page display entire content

I have a signifiantly big problem up there.
I'm trying to design my search restult page on WordPress, but if it comes that the search find a page with the keyword I just entered, it display the entire page instead of the title();
My code
<?php
/**
* The template for displaying search results pages.
*
* #package miller
*/
get_header(); ?>
<section id="primary" class="content-area">
<main id="int_top_main" class="internal blue_top" style="min-height:80px;">
<div class="wrapper">
<h2 class="page_title uppercase"><span class="parent_page">Search results</h2>
<div id="infinite_blue_top_bar"></div>
</div>
</main><!-- #main -->
<div id="int_content_main" class="internal">
<div class="wrapper physician_headline">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php else : ?>
<h2><?php _e( 'Nothing Found', 'miller' ); ?></h2>
<div class="page-content">
<?php if ( is_search() ) : ?>
<p><?php _e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'miller' ); ?></p>
<?php else : ?>
<p><?php _e( 'It seems we can’t find what you’re looking for. Perhaps searching can help.', 'miller' ); ?></p>
<?php endif; ?>
</div><!-- .page-content -->
<?php endif; ?>
</div>
</div>
</section><!-- #primary -->
<?php get_footer(); ?>
If it finds nothing, it will go into the else: but if it do finds something they display all the pages (fullpage) of what it finds out there.
It should only display the_title(); but no..
Even if I completly destruct the search.php file it stills automaticly goes to the "suggested" page.
First time I am getting this kind of thing and I do not know how to solve it :(
It's calling for the post before the title, which is why it pulls for the full post.
Try:
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_title(); ?>
<?php endwhile; ?>
<?php else : ?>

Custom Post type templates not working in wp

I have some categories like about-us, services etc and want to show different templates for these categories. I have read from wp site to make files name like category-slug.php where slug may be about-us or services. I made these files but they didn't worked for me. Instead of these templates the index file displays the posts. I want to display posts from these categories in custom files.
Can any one tell me how to do this?
Are you looking for something like this?
<?php /*
Template Name: ListPostsInCategoryThatHasSameNameAsPage
*/ ?>
<?php get_header(); ?>
<div id="content">
<div id="main">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?>
<?php endwhile; else: endif; ?>
</div>
</div>
<?php get_footer(); ?>

Resources