• Hello, this is my first post and I read through quite some topics and reference pages before creating this post. If I overread something or am not aware of certain rules of posting I apologize.

    I want to display 5 posts in a div container. Below the container (or on the bottom of it) I want to have two buttons. The first button (down arrow) should load the next 5 posts and the second one (up arrow) should go back and display the previous 5 posts.

    Ideally I would want to load all posts of certain category this way, meaning if I press button 1 (down arrow) multiple times it goes on until the last post is shown.

Viewing 1 replies (of 1 total)
  • Thread Starter tchaecker

    (@tchaecker)

    So, after more research I managed to display 5 posts using a shortcode. Now my problem is to create working links. Currently the links are working I would add it into a page but not inside a div.

    Any recommendation on how to them work to display the next posts in the div?

    <?php
    
    function myLoop($atts, $content = null) {
    	extract(shortcode_atts(array(
    		"pagination" => 'true',
    		"query" => '',
    		"category" => '',
    	), $atts));
    	global $wp_query,$paged,$post;
    	$temp = $wp_query;
    	$wp_query= null;
    	$wp_query = new WP_Query();
    	if($pagination == 'true'){
    		$query .= '&paged='.$paged;
    	}
    	if(!empty($category)){
    		$query .= '&category_name='.$category;
    	}
    	if(!empty($query)){
    		$query .= $query;
    	}
    	$wp_query->query($query);
    	ob_start();
    	?>
    
    	<div id="newscontainer">
    
    	<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    
    <div class="news">
      <div class="nachrichten-datum"><p><?php the_date('j. F'); ?></p><h3><?php echo the_title(); ?></h3></div>
      <div class="weiterlesen"><a href="<?php the_permalink() ?>">mehr lesen >></a></div>
    </div>
    <div class="trennlinie"></div>
    	<?php endwhile; ?>
    
    		<div class="news-navigation">
    	  <div class="alignleft"><?php previous_posts_link('? Previous') ?></div>
    	  <div class="alignright"><?php next_posts_link('More ?') ?></div>
    	</div>
    	<?php if(pagination == 'true'){ ?>
    
    	<?php } ?>
    </div>
    	<?php $wp_query = null; $wp_query = $temp;
    	$content = ob_get_contents();
    	ob_end_clean();
    	return $content;
    }
    add_shortcode("loop", "myLoop");
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Display posts in container, changing per button click’ is closed to new replies.