I need some help trying to figure this out, but currently, when I post a post on the Manhusay Theme on my Wordpress Site, it repeats it 3 times and replaces the other posts. The site is www.pcrmj.com. Here is the script that is currently in there if anyone has any suggestions or ways of correcting this.
<?php get_header(); ?>
<div id="content">
<div class="postgroup">
<?php for($i=1;$i<4;$i++) : ?>
<?php
$latest = get_option('mahusay_category_' . $i);
$latcat = (empty($latest)) ? 1 : get_category_by_slug($latest);
query_posts('showposts=1&cat='.$latcat->cat_ID);
?>
<?php while (have_posts()) : the_post(); ?>
<div class="post indexpost" id="post-<?php the_ID(); ?>">
<?php
$customfields = get_post_custom();
$scrp = get_bloginfo('wpurl') . '/tt-scripts/timthumb.php?';
if (empty($customfields['paddimage'][0])) {
$imgpath = $scrp . 'src=' . get_bloginfo('wpurl') . '/wp-content/themes/mahusay/images/thumbnail.png' . '&w=125&h=125&zc=1';
} else {
$imgpath = $scrp . 'src=' . get_bloginfo('wpurl') . $customfields['paddimage'][0] . '&w=125&h=125&zc=1';
}
?>
<div class="title">
<p>
<span class="date"><?php the_time('F j, Y'); ?></span>
<span class="nodisplay">|</span>
<span class="comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span>
<span class="nodisplay">|</span>
<span class="categories"><?php echo $latcat->cat_name; ?></span>
</p>
</div>
<img class="header" src="<?php echo $imgpath; ?>" alt="<?php the_title(); ?>" />
<div class="entry">
<h2 class="title"><?php the_title(); ?></h2>
<?php themefunction_content(400,'');?>
</div>
</div>
<?php endwhile; ?>
<?php endfor; ?>
</div>
<div class="extra">
<div class="box box-popular">
<h2>Popular</h2>
<div class="interior">
<ul>
<?php akpc_most_popular(5,'<li><span>','</span></li>'); ?>
</ul>
</div>
</div>
<div class="box box-recent">
<h2>Recent</h2>
<div class="interior">
<?php themefunction_recent_post(); ?>
</div>
</div>
<div class="clearer"></div>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Also, Thumbnail.png is not appearing. If anybody can help, that would be great.
First thing to do is after the following line...
<?php endfor; ?>
Add...
<?php wp_reset_query(); ?>
This resets the query back to what the query for that page should be and will stop any query_posts functions effecting other loops on the page.
Related
I'm currently working on a website for a client and I want to change the search results page. I tried a lot of things but when I search for something on the website I get search results, but without a image or description. My client want the website to show a image and a description.
Here is my search.php code:
/**
* The search template file.
*
* #package Betheme
* #author Muffin group
* #link https://muffingroup.com
*/
get_header();
$translate['search-title'] = mfn_opts_get('translate') ? mfn_opts_get('translate-search-title','Ooops...') : __('Ooops...','betheme');
$translate['search-subtitle'] = mfn_opts_get('translate') ? mfn_opts_get('translate-search-subtitle','No results found for:') : __('No results found for:','betheme');
$translate['published'] = mfn_opts_get('translate') ? mfn_opts_get('translate-published','Published by') : __('Published by','betheme');
$translate['at'] = mfn_opts_get('translate') ? mfn_opts_get('translate-at','at') : __('at','betheme');
$translate['readmore'] = mfn_opts_get('translate') ? mfn_opts_get('translate-readmore','Read more') : __('Read more','betheme');
?>
<div id="Content">
<div class="content_wrapper clearfix">
<div class="sections_group">
<div class="section">
<div class="section_wrapper clearfix">
<?php if( have_posts() && trim( $_GET['s'] ) ): ?>
<div class="column one column_blog">
<div class="blog_wrapper isotope_wrapper">
<div class="posts_group classic">
<?php
while ( have_posts() ):
the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class( array('post-item', 'clearfix', 'no-img') ); ?>>
<div class="post-desc-wrapper">
<div class="post-desc">
<?php if( mfn_opts_get( 'blog-meta' ) ): ?>
<div class="post-meta clearfix">
<div class="author-date">
<span class="author"><span><?php echo esc_html($translate['published']); ?> </span><i class="icon-user"></i> <?php the_author_meta('display_name'); ?></span>
<span class="date"><span><?php echo esc_html($translate['at']); ?> </span><i class="icon-clock"></i> <?php echo esc_html(get_the_date()); ?></span>
</div>
</div>
<?php endif; ?>
<div class="post-title">
<h2><?php the_title(); ?></h2>
</div>
<div class="post-excerpt">
<?php the_excerpt(); ?>
</div>
<div class="post-footer">
<div class="post-links">
<i class="icon-doc-text"></i> <?php echo esc_html($translate['readmore']); ?>
</div>
</div>
</div>
</div>
</div>
<?php
endwhile;
?>
</div>
<?php
if(function_exists( 'mfn_pagination' )):
echo mfn_pagination();
else:
?>
<div class="nav-next"><?php next_posts_link(esc_html__('← Older Entries', 'betheme')) ?></div>
<div class="nav-previous"><?php previous_posts_link(esc_html__('Newer Entries →', 'betheme')) ?></div>
<?php
endif;
?>
</div>
</div>
<?php else: ?>
<div class="column one search-not-found">
<div class="snf-pic">
<i class="themecolor <?php echo esc_attr(mfn_opts_get('error404-icon', 'icon-traffic-cone')); ?>"></i>
</div>
<div class="snf-desc">
<h2><?php echo esc_html($translate['search-title']); ?></h2>
<h4><?php echo esc_html($translate['search-subtitle']) .' '. esc_html($_GET['s']); ?></h4>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php if( is_active_sidebar( 'mfn-search' ) ): ?>
<div class="sidebar four columns">
<div class="widget-area clearfix <?php echo esc_attr(mfn_opts_get('sidebar-lines')); ?>">
<?php dynamic_sidebar( 'mfn-search' ); ?>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php get_footer();
<?php $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full'); ?>
<div class="post-img">
<img src="<?php echo $featured_img_url; ?>"/>
</div>
use above code in while loop to show image by using post id.
I am able to display next and previous post in worspress but unable to show second-previous or third-previous || second-next or third-next like
1 - I want to show this too
2 - this is showing
3 - My Current post
4 - This is showing
5 - I want to show this too
any help would be appreciated.
In the and I am showing you my code so you can judge.
CODE:
<?php $next = get_permalink(get_adjacent_post(false,'',false)); if
($next != get_permalink()) { ?><a href="<?php echo $next; ?>">
<li class="col-xs-12 col-md-4">
<div class="article">
<div class="contain-image">
<?php $nextPost = get_next_post(true); $nextthumbnail = get_the_post_thumbnail($nextPost->ID); echo $nextthumbnail; ?>
</div>
<div class="content">
<div class="double-content">
<div class="information">
<span class="category"><?php echo get_cat_name(1);?></span>
<span class="time"><?php the_time('M j, Y') ?></span>
</div>
<div class="title">
<?php next_post_link('%link', "%title", TRUE); ?>
</div>
<p>
<?php
$Nextpost = get_next_post($id);
echo apply_filters(‘the_content’, $Nextpost->post_content);
?>
</p>
</div>
</div>
</div>
</li>
</a>
<?php } ?>
<?php $prev = get_permalink(get_adjacent_post(true,'',true)); if
($prev != get_permalink()) { ?><a href="<?php echo $prev; ?>">
<li class="col-xs-12 col-md-4">
<div class="article">
<div class="contain-image">
<?php $prevPost = get_previous_post(true); $prevThumbnail = get_the_post_thumbnail($prevPost->ID); echo $prevThumbnail; ?>
</div>
<div class="content">
<div class="double-content">
<div class="information">
<span class="category"><?php echo get_cat_name(1);?></span>
<span class="time"><?php the_time('M j, Y') ?></span>
</div>
<div class="title">
<?php previous_post_link('%link', "%title", TRUE); ?>
</div>
<p>
<?php
$Prevpost = get_previous_post($id);
echo apply_filters(‘the_content’, $Prevpost->post_content);
?>
</p>
</div>
</div>
</div>
</li>
</a>
<?php } ?>
WordPress provides several navigational template tags to make it easy for visitors to surf your pages. There are basically two different types of template tags used for chronological post navigation:
posts_nav_link() – for navigating various archive (non-single) pages
previous_post_link() & next_post_link() – for navigating single-post pages
<?php $posts = query_posts($query_string); if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php previous_post_link(); ?> | <?php next_post_link(); ?>
<?php endwhile; endif; ?>
try this:
global $post;
$post_curr = $post;
//get last post
$post_last1 = get_previous_post();
setup_postdata($post_last1);
//get second last post
$post_last2 = get_previous_post();
setup_postdata($post_curr);
//get next post now
$post_next1 = get_next_post();
setup_postdata($post_next1);
//get second next post
$post_next2 = get_next_post();
//reset current post data
setup_postdata($post_curr);
I am building a WP site, which will have a News and Blog.
They will be in separate pages, One for news and one for Blog, which will be separated by categories.
So for example, I have this code on 'News', which stops the loop getting posts:
<?php
$uncat = get_cat_ID('uncategorised');
$uncat2 = get_cat_ID('blog');
$args = array(
'posts_per_page' => 3,
'category__not_in' => array($uncat, $uncat2)
);
$loop = new WP_Query( $args );
while ($loop->have_posts() ) : $loop->the_post();
?>
<div class="col-md-12 col-sm-12 col-xs-12" style="padding-left:0; padding-right:0;">
<a style="color:#333; text-decoration:none;" href="<?php echo get_permalink(); ?>">
<div class="postsize">
<div class="leftfloat" style="float: left; padding-right:20px;">
<?php echo get_the_post_thumbnail( $page->ID, 'categoryimage', array('class' => 'faqposts')); ?>
</div>
<div class="contentfaq">
<h4><?php the_title(); ?></h3>
<span class="entry-date-blue"><strong><?php echo get_the_date('d/m/y'); ?></strong></span>
<?php $trimexcerpt = get_the_excerpt();
$shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 10, $more = '… <br/> Read More ...' );
echo '<a style="color:#333; text-decoration:none;" href="' . get_permalink() . '"><p>' . $shortexcerpt . '</p></a>';
?>
</div>
</div>
</div>
</a>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
This works fine, but I also have 'Archives' on the right hand side, which filters by date posted. The issue is, this will get posts from News AND blog, which defeats the idea of splitting them up.
Is there a way to split these up, so if the user clicks 'March 2015' on the archive, it will only get the posts from this month from NEWS?
Here is my current code for Archive.php
<?php if (have_posts()) : ?>
<!-- First, the loop checks whether any posts were discovered with the have_posts() function. -->
<!-- If there were any posts, a PHP while loop is started. A while loop will continue to execute as long as the condition in the parenthesis is logically true. So, as long as the function have_posts() returns a true value, the while loop will keep looping (repeating). -->
<?php while (have_posts()) : the_post(); ?>
<div class="col-md-12 col-sm-12 col-xs-12">
<a href="<?php echo get_permalink(); ?>">
<div class="postsize">
<div style="float: left; padding-right:20px;">
<?php echo get_the_post_thumbnail( $page->ID, 'categoryimage', array('class' => 'faqposts')); ?>
</div>
<h5 class="captext"><?php the_title(); ?></h5>
<span class="entry-date-orange"><?php echo get_the_date(); ?></span>
<?php
foreach((get_the_category()) as $category) {
echo ' | ' . $category->cat_name;
}
?>
<p style="margin-top:10px";><?php the_excerpt(); ?></p>
</div>
</a>
</div>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
Try this , it will echo list
<h2>Archives by Month:</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
<h2>Archives by Subject:</h2>
<ul>
<?php wp_list_categories(); ?>
</ul>
full example code
<?php
/*
Template Name: Archives
*/
get_header(); ?>
<div id="container">
<div id="content" role="main">
<?php the_post(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php get_search_form(); ?>
<h2>Archives by Month:</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
<h2>Archives by Subject:</h2>
<ul>
<?php wp_list_categories(); ?>
</ul>
</div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I am not finding out why archive.php only shows maximum 10 posts in a category... Could you please help to find where the bug is?
<div id="blogg_header" class="col col-lg-12 col-sm-12"><div class="well">
<?php if (is_category()) {?>
<h1 class="title">Kategori: <i><?php single_cat_title(); ?> </i></h1>
<?php } elseif (is_month()) { ?>
<h2 clss="title"><?php the_time('F, Y'); ?></h2>
<?php } ?>
</div></div>
<div id="blogg_innlegg_left" class="col col-lg-8 col-sm-8"><div class="well">
<ul>
<?php if (have_posts()) :?>
<?php while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<a class id="linkforside" href="<?php the_permalink(); ?>">
<?php get_the_post_thumbnail($header_thumb->ID);?><br/>
</a>
<p class id="infotekst"><?php the_time('d.m.Y') ?></p>
<p class="blogg_innlegg_teksten"><?php echo substr(strip_tags($post->post_content), 0, 250);?></p>
<?php endwhile; ?>
<?php else : ?>
<h2>Ingenting ble funnet.</h2>
<?php endif; ?>
</ul>
</div></div>
I guess I may need to insert the following:
<?php wp_get_archives('type=postbypost&limit=none'); ?>
Any ideas why the_content() is returning null? When I use $page->content in the same place, this returns the correct value from database.
<?php get_header(); ?>
<div id="main" class="clearfix" role="main">
<?php $attachments = new Attachments( 'attachments' ); ?>
<?php if( $attachments->exist() ) : ?>
<div id="myCarousel" class="carousel">
<!-- Carousel items -->
<div class="carousel-inner">
<?php $i = 0; while( $attachments->get() ) : $i++; ?>
<div class="<?php if($i == 1){ echo 'active'; } ?> item item-<?php echo $attachments->id(); ?>">
<?php echo $attachments->image( 'featured-home' ); ?>
<?php if($attachments->field('caption')){ ?>
<div class="carousel-caption">
<?php echo $attachments->field('caption'); ?>
</div>
<?php } ?>
</div>
<?php endwhile; ?>
</div>
<?php if($i > 1) { ?>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
<?php } ?>
<div class="carousel-overlay icons">
Facebook
Twitter
YouTube
RSS Feed
</div>
</div>
<?php endif; ?>
<?php if (have_posts()) : ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(array('row-fluid','clearfix')); ?> role="article">
<div id="content" class="span8">
<header>
<h1><?php echo get_post_meta($post->ID, 'custom_tagline' , true);?></h1>
<?php the_content(); ?>
</header>
<section class="post_content hasSidebar">
<?php query_posts('showposts=10');
while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article">
<header>
<?php the_post_thumbnail( 'wpbs-featured' ); ?>
<h2><?php the_title(); ?></h2>
<?php if(get_comments_number() >= 1): ?>
<a href="<?php comments_link() ?>" title="<?php comment_date() . ' - ' . comment_excerpt(); ?>" <?php comment_class(); ?>><?php comments_number(); ?></a>
<?php endif; ?>
<p class="meta"><?php _e("Posted", "bonestheme"); ?> <time datetime="<?php echo the_time('Y-m-j'); ?>" pubdate><?php the_date(); ?></time> <?php _e("by", "bonestheme"); ?> <?php the_author_posts_link(); ?> <span class="amp">&</span> <?php _e("filed under", "bonestheme"); ?> <?php the_category(', '); ?>.</p>
</header>
<section class="post_content">
<?php the_excerpt(); ?>
</section>
<?php if(has_tag()): ?>
<footer>
<p class="tags"><?php the_tags('<span class="tags-title">' . __("Tags","bonestheme") . ':</span> ', ' ', ''); ?></p>
</footer>
<?php endif; ?>
</article>
<?php endwhile ?>
<?php content_paging_nav('nav-below'); ?>
</section>
<footer>
<p class="clearfix"><?php the_tags('<span class="tags">' . __("Tags","bonestheme") . ': ', ', ', '</span>'); ?></p>
</footer>
</div>
<?php get_sidebar('sidebar2'); ?>
</article>
<?php else : ?>
<article id="post-not-found">
<header>
<h1><?php _e("Not Found", "bonestheme"); ?></h1>
</header>
<section class="post_content">
<p><?php _e("Apologies, but no results were found. Perhaps searching will help find a related post.", "bonestheme"); ?></p>
</section>
<footer>
</footer>
</article>
<?php endif; ?>
</div> <!-- end #main -->
<?php //get_sidebar(); // sidebar 1 ?>
<?php get_footer(); ?>
You're not in a WP loop. You should call e.g. the_post() to set up WP's slew of globals.
Beware of nested WP loops, too. There used to be a gazillion bugs related to them, and there might still be a few lying around just waiting to bite.