Putting a shortcode into a PHP file
-
I am using Progress Maps plugin on my site and I want to add it to all blog listing pages so they display a map of the post locations by category automatically. The author says this is possible but the code he provides to do it doesn’t work, so I wonder if anyone knows why it doesn’t work?
The shortcode when I use it in a widget looks like:
‘[codespacing_progress_map map_id=”blogposts” post_type=”post” tax_query=”category{296|IN}”]’
This maps all the posts in category_ID=296.
To put it into archive.php so it gets the category_ID dynamically for each category, the author suggests adding the following code to /library/includes/blog_listing.php in my child theme:
‘<div id=”top_map”>
<?php
$categories = get_the_category();
$category_id = $categories[0]->cat_ID;
echo do_shortcode(‘[codespacing_progress_map post_type=”post” tax_query=”category{‘.$category_id.’|IN}”]’);
?>
</div>’But all this does is display every post in every category, so I’m assuming it’s not getting the current category_ID into the shortcode (because that’s what Progress Maps displays with no category filter in the shortcode).
I’m not a PHP coder so I don’t know where it’s going wrong. Can anyone help me to debug it?
The topic ‘Putting a shortcode into a PHP file’ is closed to new replies.