Шорткод не работает в основном содержимом WordPress

Я использую шорткод, и по этому шорткоду я хочу основной заголовок, миниатюру, некоторый контент и затем постоянную ссылку на мой пост.
Но с помощью этого короткого кода WordPress покажет полный контент без заголовка, эскиза и постоянной ссылки.
Что мне теперь делать.
Фото моего стиля
(Примечание: это старый формат Shortcode)
Помогите мне, пожалуйста.

Это код Into Functions.php

function category_post_shortcode($atts){
extract(shortcode_atts(array(
'title' => '',
'link' => '',
'category' => '',
), $atts, 'category_post'));

$q = new WP_Query(
array( 'category' => $category, 'post_per_page' => '3', 'post_type' => 'post')
);
$list = '<div class="your_class"><h2>'.$title.'</h2> <a href="'.$link.'">more</a>';

while($q->have_posts()) : $q->the_post();
$id = get_the_ID();

$post_excerpt = get_post_meta($id, 'post_excerpt', true);
$post_thumbnail=get_the_post_thumbnail( $post->ID,'post-thumbnail' );
$list .= '<div class="single-cat-post">
'.$post_thumbnail.'
<h3>'.get_the_title().'</h3>
<P>'.$post_excerpt.'</p>
<a href="'.get_permalink().'">read more</a>
</div>';
endwhile;
$list.= '</div>';
wp_reset_query();
}
add_shortcode('category_post', 'category_post_shortcode');

Это в мой Index.php

 <?php if(have_posts()) : ?><?php while(have_posts()) : the_post (); ?>
<?php the_content(); ?>
<?php endwhile; ?>

<?php else : ?>
<h3><?php _e('404 Error: Not Found'); ?></h3>
<?php endif; ?>

Это для поддержки миниатюр

add_theme_support( 'post-thumbnails' );
add_image_size( 'post-image', 145,100, true);

Мой шорткод

[category_post title="This is a testing post" category="New" link="#"]

0

Решение

Пожалуйста, проверьте этот код, я сделал немного изменений в коде.

function category_post_shortcode($atts){
extract(shortcode_atts(array(
'title' => 'true',
'link' => 'true',
'category' => '',
), $atts));
$q = new WP_Query(
array( 'category_name' => $category, 'posts_per_page' => '3','ignore_sticky_posts' => 1));
$list ='';
$list.= '<div class="your_class">';
while($q->have_posts()) : $q->the_post();
$list .= '<div class="single-cat-post">';

/*--------------Thumbnail ----------*/
$list .= '<div class="thumbnail-cat-post">';
$list.=  get_the_post_thumbnail() ;
$list .= '</div>';
/*--------------Thumbnail end ----------*/

/*------------Title start ------------*/
if ( $title == 'true' )
{
$list .= '<div class="title-cat-post">';
$list.= the_title('<h3 class="ss">','</h3>', false);
$list .= '</div>';
}
/*------------title End ------------*/

/*--------------excerpt start ----------*/
$list .= '<div class="excerpt-cat-post">';
$list.= '<p>'.get_the_excerpt ().'</p>';
$list .= '</div>';
/*-----------excerpt end-------------*/

/*--------------Permalink start----------*/
if ( $link == 'true' )
{
$list .= ' <a href="'.get_permalink().'">read more</a>';
}
/*----------------Permalink end --------*/

$list.= '</div>';/*----------Single-cat-post end--------------*/
endwhile;
$list.= '</div>'; /*-------------your_class end-----------*/
wp_reset_query();
return $list;
}
add_shortcode('category_post', 'category_post_shortcode');

Короткий номер : [category_post title="true" category="markup" link="true"]

1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector