Custom Wordpress Post Page Breaks if More Than 2 Posts? - wordpress

I have a very custom template, and it works great if there are 1 or 2 posts on the blog page. But as soon as a 3rd post is added, it alters the structure of the template... Literally moves a div inside of another and I cannot understand why. The code for the blog template is here, and a screenshot of the structure as it should be and another showing the misplaced div when a third post is there. Does this make any sense, any ideas?
<div class="post" id="post-<?php the_ID(); ?>"><!--start post-->
<h2><?php the_title(); ?></h2>
<div id="main_full" class=" clearfix"><!--start main-->
<div id="top_bar"><h3 class="gallery-title">news</h3></div>
<div id="blog_page"><!--start blog page-->
<div class="entry"><!--start entry-->
<?php the_content(); ?>
</div><!--end entry-->
</div><!--end blog page-->
</div><!--end main-->
<?php endwhile; endif; ?>
</div><!--end post-->
<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
<?php comments_template(); ?>

Without seeing the beginning of your loop, I can't be 100% sure, but it looks like you need to have:
<?php endwhile; endif; ?>
</div><!--end post-->
be
</div><!--end post-->
<?php endwhile; endif; ?>

<?php endwhile; endif; ?>
</div><!--end post-->
Flip their places. If it doesn't help, please show us what while and what if are getting closed.

Related

Disable WordPress auto paragraph

I've been trying to remove the wp auto p. I've tried both remove_filter('the_content', 'wpautop'); inside my theme's functions.php file and any plugin available to do this, but none of them are actually working.
Also i am not using any plugin that could be placing these p tags, so I am very confused.
Any help would be appreciated.
<?php
/*
Template Name: Text template.
*/
get_header(); ?>
<?php
if(have_posts()):
while(have_posts()): the_post(); ?>
<div class="color-1">
<div class="content">
<p><?php the_content(); ?></p>
</div>
</div>
<?php endwhile;
endif;
?>
<?php get_footer(); ?>
The paragraph around <?php the_content(); ?> was the reason why.

Wordpress Placing of the_content() function in custom page

I have made a custom page in my wordpress theme. The page is working fine. But I am facing trouble using the_content(); function. I am using a few custom fields to display some content on the page and I want the content of the page, that is entered in the Editor, to be displayed on a specific place on the page. But Whatever I enter in the Editor, gets placed at the top of the page above all other content.
EDIT:
Here is the full code:
<?php get_header(); ?>
<div id="main-content">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
<div class="mobile-top">
<a href="<?php the_permalink(); ?>">
<p><?php the_title(); ?> price</p>
</a>
</div>
<?php comments_template(); ?>
</div>
</div> <!--main-content Ends-->

Simplify while loop containing posts code in wordpress

The code below should display the content of the page followed by certain page content.
<!-- Section -->
<section>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- Article -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- Posts for homepage -->
<?php
if ( is_front_page() ) { ?>
<?php the_content(); ?>
<!-- Show page content according to page ID -->
<div class="title-home clearfix">
<div class="four title-home-text">Services Spotlight</div>
<div class="four title-home-text" style="margin-left: 115px;">Industry Expertise</div>
<div class="four title-home-text" style="margin-left: 125px;">Features & Benefits</div>
</div>
<div class="four-wrapper clearfix">
<div class="four-container">
<div class="four-col line">
<?php
query_posts('page_id=40');
while (have_posts()): the_post();
the_content();
endwhile;
?>
</div>
read more
</div>
<div class="four-container">
<div class="four-col line">
<?php
query_posts('page_id=41');
while (have_posts()): the_post();
the_content();
endwhile;
?>
</div>
read more
</div>
<div class="four-container">
<div class="four-col line">
<?php
query_posts('page_id=42');
while (have_posts()): the_post();
the_content();
endwhile;
?>
</div>
read more
</div>
<div class="four-container">
<div class="four-col line">
<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('widget-area-3')) ?>
</div>
</div>
</div>
<?php
}
else {
?>
<h1><?php the_title(); ?> </h1>
<?php the_content(); ?>
<?php } ?>
<!-- end post homepage -->
<br class="clear">
<?php edit_post_link(); ?>
</article>
<!-- /Article -->
<?php endwhile; ?>
<?php else: ?>
<!-- Article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<!-- /Article -->
<?php endif; ?>
</section>
<!-- /Section -->
<?php get_footer(); ?>
However, it displays the last query as loop.
Output Code:
<article id="post-6" class="post-6 page type-page status-publish hentry">
<article id="post-42" class="post-42 page type-page status-publish hentry">
post-42 should not be displayed in the article.
Also, I know the code is not simplified for using while loop. I want to fix the article problem and simplify this code.
The codex advises against using query_posts for secondary loops as per Codex Query Posts Page
It looks like you are stomping on the main loop (article) since query_posts alters the main loop. If you want to use query_posts it is recommended that you call wp_reset_query() when done. The preferred method is to use WP_query().

How can I have multiple loops on one page in Wordpress?

I am using a nice jquery slideshow plugin I found and trying to get it to work into my Wordpress template. I have tried the code below in various formats but I can't seem to get it the way I want.
The first part is where the title and content of the post reads into the slider, using a specific category. I have 3 of these sections:
<div class="details_wrapper">
<div class="details">
<div class="detail">
<?php query_posts('cat_ID=7&showposts=1');
if (have_posts()) : while (have_posts()) : the_post();?>
<h2 class="Lexia-Bold"><a href="<?php the_permalink() ?>">
<?php the_title() ?></a><?php the_excerpt(); ?></h2>
<?php endwhile; endif;
?>
</div><!-- /detail -->
<div class="detail">
<?php query_posts('cat_ID=8&showposts=1');
if (have_posts()) : while (have_posts()) : the_post();?>
<h2 class="Lexia-Bold"><a href="<?php the_permalink() ?>">
<?php the_title() ?></a><?php the_excerpt(); ?></h2>
<?php endwhile; endif;
?>
</div><!-- /detail -->
<div class="detail">
<?php query_posts('cat_ID=9&showposts=1');
if (have_posts()) : while (have_posts()) : the_post();?>
<h2 class="Lexia-Bold"><a href="<?php the_permalink() ?>">
<?php the_title() ?></a><?php the_excerpt(); ?></h2>
<?php endwhile; endif;
?>
</div><!-- /detail -->
</div><!-- /details -->
</div>
Now this actually works, but I just need it to post the title and excerpt from one of the posts from the category noted. I was reading that I may need to add the wp_reset_query(); line somewhere to destroy the previous loop's query, but I'm not sure.
Here's the second part of the code where the post's featured image is retrieved:
<div class="item item_1">
<?php query_posts('cat_ID=7&posts_per_page=1'); ?>
<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
</div><!-- /item -->
<div class="item item_2">
<?php query_posts('cat_ID=8&posts_per_page=1'); ?>
<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
</div><!-- /item -->
<div class="item item_3">
<?php query_posts('cat_ID=9&posts_per_page=1'); ?>
<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
</div>
Any help would be greatly appreciated :) Here's an example.
Have you tried using...
query_posts('cat_ID=9&posts_per_page=1');
Or I have used get_post before as while to get certain amount of post like so...
<?php
global $post;
$myposts = get_posts('posts_per_page=1&numberposts=-1&category=1');
foreach($myposts as $post) :
?>
<h6><?php the_title(); ?></h6>
<?php setup_postdata($post);?>
<?php the_excerpt(); ?>
<?php endforeach; ?>
</div>
If its just one post you want you wouldn't really need the foreach or while loop.
I used the method Tianbo84 suggested above both to query the posts AND the featured images from that post to finish the job :) Thanks Tianbo84! To my understanding, the get_posts and <?php endforeach; ?> lines were key... like opening a query and then closing it once the data was retrieved.

Wordpress and the_content()

Anyone knows why the_content() doesn't show on my single.php page, while it shows up on index.php?
<div class="block">
<h1><?php the_title(); ?></h1>
<p class="date">
<?php the_date('d F Y'); ?>
</p>
<p>
<?php the_content(); ?>
</p>
</div>
in your single.php page nad index page the_*() functions are only designed to be used within the loop.
while(have_posts())
{
///the_content(); the_title(); the_post(); etc
}
//If I Used here then it would not work!

Resources