function shortcode to display latest post and (more..) link not working help

Discussion in 'WordPress' started by macaela, May 14, 2012.

  1. #1
    Hi i have tried this two function to display the last post on the homepage but both of them not working can someone help me so that one of them work?

    the first almost work except its display the last post twice on the homepage twice and i cannot position even thou I have the short code inside a div box it shows at the top and bottom of content.

    the second one the (more..) link doesnt work

    click on the (click here to see the function txt file) to see the actual functions on my site. http://eurico.co.uk/

    help will b much appreciated thanks
     
    macaela, May 14, 2012 IP
  2. ColorVila

    ColorVila Greenhorn

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #2
    Paste your homepage code here, let us have a check that.
     
    ColorVila, May 14, 2012 IP
  3. macaela

    macaela Active Member

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    Hi these are the two functions i am trying to fix one of them, recap so that display the latest post and the more link to cut off the post.

    this one is displaying the last post twice on the homepage at the top and bottom even thou i place the [shortcode] inside a div.
    <?php 
    function wptuts_working_shortcode($atts, $content=null){?>
    	<div class="left home_bot_box"><!-- START LOOP TO DISPLAY LATEST POST ONLY-->
    		<h2>latest</h2>
        
    <?php 
    global $more;    // Declare global $more (before the loop).
    $more = 0;       // Set (inside the loop) to display content above the more tag.
    ?>
    
    <?php
    // set while loop to display only post of category latest-news and one post only per page
    query_posts('category_name=latest-news&posts_per_page=1');
    ?>
    
    <?php while (have_posts()) : the_post(); ?>
    		<p><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></p>
    		<p><?php the_content(__('more…')); ?></p>
    	</div> <!-- END LOOP FOR POST ONLY-->
    
    
    <?php endwhile;
    
    ?>
    
    <?php  }  
    add_shortcode('working', 'wptuts_working_shortcode');
    
    ?>
    PHP:
    and this this one I cannot get it to display the the more button even thou I placed the (<!--more-->) to cut off the text and show the more link.
    <?php
    
    
        function wptuts_recentpost($atts, $content=null){  
    	  global $more;    // Declare global $more (before the loop).
      	$more = 0;       // Set (inside the loop) to display content above the more tag.
          
            $getpost = get_posts( array('number' => 1) );  
          
            $getpost = $getpost[0];  
          
            $return = $getpost->post_title . "<br />" . $getpost->post_content . "…";  
          
    $return = $getpost->post_title . "<br />" . apply_filters('the_content',$getpost->post_content) . "…";      
            return $return;  
          
        }  
        add_shortcode('newestpost', 'wptuts_recentpost');  
    
    ?>
    PHP:
     
    macaela, May 15, 2012 IP