Recent posts carousel shortcode (6 posts)

  1. AlexanderBeloev
    Posted 1 year 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">
    			$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>';
    	<div class="clearfix"></div>
    	<a id="prev2" class="prev" href="#"><</a>
    	<a id="next2" class="next" href="#">></a>

    Thank you all in advance!


    Alex :)

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Have you reviewed the Shortcode_API?

  3. AlexanderBeloev
    Posted 1 year 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 1 year 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
    Posted 1 year ago #

    Ok, thanks.

    Here is the original pastebin:


    And here is the code I try to modify:


    Thank you in advance!


    Alex :)

  6. esmi
    Forum Moderator
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic