Wordpress-Loop: PHP-code is not working - wordpress

i'm currently struggling making my wordpress-loop working properly. I guess the error is in the IF-request. Could anyone please debug and optimize these few lines of PHP? I'm very interested in learning proper coding so don't hesitate to give me some further advices! ;-)
Would be amazing! All the best, enjoy your weekend!!!
<?php
?>
<?php get_header(); ?>
<!-- Start body -->
<body <?php body_class(); ?>>
<!-- Hier geht der Wrapper auf-->
<div class="wrapper">
<!-- Get Logo -->
<?php get_template_part( 'logo' ); ?>
<div class="clear"></div>
<!-- Wordpress verbieten, <p>-Tags zu setzen -->
<?php remove_filter ('the_content', 'wpautop'); ?>
<!-- T H E L O O P -->
<?php if ( have_posts() ): ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="article-content" id="post-<?php the_ID(); ?>">
<div class="article-thumb">
<?php the_content(); ?>
<div class="theid"><?php the_ID(); ?></div>
<?php if (in_category( "28" )){
echo '<a href="';
echo '#';
echo '" target="_blank"> link</a>';
}
else { echo 'Hi!'; ?>
<!-- Close article-thumb -->
</div>
<!-- Close article-content -->
</div>
<?php endwhile; ?>
<?php endif; ?>
<!-- /T H E L O O P -->
<!-- Clear -->
<div class="clear"></div>
<?php else: ?>
<h2>No posts to display</h2>
<?php endif; ?>
<?php wp_reset_query(); ?>
<!-- bottomnav -->
<div class="bottomnav"><a class="super next"><?php posts_nav_link(' / ','Zurück','Weitere Projekte'); ?></a></div>
<!-- Infinite Scroll -->
<script type="text/javascript">
$('.wrapper').infinitescroll({
loading: {
finished: undefined,
finishedMsg: "End.",
img: "http://www.injuvik.de/wp-content/themes/injuvik/img/pfeilnachunten.png",
msg: null,
msgText: "Loading..",
selector: null,
speed: 'fast',
start: undefined
},
navSelector: "div.bottomnav",
nextSelector: "div.bottomnav a:last",
itemSelector: "div.wrapper div.article-content",
animate: false
});
</script>
</div>
<!-- toggle class on click -->
<script>
$('body').on('click', 'div.article-content', function(){
$( this ).toggleClass( "bigger" );
});
</script>
<?php get_footer(); ?>

try to add to the end of the code
<?php endif; ?>
Also change:
echo 'Hi!';
}
/>
to
echo 'Hi!';
}
?>

Check This one out ! I just used it from Wordpress Documentation Wordpress Loop
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<?php if ( in_category( '28' ) ) : ?>
<div class="post-cat-three">
<?php else : ?>
<div class="post">
<?php endif; ?>
</div>
<?php endwhile; ?>
<?php else : ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1>Not Found</h1>
</div>
<?php endif; ?>

AWWW!
The solution was so simple! I just had two else-commands inside my index.php.
Thank you Guys!

Related

WordPress get_query_var() with offset?

I am currently using get_query_var() to displays all post in the index.php page, and I wonder if it's possible to skip the latest post ( I am already displaying it on the home page...) using any offset parameter ?
<div class="wrapper section-inner">
<div class="content full-width">
<?php if (have_posts()) : ?>
<div class="posts">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$total_post_count = wp_count_posts();
$published_post_count = $total_post_count->publish;
$total_pages = ceil( $published_post_count / $posts_per_page );
if ( "1" < $paged ) : ?>
<div class="page-title">
<h4><?php printf( __('Page %s of %s', 'hemingway'), $paged, $wp_query->max_num_pages ); ?></h4>
</div>
<div class="clear"></div>
<?php endif; ?>
<?php while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php get_template_part( 'content', get_post_format() ); ?>
</div> <!-- /post -->
<?php endwhile; ?>
</div> <!-- /posts -->
<?php endif; ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div class="post-nav archive-nav">
<?php echo get_next_posts_link( __('« Older<span> posts</span>', 'hemingway')); ?>
<?php echo get_previous_posts_link( __('Newer<span> posts</span> »', 'hemingway')); ?>
<div class="clear"></div>
</div> <!-- /post-nav archive-nav -->
<?php endif; ?>
</div> <!-- /content -->
</div> <!-- /wrapper -->
Thanks for your feedback and suggestions
One way is to skip the first index:
<?php
$i = 0;
while (have_posts()) : the_post();
if($i > 0):
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php get_template_part( 'content', get_post_format() ); ?>
</div> <!-- /post -->
<?php
endif;
i++;
endwhile;
?>

Wordpress Pagination

I have a wordpress site : There is a problem with the pagination.. When I click on 2'nd page it shows up the first one(index page). The other pages are working. Can you help me?
I looked up for errors in the loop but i didn't found anything!
this my index.php code
<?php get_header(); ?>
<div id="content">
<?php if(get_option('freshlife_featured_content_enable') == 'on') { ?>
<div id="featured-content">
<div class="heading">
<span class="heading-text"><?php _e('Featured Articles', 'themejunkie'); ?></span>
</div> <!-- end .heading -->
<ul>
<?php
$counter = 1;
query_posts( array(
'showposts' => get_option('freshlife_featured_post_num'),
'tag' => get_option('freshlife_featured_post_tags')
) );
if( have_posts() ) : while( have_posts() ) : the_post();
?>
<li class="featured-<?php echo $counter; ?>"><?php the_post_thumbnail('featured-thumb', array('class' => 'entry-thumb')); ?><span class="entry-date"><abbr title="<?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>"><?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . __(' ago', 'themejunkie'); ?></abbr></span><h2 class="entry-title"><?php the_title(); ?></h2></li>
<?php $counter++; endwhile; endif; wp_reset_query(); ?>
</ul>
</div> <!-- end #featured-content -->
<?php } ?>
<div class="heading">
<span class="heading-text"><?php _e('All Stories', 'themejunkie'); ?></span>
</div> <!-- end .heading -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php include(TEMPLATEPATH. '/includes/templates/loop.php'); ?>
<?php endwhile; ?>
<div class="clear"></div>
<?php if (function_exists('wp_pagenavi')) wp_pagenavi(); else { ?>
<div class="pagination">
<div class="left"><?php previous_posts_link(__('Newer Entries', 'themejunkie')) ?></div>
<div class="right"><?php next_posts_link(__('Older Entries', 'themejunkie')) ?></div>
<div class="clear"></div>
</div> <!-- end .pagination -->
<?php } ?>
<?php else : ?>
<?php endif; ?>
</div> <!-- end #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
It's hard to say without looking at the WP_Query generated by the requests.
But I do see something that might be causing problems, query_posts alters the main query, that could be messing with the pagination.
Try to use get_posts instead query_posts, so the main loop is not affected.
A more detailed explanation can be found here

WordPress Query Posts To Show All & Style Each One

I am trying to include every post onto my index page on WordPress and have each one of them be styled with the included CSS. I am able to query all of the posts and have them show up, but only the first post is actually styled. The rest inherit the base h1, h2, p and other generic styles, but they aren't inheriting the "box" class for each one. All of the information is being thrown into one 'box' class instead of starting a new 'box' class for each post like I would like it to do. Any help on this would be appreciated.
Here is my code I am using
<?php get_header(); ?>
<div id="index-float-left">
<div class="box">
<?php query_posts( 'showposts=-1' ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<p class="post-date"><?php echo $post_date = get_the_date(); ?></p>
</div>
</div> <!-- END BOX -->
</div> <!-- FLOAT BOX BOX -->
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
There is a problem with "End Box" and "Fload Box Box". Can you try like this:
<?php get_header(); ?>
<div id="index-float-left">
<?php query_posts( 'showposts=-1' ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="box">
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<p class="post-date"><?php echo $post_date = get_the_date(); ?></p>
</div>
</div> <!-- END BOX -->
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
</div> <!-- FLOAT BOX BOX -->
<?php get_sidebar(); ?>

How to call Custom Field in Wordpress Template

I want to call custom field in single.php template to complete a short code and thus show a menu.
I places the below code but it is not working
<?php echo do_shortcode("[custommenu menu=<?php echo get_post_meta($post->ID, ‘tabmenu’, true); ?>]?>")
Please help
Here's my template file
I saved this as single-default.php and calling it category wise from single.php file
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="content">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="tab-menu"><?php echo do_shortcode("[custommenu menu='".get_post_meta($post->ID, ‘tabmenu’, true)."']"); ?>
</div>
<div class="entry-content">
<?php if(get_option('resizable_integrate_singletop_enable') == 'on') echo (get_option('resizable_integration_single_top')); ?>
<?php the_content(''); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'themejunkie' ), 'after' => '</div>' ) ); ?>
<?php if(get_option('resizable_integrate_singlebottom_enable') == 'on') echo (get_option('resizable_integration_single_bottom')); ?>
<div class="clear"></div>
<?php printf(the_tags(__('<div class="entry-tags"><span>Tags:</span> ','themejunkie'),', ','</div>')); ?>
<?php edit_post_link('('.__('Edit', 'themejunkie').')', '<span class="entry-edit">', '</span>'); ?>
</div><!-- .entry-content -->
</div><!-- #post-<?php the_ID(); ?> -->
<div class="clear"></div>
<div class="entry-bottom">
<div class="clear"></div>
</div><!-- .entry-bottom -->
</div><!-- #content -->
<?php endwhile; else: ?>
<?php endif; ?>
You need to concatenate the inner echo in the shortcode
<?php echo do_shortcode("[custommenu menu='".get_post_meta($post->ID, ‘tabmenu’, true)."']"); ?>

Wordpress loop count

I have created a simple Wordpress loop already but now it should loop a little differently and i dont know how to start or even where to start. I have inside DIV class="item-row-wrap" my loop it loops through DIV class="vinyl-wrap" normally.
My problem: i would like it to loop three times and then to create a new DIV class="item-row-wrap" and start again looping DIV class="vinyl-wrap" three times...and go on and on
Here is the code:
<code>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if(get_field('artist-repeater')): while(has_sub_field('artist-repeater')): ?>
<div class="item-row-wrap"> <!--START of item-row-wrap-->
<div class="vinyl-wrap"> <!--START of vinyl-wrap-->
<?php if(get_sub_field('play-repeater-songlink')): ?>
<a class="play" href='<?php the_sub_field('play-repeater-songlink'); ?>' target="_blank"></a>
<?php endif; ?>
<?php if(get_sub_field('moreinfo-repeater-song')): ?>
<a class="more-info" href='<?php the_sub_field('moreinfo-repeater-song'); ?>' target="_blank"></a>
<?php endif; ?>
<div class="vinyl-cover">
<div class="vinyl-cover-plastik"></div>
<?php if(get_sub_field('album-repeater-image')): ?>
<?php $image = wp_get_attachment_image_src(get_sub_field('album-repeater-image'), 'thumbnail'); ?>
<img class="album-cover-art" src="<?php echo $image[0]; ?>" alt="<?php get_the_title(get_field('album-repeater-image')) ?>" />
<?php endif; ?>
</div> <!--End of vinyl-cover-->
<div class="likeit">
<?php if(function_exists(getILikeThis)) getILikeThis('get'); ?>
</div>
<div class="artist-name-wrap">
<div class="artist-wrap-left"></div>
<div class="artist-wrap-mid">
<p><?php the_title(); ?></p>
</div>
<div class="artist-wrap-right"></div>
</div> <!--End of artist-name-wrap-->
<div style="clear:both;"></div>
<div class="song-name-wrap">
<div class="song-wrap-left"></div>
<div class="song-wrap-mid">
<?php if(get_sub_field('song-repeater-name')): ?>
<p><?php the_sub_field('song-repeater-name'); ?></p>
<?php endif; ?>
</div>
<div class="song-wrap-right"></div>
</div> <!--end of song-name-wrap-->
</div> <!--END OF VINYL-WRAP-->
<?php endwhile; endif; ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php else: ?>
Yhtään artikkelia ei ole vielä julkaistu.
<?php endif; ?>
</div> <!--END OF ITEM-ROW-WRAP-->
Make $i var before the loop.
Up the value just before the loops closes: $i++
Set a Modulo check around the <div class="item-row-wrap"> (and the closing </div>)
Modulo tutorial
Not a complete answer but enough to get you started.
example
The example below shows how you should do this
<?php
$i = 0;
if (have_posts()) : while (have_posts()) : the_post();
if(get_field('artist-repeater')): while(has_sub_field('artist-repeater')):
if ($i % 3 == 0) {
echo '<div class="item-row-wrap"> <!--START of item-row-wrap-->';
}
$i++; // up the numer of looped
?>
DO your magic
<?php
if ($i % 3 == 0) {
echo '</div> <!--END OF ITEM-ROW-WRAP-->';
}
endwhile; //end have_posts()
endif;

Resources