SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    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

  2. #2
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here my code in case anyone have time to have a look at it
    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 Code:
    <?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');

    ?>

    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 Code:
    <?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');  

    ?>

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Location
    New Delhi
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can copy the code from sidebar.php or as below for latest 10 articles

    "<?php
    $args = array( 'numberposts' => 10, 'order'=> 'ASC', 'orderby' => 'title' );
    $postslist = get_posts( $args );
    foreach ($postslist as $post) : setup_postdata($post); ?>
    <div>
    <?php the_date(); ?>
    <br />
    <?php the_title(); ?>
    <?php the_excerpt(); ?>
    </div>
    <?php endforeach; ?>"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •