利用短代码功能往elementor插入自定义调用文章功能
Posted on March 14, 2022 | Posted in 编程开发
function wpc_elementor_shortcode( $atts ) {
$args = shortcode_atts(array("cat" => 5, "posts_per_page" => 4), $atts);
echo ("<ul class=\"newul\">");
query_posts($args);
if(have_posts()) : while (have_posts()) : the_post();
echo "<li class=\"newli\">";
if ( has_post_thumbnail() ) {
echo ("<img class=\"newimg\" src=\"");
the_post_thumbnail_url("codilight_lite_block_2_medium");
echo ("\">");
}
the_title( sprintf( '<h2 class="entry-title newtitle"><a href="%s">', esc_url( get_permalink() ) ), '</a></h2>' );
if (has_excerpt()) {
echo ("<div class=\"excdiv\">".get_the_excerpt()."</div>");
}
echo "</li>";
endwhile;
endif;
wp_reset_query();
echo ("</ul>");
}
add_shortcode( 'my_elementor_php_output', 'wpc_elementor_shortcode');