WordPress.org

Ready to get started?Download WordPress

Forums

Recent posts carousel shortcode (6 posts)

  1. AlexanderBeloev
    Member
    Posted 10 months ago #

    Hello there,

    First off I want to introduce myself.

    My name is Alex, I am 23 and I have started learning wordpress a couple of months ago.

    I wanted to ask you a question about shortcodes. I have the following code, that I want to transform into a wordpress shortcode with 3 variables: title, number_of_posts and category. I have tried a lot of different ways, but simply it doesn't work. Here is the code I have:

    <h3>You may also like...</h3>
    <div class="list_carousel responsive">
    	<ul id="foo2">
    		<?php
    			$args = array( 'numberposts' => '5' );
    			$recent_posts = wp_get_recent_posts( $args );
    			foreach( $recent_posts as $recent ){
    				if ( has_post_thumbnail($recent["ID"])) {
    					echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . get_the_post_thumbnail($recent["ID"], 'large') . '</a>
    					<a href="' . get_permalink($recent["ID"]) . '" class="carousel-post-title" title="Look '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a> </li>';
    				}
    			}
    		?>
    	</ul>
    	<div class="clearfix"></div>
    	<a id="prev2" class="prev" href="#"><</a>
    	<a id="next2" class="next" href="#">></a>
    </div>

    Thank you all in advance!

    Regards,

    Alex :)

  2. esmi
    Forum Moderator
    Posted 10 months ago #

    Have you reviewed the Shortcode_API?

  3. AlexanderBeloev
    Member
    Posted 10 months ago #

    Hey Esmi,

    Yes I have read thru it.

    If it will be easier for you, I can post the code that I ended up with, but it still doesn't work?

  4. esmi
    Forum Moderator
    Posted 10 months ago #

    If the code is more than about a dozen lines long, it would be better to use a pastebin and post the pastebin url here.

  5. AlexanderBeloev
    Member
    Posted 10 months ago #

    Ok, thanks.

    Here is the original pastebin:

    http://pastebin.com/FSX1fTFQ

    And here is the code I try to modify:

    http://pastebin.com/hv7VZ5An

    Thank you in advance!

    Regards,

    Alex :)

  6. esmi
    Forum Moderator
    Posted 10 months ago #

    You should be setting up the shortcode in your theme's functions.php file.

Reply

You must log in to post.

About this Topic