I have a static wordpress front page. I want the code that works on my regular blog template to work on the homepage too.
Currently, it only shows one post. The code in the main index.php is this...
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
<?php wp_pagenavi(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
content.php calls this....
<div class="col-md-4">
<?php the_excerpt(); ?>
</div><!-- /col-md-4 -->
This works great while on the blog page. But i can't get this exact same content on to the static home page. I know I need a different query for homepage but no idea what that is. Any help appreciated!
Your code looks right to me, you can try to reset the loop and query the posts again.
<?php
rewind_posts();
query_posts( $args );
while ( have_posts() ) : the_post();
?>
<!-- Do stuff... -->
<?php endwhile; ?>
global $query_string;
query_posts($query_string.'&post_type=post&posts_per_page=15');
Adding this on top of your code should work. Try it out.
Related
This is my first attempt at creating a theme purely from scratch. Before this I just used underscores_me and made most of my changes to style.css and left the majority of PHP alone, because I'm a novice with it.
My issue is that plugins are not working. None of the ones I have installed work. At this point I have been trying plugins that create an event calendar, but I'm assuming that any and all plugins will have issues. In the areas that are meant to display the calendar, there are two things I'm seeing. Plugin-generated pages show nothing at all (aside from the theme visuals) and plugins that are inserted into an admin-created page display plugin-generated code.
I am using WampServer. I have wp_footer(); and wp_head(); in the correct places. My functions.php file was created from the example found at https://scanwp.net/blog/create-a-wordpress-starter-theme-from-scratch/ and the only adjustment I have made to it so far is to remove the fontawesome line of code.
My index.php file looks like this:
<?php get_header(); ?>
<h1><?php echo "☛ "; ?><?php the_title(); ?></h1>
if ( have_posts() ) :
while ( have_posts() ) : the_post();
// Display post content
endwhile;
endif;
?>
<?php get_footer(); ?>
And my page.php file looks like this:
<?php get_header(); ?>
<h1><?php echo "☛ "; ?><?php the_title(); ?></h1>
<?= get_post_field('post_content', $post->ID) ?>
<?php get_footer(); ?>
First of all, you have to understand that in your displayed files, there are no functions that recall objects that will later show the page content.
Then, in your index.php file there is an error, besides what was said above, because you're calling the_title () (function) that extrapolates the title of a post or page via the post object, which in this case should be extracted within the while loop contained within the if condition.
Then try editing the files as follows.
index.php
<?php
get_header(); ?>
<?php if( have_posts() ) : ?>
<?php while( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php if( is_singular() ) : ?>
<?php the_content(); ?>
<?php else : ?>
<?php the_excerpt(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php else: ?>
<h1>No posts to display</h1>
<?php endif; ?>
<?php get_footer(); ?>
and page.php
<?php
get_header(); ?>
<?php while( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; ?>
<?php get_footer(); ?>
However, within the wordpress codex you will find all the guides well written on any type of function, look no further.
source: https://codex.wordpress.org/
I am using wp-paginate plugin for pagination on my wordpress site. The pagination links are showing fine. The problem is every page shows a blank page.
I am using following code to call pagination. I am new to wordpress so sorry for any mistakes..
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php //twentytwelve_content_nav( 'nav-below' ); ?>
<?php if(function_exists('wp_paginate')) {
wp_paginate();
}
else {
twentytwelve_content_nav( 'nav-below' );
}
?>
You have stared if block but not close it. Enable errors you will get error in php
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php //twentytwelve_content_nav( 'nav-below' ); ?>
<?php if(function_exists('wp_paginate')) {
wp_paginate();
}
else {
twentytwelve_content_nav( 'nav-below' );
}
endif; //<--------------add end if
?>
Finally I found the solution. There was a page named page.php on my server's root folder. I deleted it and problem solved.
I've created a custom template using the twentythirteen template. When I activate the template the blog posts disappear from the front page. I've used the same process to make the new template as I did for my own.
You can see my blog page here, http://www.gnarlydigital.com/blog/ and the new blog that I'm working on is here, http://www.flowdirectpumps.com/news/.
I've tripled checked all the code and both templates are identical. I've uploaded the Gnarly Digital template and it works.
Can anyone see anything obvious?
This is the index.php file
<?php get_header(); ?>
<div class="container pageContent">
<div class="row">
<div class="col-md-12">
<?php if ( have_posts() ) : ?>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentythirteen_paging_nav(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div>
</div>
</div>
<?php get_footer(); ?>
Good day to all,
I'm new in wordpress. I want to ask on how to display my page content in different div. But when I try this code. It won't display anything, my page won't even load. Any help would be much appreciated. Thanks!
<?php if($_SERVER['REQUEST_URI'] == '/wordpress/?page_id=5'): ?>
<div style="width:960px; float:left;min-height:290px;word-wrap: break-word">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
</div>
<?php else: ?>
<div style="width:640px; float:left;min-height:290px;word-wrap: break-word">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
</div>
<?php endif;?>
If you have access to the theme files, copy and paste the page.php, rename the duplicate file to page-about.php, where about is the slug of the page. Similarly you can have any number of page duplicates.
To find what is the slug of a page, go to the page editing area, Screen Option > View Slug.
Hey guys so I am trying to have a loop run to get all the post that are within a certain category on a page, for some reason nothing happens though?
Code :
<?php
/*
Template Name: djequip
*/
get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php /*query_posts('test');uncategorized*/
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile; endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Let me know if you can help, thanks a ton!
<?php /* Template Name: TEMPLATE NAME */ ?>
<?php get_header();?>
<?php query_posts('category_name=CATEGORY NAME'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_excerpt(); ?>
<?php endwhile; ?>
Is this what you mean?
the_excerpt
can be changed to
the_content
Also I'd just like to add that you can put divs in there around the WP PHP.