I'm currently working on my first Wordpress theme and I've a problem:
I want to have my last 3 posts on every site. Everything works fine on my home page, but when I go to another page it just shows the page name and the "Read more..." tag after it.
The code I use is:
<?php while(have_posts()) : the_post(); ?>
<div class="article-preview">
<p>» <?php the_time('l, j. F Y')?></p>
<b><?php the_title(); ?></b>
<?php the_excerpt(); ?> Mehr...
<hr style="margin-top:5px" />
</div>
<?php endwhile; ?>
Does anyone know how to fix this issue? Thanks in advance!
For displaying posts on other pages, you have to display custom query before while loop.
Here is the updated code of your code:
<?php $the_query = new WP_Query( 'post_type'=>'post', 'posts_per_page=3' ); ?>
// Start our WP Query
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<div class="article-preview">
<p>» <?php the_time('l, j. F Y')?></p>
<b><?php the_title(); ?></b>
<?php the_excerpt(); ?> Mehr...
<hr style="margin-top:5px" />
</div>
<?php endwhile;
wp_reset_postdata();
?>
May be this would be helpful for you.
Related
Hello guys so I am making a car review wordpress magazine and I am having issues with php codes as I am not a great programmer. Actually on this page Memes I would like the social plugins to be below each picture and not on the top furthermore I would like it to display the post date and the author of the post. Some formatting for the pictures size etc would be great too. Below is the code I am using
<?php /*
Template Name: ListPostsInCategoryThatHasSameNameAsPage
*/ ?>
<?php get_header(); ?>
<div id="content" class="archive <?php if(get_option('colabs_layout_settings')=='two-col-right'){echo 'right';}else{?>left<?php }?>">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class(); ?> id="post_<?php the_ID(); ?>">
<span id="map"><?php _e('Home','colabsthemes');?> » <?php the_title(); ?></span>
<h2 class="title"><?php the_title(); ?></h2>
<div class="entry" style="padding-top:15px;">
<?php the_content(__('<p>Read the rest of this page »</p>','colabsthemes')); ?>
<?php echo colabs_share();?>
<?php wp_link_pages(array('before' => __('<p><strong>Pages:</strong>','colabsthemes'), 'after' => '</p>', 'next_or_number' => 'number')); ?>
</div>
</div>
<?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(); ?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?>
<?php endwhile; else: endif; ?>
</div>
</div>
<div id="sidebar" class="<?php if(get_option('colabs_layout_settings')=='two-col-right'){echo 'left';}else{?>right<?php }?>">
<?php get_sidebar(); ?>
</div>
<div> <?php get_footer(); ?> </div>
Finally for the review part I would like to do something like Autotest/review but I don't know which code to use to show these kind of square articles. Please help me out.
For adding the author and date of the post, you can add:
<p>Written by:
<?php get_the_author(); ?></p>
get_the_author() will display the author's name as is set in their "Display name publicly as" field in their user profile (Administration > Users > Your Profile).
To also display the date:
<p>Written by:
<?php get_the_author(); ?> on
<?php get_the_date(); ?></p>
I don't see where you're using the social sharing links on the page you linked to - did you remove them?
For more information:
http://codex.wordpress.org/Function_Reference/get_the_author
http://codex.wordpress.org/Function_Reference/get_the_date
hi i has a wordpress blog i put this code below within single.php page in side bar
the code is the same code in the hompage side bar >
this code is correctly work in hompage sidebar and return to all posts
but in the single.php sidebar only return to one post.
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="new-posts-form">
<div class="new-posts-img"><?php the_post_thumbnail(array(100,80)); ?></div>
<div class="new-posts-title"><?php the_title(); ?></div>
<div class="new-post-description"><?php content('11'); ?></div>
<div class="new-post-add-date-time"><img src="<?php bloginfo('template_url'); ?>/images/tb_clock.png" /><?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?> : <?php the_category(', ') ?></div>
<?php endwhile; ?>
<?php endif; ?>
I think on single.php page you should use this
for reference please check
http://codex.wordpress.org/Function_Reference/get_post
i am trying to solve your problem hope this help.
thanks
anand
Hi all looking for a Wordpress help. I need to place a simple query/array to display posts from a certain cat e.g "News' that will include the posts featured image.
Can anyone please help?
Gary
Try this
<?php
$query = new WP_Query('category_name=News&posts_per_page=4');
if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
if (has_post_thumbnail()) {
?>
<?php the_post_thumbnail(); ?>
<?php
}
?>
<h2><?php the_title(); ?></h2>
<?php
the_excerpt(); // or the_content(); for full post content
endwhile;endif;
?>
Don't use query_posts(). Its intention is to modify the default Wordpress Loop, and should not be used for general queries. Use WP Query or Get Posts instead.
Here's some documentation on Post Thumbnails
Here's a small example based on what you showed me that might work. Notice that 'showposts' has been changed to 'posts_per_page', as 'showposts' was deprecated as of version 2.1:
<?php
$q = new WP_Query(array('cat'=>8, 'posts_per_page'=>4));
if($q->have_posts()) : while($q->have_posts()) : $q->the_post();
the_excerpt();
if(has_post_thumbnail())
the_post_thumbnail('thumbnail');
endwhile;endif;
?>
UPDATE:
Based on the example you gave me, this should get you started:
<div id="slider2">
<div class="viewport">
<?php
$q = new WP_Query(array('cat'=>8, 'posts_per_page'=>4));
if($q->have_posts()) : while($q->have_posts()) : $q->the_post();
?>
<div class="newsPost">
<div class="news-date"><?php the_date(); ?></div>
<div class="newstitle"><?php the_title(); ?></div>
<div class="news-des"><?php the_excerpt(); ?></div>
<?php if(has_post_thumbnail()){ ?>
<div class="newsimg"><?php the_post_thumbnail(); ?></div>
<?php } ?>
<p>Read More...</p>
</div>
<?php endwhile;endif; ?>
</div>
</div>
I have a set-up a custom theme on my wordpress install. I have been developing with it locally and everything was working fine.
I uploaded to my server tonight and was setting up the fresh wordpress install. I turned on permalinks and all of a sudden my custom category pages are causing infinite re-direct loops.
My .htaccess is writable so I don't think its that problem (I have seen this mentioned a lot online).
The code from one of my custom pages is below - it pulls from a specific category - does anyone know how to fix this issue?
<?php get_header(); ?>
<?php
/*
Template Name: Podcasts
*/
?>
<ul class="mcol">
<?php
query_posts("cat=1");
while(have_posts()) : the_post(); ?>
<li class="article" id="post-<?php the_ID(); ?>">
<?php
if ( has_post_thumbnail() ) { ?>
<?php
$imgsrcparam = array(
'alt' => trim(strip_tags( $post- >post_excerpt )),
'title' => trim(strip_tags( $post->post_title )),
);
$thumbID = get_the_post_thumbnail( $post->ID, array(200,200), $imgsrcparam ); ?>
<div class="preview"><?php echo "$thumbID"; ?><div class="front-titles"><?php the_title(); ?></div></div>
<?php } else {?>
<div class="preview"><img src="<?php bloginfo('template_url'); ?>/images/default-thumbnail.jpg" alt="<?php the_title(); ?>" /></div>
<?php } ?>
<div class="article-over">
</div>
</li> <?php ?>
<?php endwhile;
//Reset Query
wp_reset_query();
?>
</ul>
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php else : ?>
<h1 id="error"><?php _e("Sorry, but you are looking for something that isn’t here."); ?></h1>
<?php endif; ?>
<div class="pagination"><?php previous_posts_link('<< Newer Entries', 0) ?> <?php next_posts_link('Older Entries >>', 0); ?> </div>
<?php get_footer(); ?>
Anyone any ideas? I'm quite new to this so am unsure as to what the problem might be...
What your doing is weird.
query_posts is meant to alter the main loop.
You have 2 loops with different syntax on the same page.
The second loop is not doing anything, so remove it, and use get_posts or WP Query for your custom query.
I have a page in Wordpress that displays posts with a category of "newspaper" only. Now, The posts are ordered by descending order (I think, if that is the default), such that the newest is at the top.
This is the code that I have:
<?php $my_query = new WP_Query('category_name=newspaper&posts_per_page=-1'); ?>
<?php if (have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="post">
<!--<h3><?php the_title(); ?></h3>-->
<?php the_content('Read the rest of this entry »'); ?>
<div class="clear"></div>
</div>
<?php endwhile; endif;?>
I was wondering if it's possible to show posts with a "featured" tag at the top, while all other posts without a featured tag afterward.
Thanks!
Amit
Okay this is what I temporarily did. I didn't rely on a featured tag, but rather on a featured-newspaper category. It's not exactly how I wanted it to be, but this will do for now:
<?php $my_query = new WP_Query('category_name=newspaper&posts_per_page=-1'); ?>
<?php $my_featured = new WP_Query('category_name=featured-newspaper&posts_per_page=-1'); ?>
<!-- featured posts -->
<?php if (have_posts()) : while ($my_featured->have_posts()) : $my_featured->the_post(); ?>
<div class="post">
<!--<h3><?php the_title(); ?></h3>-->
<?php the_content('Read the rest of this entry »'); ?>
<div class="clear"></div>
</div>
<?php endwhile; endif;?>
<!-- /end featured -->
<?php if (have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="post">
<!--<h3><?php the_title(); ?></h3>-->
<?php the_content('Read the rest of this entry »'); ?>
<div class="clear"></div>
</div>
<?php endwhile; endif;?>
Like I said, it's not the cleanest way to do things, but it works. If you have other suggestions, I'm all ears :)
Thanks!
Amit