Wordpress skip latest "x" number of post - wordpress

I want do skip latest 4 post.Is it possible bottom loop? I tried off-set property but doesnt work like i want.
<?php if ( have_posts() ) : ?>
<?php query_posts('posts_per_page=2'); ?>
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="col-md-12" >
<div class="res">
<img src="<?php the_post_thumbnail_url(array(200,200) ); ?> " alt="Norway" style="width:100%;">
<div class="bottom-left"><h2><?php the_title(); ?></h2></div>
<div class="bottom"><h2><?php the_title(); ?></h2></div>
<div class="top-left">
<?php
foreach((get_the_category()) as $category){
$cat_link = get_category_link($category->cat_ID);
echo ' '.$category-> name.'';
}
?>
</div>
</div>
<?php wp_link_pages(); ?>
<!--. entry-->
</div>
</div><!-- .post-->
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
<?php else : ?>
<?php endif; ?></div>
I want do skip latest 4 post.Is it possible bottom loop? I tried off-set property but doesnt work like i want.

You can skip latest posts by simply changing the get_posts function parameters, adding the parameter offset .
Your code would look like:
query_posts('posts_per_page=2&offset=3')
Where offset=3 states that you want to skip first 3 posts.
More in detail information on the following article:
http://www.wpbeginner.com/wp-themes/how-to-exclude-latest-post-from-the-wordpress-post-loop/

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 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 : ?>

How to get category name from URL and pass to a template

I'm using the following page template to display the posts in a single category and plan to format the first post differently than the others. This works as desired but I have the category_name hard coded in the template. I want to use this template for several different categories and would like to learn how to pass the category_name to the template from a link.
For example, the link to the desired page using the special template is http://wildcatweb.net/5th/ and '5th' is also the category_name. How do I tell the template to get the category_name from the URL and use it in the template?
<?php
/*
Template Name: pageAssignments
*/ ?>
<?php get_header(); ?>
<div class="small-12 large-8 columns" id="content" role="main">
<header>
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<!-- show latest post FULL -->
<?php query_posts('showposts=1&category_name=5th'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="lastest-post">
<h2 class="pagetitle"><?php the_title(); ?></h2>
<?php the_content(); ?>
</div><!--close .latest-post -->
<?php endwhile; endif; ?><!-- end lastest post -->
<!-- show older post excerpts -->
<?php query_posts('showposts=5&offset=1&category_name=5th'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="older-post">
<h3 class="pagetitle"><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
</div><!--.older-post -->
<?php endwhile; endif; ?><!-- end past-entry -->
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
try this :
$current_url = $_SERVER['PHP_SELF'];
$category_name = explode ('',$current_url);
$category_name = $category_name['3'];
query_posts('showposts=1&category_name='. $category_name);

Page contents not showing on wordpress

What kind of WordPress function do you use to show the page contents?
I used the_content to show the post contents, but what about the page contents?
I have tried everything, but I haven't found a function that displays the page contents of WordPress.
Also, I have created a basic page.php file, and in the file I have:
<div id="pages">
<li><?php wp_list_pages() ?></li>
</div>
Now, why do my index.php have my list of pages even though I didn't use the inlcude or require function?
Keep in mind I created my own theme and site, and I'm trying to put it in WordPress for the first time.
Thanks!!
The function wp_list_pages() lists all the pages. If you want to list all the recent posts you should use
index.php
<?php get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 class="entry-title"><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; // end of the loop. ?>
<?php get_sidebar(); // If you have sidebar ?>
<?php get_footer(); ?>
page.php
<?php get_header(); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 class="entry-title"><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; // end of the loop. ?>
<?php get_sidebar(); // If you have sidebar ?>
<?php get_footer(); ?>
Make sure you check the default twentyeleven and twentyten themes to get idea of how to code WordPress Themes.

Resources