This is my first time on here so apologies if something like this has been asked before.
My current sites has 2 posts per row but I want the first/latest post to be styled slightly different.
Basically I want the first/latest post to be 100% wide on the page then all the other posts to follow, 2 per row but only on the home page. Category pages etc I'm happy for that to stay 2 per row.
My current code is:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<article class="post-item clearfix" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<figure>
<?php the_post_thumbnail('single-post-feature'); ?>
</figure>
<header>
<div class="post-header-title">
<div class="post-category-feature">
<?php echo get_the_category_list(); ?>
</div>
<?php if ( is_singular() ) { echo '<h1>'; } else { echo '<h2>'; } ?><span><a class="black" href="<?php the_permalink(); ?>"title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a></span><?php if ( is_singular() ) { echo '</h1>'; } else { echo '</h2>'; } ?>
<div id="excerpt"><?php the_excerpt(); ?></div>
<div id="author_date"><p><span><?php the_time('jS F Y') ?> | by <?php the_author(''); ?></span></p></div>
</div>
</header>
</article>
<?php endwhile; ?>
<?php endif; ?>
</div>
Any help would be greatly appreciated. If you would like to see the site to understand what I mean it is www.ltstlife.com. Thanks again.
I cannot get my posts to display on a category page.
It finds if the posts are within and category and displays content fine.. But the loop I am using does not bring in the posts.. Any help would be great.
<?php if (is_category(array(4, 5, 6))) { ?>
<?php if (have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div class="case-study-box">
<a href="<?php the_permalink(); ?>">
<div class="post-img ripple-me" style="background-image: url(<?php the_field('thumbnail_image'); ?>)">
</div>
</a>
<div class="post-intro">
<span><?php the_category(' '); ?></span>
<?php the_title('<h4>', '</h4>'); ?>
Read more
</div>
</div>
<!--Close .case-study-box -->
<?php endwhile; else: ?>
<?php endif; ?>
<?php } else { ?>
I am trying to setup a custom page, you can take a look here:
http://dageniusmarketer.com/download-the-book-now
and im using this code for my custom page. The sidebars as far as i can tell have IDs of "navigation", and "sidebar", however, the rules i am applying to them are not working. I tried a test rule with the ID "content", and it works as expected. Why am i not able to hide the sidebars? Something isn't making sense.
<?php
/*
* Template Name: My Custom Page
* Description: A Page Template with No Sidebars.
*/
?>
<?php get_header(); ?>
<!--single.php-->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post">
<h2 id="post-<?php the_ID(); ?>">
<a href="<?php echo get_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
<?php the_title(); ?></a></h2>
<?php the_content(); ?>
<?php wp_link_pages(); ?>
<p class="metadata">
<?php printf(__('%1$s %2$s', 'mtsgossip'), $time_since, get_the_time(__('l, F jS, Y', 'mtsjourney')), get_the_time()); ?>,
<?php _e('by ','mtsjourney');?> <?php the_author();?>
<?php _e('and is filed under','mtsjourney'); ?> "<?php the_category(', ') ?> ".
<?php if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
// Kommentare und Pingen erlaubt ?>
<?php _e('You can','mtsjourney'); ?> <?php _e('leave a response here','mtsjourney'); ?>,
<?php _e('or send a','mtsjourney'); ?>
<a href="<?php trackback_url(true); ?>" ><?php _e('Trackback','mtsjourney'); ?></a>
<?php _e('from your own site','mtsjourney'); ?>.
<?php } elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
// Nur Pingen erlaubt ?>
<?php _e('Responses are currently closed, but you can send a','mtsjourney'); ?>
<a href="<?php trackback_url(true); ?>" >
<?php _e('Trackback','mtsjourney'); ?></a>
<?php _e('from your own site','mtsjourney'); ?>.
<?php } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
// Kommentare geschlossen, Pingen erlaubt ?>
<?php _e('You can','mtsjourney'); ?>
<?php _e('leave a response here','mtsjourney'); ?>.
<?php _e('Pinging is currently not allowed','mtsjourney'); ?>.
<?php } elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
// Kommentare und Pings sind nicht erlaubt. ?>
<?php _e('Both comments and pings are currently closed','mtsjourney'); ?>.
<?php } edit_post_link('E','',''); ?>
</p>
</div>
<div id="navigation" style="margin-left:200px;"></div>
<div id="sidebar" style="display:none"></div>
<div id="content" style="width:900px"></div>
<!--postend-->
<p class="navigate">
<?php previous_post_link('« %link') ?>
||
<?php next_post_link(' %link »') ?>
</p>
<?php endwhile; endif;?>
<!--post end-->
<!--single.php end-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Looking at the page structure, I tried to remove left and right sidebar by adding following styles.
Put the following styles as inline css in the desired template, so that it don't affect the layout of any other page. Hope this helps.
div#navigation
{
display:none;
}
div#sidebar
{
display:none;
}
div#content
{
margin: 5px 0 75px 0;
}
Your sidebar is being called with this line:
<?php get_sidebar(); ?>
You can try commenting it out to hide the sidebar:
<?php //get_sidebar(); ?>
You have two divs with the "sidebar" id, the one we can see in the code you posted (Which has the styles) and the one that eventually gets created by <?php get_sidebar(); ?>
These are not the same elements, so to fix your problem just remove that superfluous sidebar and apply the styles in your stylesheet.
Why dont you delete all the content of sidebar.php? so, all other files that call it will show nothing.
your sidebar is being called with this line
<?php get_sidebar(); ?>
try to comment it
I have a wordpress site I am creating.
on the post pages, I have text widget with PHP allowed, where I have a custom loop:
<?php $my_query2 = new WP_Query("showposts=1&cat=9,10,11,18,19&orderby=rand"); ?>
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink() ?>">
<div class="home-widget-thumb">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail('home-thumb');
}
?>
</div>
<h2><?php the_title(); ?></h2></a>
<div class="body">
<?php echo get_the_excerpt(); ?>
</div><!--body-->
</br>
<span class="more-link">
[more]
</span>
<?php endwhile; ?>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
For some reason, whatever blog post you are on is the same as in the loop I created.
See an example here:
http://counselingandtraining.com/play-therapy/
The loop for the post is not modified.
Can anyone tell me why this is happening?
Let me know if I can provide further info.
Thanks in advance for your time.
Chris
It looks to me like the problem is that you are still using the base query.
You can change this by adding your variable $my_query2 in the code like this:
<?php if ($my_query2->have_posts()) : ?><?php while ($my_query2->have_posts()) : $my_query2->the_post(); ?>
This will make all the functions like the_title(), the_content(), etc work as intended since they will be set to $my_query2.
On both the front page and the blog page - the sidebar shows the most recent post, which I find doesn't look very good duplicated against the same post expanded on the main page.
This is my code for the sidebar:
<div class="blog-sidebar">
<?php query_posts('showposts=5'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="blog-sidebar-feature">
<?php if ( has_post_thumbnail() ) { ?>
<div class="blog-sidebar-image"><?php the_post_thumbnail('medium'); ?></div>
<?php
}
?>
<div class="blog-sidebar-content">
<p class="date"><?php the_time('F j, Y') ?></p>
<h3 <strong><?php
foreach((get_the_category()) as $category) {
echo $category->cat_name . ' ';
}
?></strong></h3>
<h2 <p><a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_title();
?></a></p></h2><?php echo get_excerpt(166); ?>
</div>
</div>
<?php endwhile;?>
<br />
<?php wp_pagenavi(); ?>
</div>
and the relevant code for how the blog appears on the home page:
<div class="blog-sidebar">
<div class="blog-sidebar-feature">
<?php query_posts('orderby=date&order=DESC&showposts=2'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="blog-sidebar-image"><?php the_post_thumbnail('medium'); ?></div>
<?php
}
?>
<div class="blog-sidebar-content">
<p class="date"><?php the_time('F j, Y') ?></p>
<h3 <strong><?php
foreach((get_the_category()) as $category) {
echo $category->cat_name . ' ';
}
?></strong></h3>
<h2 <p><a href="<?php the_permalink() ?>"
rel="bookmark" title=""><?php the_title(); ?></a></p></h2><?php echo get_excerpt(166); ?>
</div>
<?php endwhile;?>
</div>
</div>
<div id="connect">
<?php query_posts('page_id=1');
while (have_posts()): the_post();
the_content();
endwhile;
wp_reset_query(); ?>
</div>
Is there any way to remove only the most recent post from the sidebar when it appears in full on the main container? Thanks in advance for any help.
UPDATE V2
So you do want recent posts, just not the post currently showing in the main content.
UPDATE V3:
This should work now. I had to change arguments of query_posts to array to make it work.
Try it now:
<?
global $wp_query;
$skip_posts=array();
if (is_single()) //only exclude posts when single post is shown
$skip_posts[]=$wp_query->post->ID;
?>
<?php query_posts( array( 'showposts'=>5,'post__not_in'=>$skip_posts)); ?>
<?php query_posts('posts_per_page=5&offset=1'); ?>
Thanks to 850010 for all the help, I went back and had a look at the offset rule and the 'array' wasn't needed. Deceptively simple.