I am using in my Wordpress-based site a specific template that has no options display publications, but only static pages. How can I import it to my latest publication?
You can get the latest posts by entering "the Loop" enviroment, the code below is from the Twenty Eleven: Main Index Template by Wordpress
<?php if ( have_posts() ) : ?>
<?php twentyeleven_content_nav( 'nav-above' ); ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentyeleven_content_nav( 'nav-below' ); ?>
<?php else : ?>
you may not want to use twentyeleven_content_nav( 'nav-below' ); nor twentyeleven_content_nav( 'nav-below' ); while using other template (say not based on Twenty Eleven)
Related
I am quite new to WordPress and PHP. I have a problem with posting specific posts on the front page (but I don't use static page option, using the index.php).
I have 2 categories (blog and tips) and currently, I am using 2 formats (standard and aside). Blogs are only assigned to standard and tips are only for the aside format. I want to display them in loop with posts which are in the Blog category & standard format.
<?php if ( have_posts()) : ?>
<div id="ob-grid" class="grid-layout">
<?php if( !in_category('Blog') && !has_post_format()) : ?>
<?php $i=1; while (have_posts() && $i<5 ) : the_post();?>
<?php get_template_part( 'content', get_post_format() );?>
<?php $i++; endwhile; ?>
<?php else : ?>
<?php while (have_posts()) : the_post();?>
<?php get_template_part( 'content', get_post_format() );?>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php do_action( 'E2R_posts_navigation' ); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
The problem is that the !in_category('Blog') && !has_post_format() are excluding each other and getting into else condition (displays all posts) and I can't find the problem (before I used instead of 'Blog', 'Tips' but it did not work either). When I put the condition for !has_post_format() in the while loop, then it filters correctly but the numbering then does not work properly.
The post formats are defined as:
add_theme_support(
'post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
)
);
I have found solution for this problem by position change of the $i iteration. It looks like:
<div id="ob-grid" class="grid-layout">
<?php if( !is_category('Blog')) : ?>
<?php $i=1; while (have_posts() && $i<5 ) : the_post();?>
<?php if( !has_post_format()) : ?>
<?php get_template_part( 'content', get_post_format() );?>
<?php $i++ ;?>
<?php endif;?>
<?php endwhile;?>
<?php endif;?>
I got back to the point: ok, here it was displaying correctly but the number of the post was incorrect (the number of standard-blog posts minus number of aside-tip posts). so I said increment $i only if the post has no format -> !has_post_format() -> is standard. The syntax and functionality of this WordPress functions is weird. but it works for me.
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 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.
So my link to show the older posts is not displaying on my main blog page http://surechamp.com/blog/ it's displaying fine in my archive.php so I'm not sure why it's not working with the index.php. I'm using underscores as my base theme to work off of. This is my code:
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
<?php _s_paging_nav(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
I typically run paging navigation outside the loop and test if there will be a previous or next link shown:
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<?php if($wp_query->get('paged') || $wp_query->get('paged') > 1): ?>
<a class="loadPrev" href="<?php previous_posts(); ?>">prev</a>
<?php endif; ?>
<?php if ($next_url = next_posts($wp_query->max_num_pages, false)): ?>
<a class="loadNext" href="<?php echo $next_url; ?>">next</a>
<?php endif;?>
<?php endif; ?>
I am developing a theme and using twentyeleven theme as my base theme
Twenty eleven uses <?php get_template_part( 'content', get_post_format() ); ?>
To fetch post
SO this codes work properly in index.php
But when i use in custom page template
it doesnt get fomratted propely
<?php
/*
Template Name: Vote Page Template
*/
get_header(); ?>
<div id="primary">
<div class="container">
<head>
</head>
<?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 endif; ?>
</div>
</div>
<?php get_footer(); ?>
Proper Format
Unproper Format