A
A
Anton Essential2016-01-12 01:56:18
WordPress
Anton Essential, 2016-01-12 01:56:18

do_shortcode not working in WP?

Kind, please tell me how to display a certain phrase in the preview of posts in WordPress.
I'm trying to display a preview of posts from a certain category, with native functions I output the title, picture, and the_excerpt() function; you can display a short preview, but it doesn’t suit me, I don’t want to display a preview of the post, but I want to display certain phrases from the post, and it’s not entirely clear how to do this, maybe tell me a solution, maybe the shortcode is not suitable in this case.

<?php
  $query = new WP_Query('&cat=6&showposts=10' . '&paged='.$paged);
    if( $query->have_posts() ){
    while( $query->have_posts() ){ $query->the_post();
  ?>
  <div class="news-item rel-info">
    <a href="<?php the_permalink();?>">
      <?php the_post_thumbnail();?>
    </a>
  </div>
  <div class="col-md-8">
    <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
    <span class="num">
      <?php echo do_shortcode('[articul]'); ?> // Не работает !
    </span>
    <span class="type"> В это место необходим тоже вывод определенного описания</span>
    <a href="<?php the_permalink();?>" class="next"> more... </a>
  </div>
<?php
}
wp_reset_postdata();
}
?>

Это то, что лежит в functions.php
<?php
function articul_function($atts){
  extract(shortcode_atts(array(
    'name' => ''
  ), $atts) );
  return $name;
}
add_shortcode('articul','articul_function');
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WP Panda, 2016-01-12
@wppanda5

1. According to the API, the shortcode is not compiled correctly, this time.
2. And what should he return?
It works, but it has nothing to display.
3. the_excerpt() - perfect for you, read the function description carefully.
If this field is filled,
then it will display its contents

M
Maxim Kudryavtsev, 2016-01-12
@kumaxim

I still don't fully understand the essence of your problem, but if you need to filter something from the standard output of WP, then I always use the add_filter() function . See the list of all possible filters here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question