You don’t copy the entire PHP line into content, you just need the shortcode itself. As in [ic_add_posts category='Ridgeway Research News' showposts='3']
But if this shortcode is being called from your template by do_shortcode(), why would you also want it in your page content? It’s going to show up right below the content anyway.
Hi,
The shotcode isnt in the page content, the only place I have it is in the php template page I created to use with the ‘News’ page.
So I did what you said and left the shortcode as you have it above, no php around it, and it still didnt work.
I still when I go to the ‘News’ page, only see the shortcode and not the posts.
http://www.accend4web.co.uk/ridgeway/news/
So now the template called template-ridgeway-news.php which has been associated with the ‘News’ page, looks like this –
<?php /* Template Name: Ridgeway-News-Page */ ?>
<?php get_header(); ?>
<?php get_template_part('element', 'page-header'); ?>
<div id="main" class="main">
<div class="container">
<section id="content" class="content">
<?php do_action('cpotheme_before_content'); ?>
<?php if(have_posts()) while(have_posts()): the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="page-content">
<?php do_action('cpotheme_after_title'); ?>
<?php the_content(); ?>
[ic_add_posts category='Ridgeway Research News' showposts='3']
</div>
</div>
<?php endwhile; ?>
<?php if(get_query_var('paged')) $current_page = get_query_var('paged'); else $current_page = 1;?>
<?php $query = new WP_Query('post_type=cpo_service&paged='.$current_page.'&posts_per_page=-1&order=ASC&orderby=menu_order'); ?>
<?php if($query->posts): $feature_count = 0; ?>
<section id="services" class="services">
<?php cpotheme_grid($query->posts, '', '', 3); ?>
</section>
<?php cpotheme_numbered_pagination($query); ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php do_action('cpotheme_after_content'); ?>
</section>
<!--<?php get_sidebar(); ?>-->
<div class="clear"></div>
</div>
</div>
<?php get_footer(); ?>
I’m sorry, I misunderstood what you said were saying you were doing. You do need the do_shortcode() call to use shortcodes in template code. If the shortcode itself still displays after restoring the correct code, then it was not properly registered with add_shortcode() in the context of your page. Where ever it’s registered is apparently conditionally executed. Some condition that does not include your page.
Thats fine, no worries, i’m just starting out with wordpress so everyday is a new day for me with wordpress.
Umm I have restored the line to –
<?php echo do_shortcode(“[ic_add_posts category=’Ridgeway Research News’ showposts=’3′]”); ?>
And like you say there still is a problem, but I havent a clue what your sentence below means.
“Where ever itβs registered is apparently conditionally executed. Some condition that does not include your page.”
Does it mean this isnt going to work, or is there something I need to do to get it to work.
Thanks for getting back to me
I think I have found what your describing, but how do you know what the condition is set against, as in is the page name, the category, I’m not sure at all. Found the info here –
https://en-gb.wordpress.org/plugins/conditional-tags-shortcode/
Sorry to post again, but tried below I got an error and so it didnt work, but am I on the right path.
<?php [if is_page=’news’] echo do_shortcode(“[ic_add_posts category=’Ridgeway Research News’ showposts=’3′]”); [/if] ?>
You can make as many posts as you feel necessary! π
Let’s be sure I’m correctly understanding now. You’ve restored the do shortcode as per the code 3 posts back. The news page you linked even earlier is currently based on a template that uses the restored code, correct?
Then the shortcode is not registered for some reason. You don’t need the conditional plugin for template code, it’s meant for placing conditionals within page content. On templates we just use PHP. You also don’t need a PHP conditional, I was attempting to guess why the shortcode is not registered, not suggesting you change your code.
Does the shortcode, entered in page content without any PHP — just the part between brackets (including the brackets), work on other pages? What about if you entered it in this news page’s content?
Yes that’s correct, I restored it back to post 3 and as per your advice I took away the conditional plugin too, so the line of code that doesnt seem to be working inside a my template that is only being used for the ‘News’ page is –
<?php echo do_shortcode(“[ic_add_posts category=’Ridgeway Research News’ showposts=’3′]”); ?>
I have pasted [ic_add_posts category=’Ridgeway Research News’ showposts=’3′] directly into the editor part of the news page and again you get the same result, only this time there 2 appearing on the news page as below –
http://www.accend4web.co.uk/ridgeway/news/
Its strange isnt it. I’m happy to give you admin details if that makes it any easier
Yeah, that’s what I was afraid of, the shortcode is not working at all, it’s not anything you’ve done wrong, it’s not setup to work on pages.
Thank you for the offer of admin access, but that level of assistance is forbidden by the terms of these forums. While admin access would make things easier, it introduces risks and liabilities that are inappropriate for this type of assistance. While cumbersome, it serves to protect us all, even when some of us don’t feel the need.
The next step is to find the code that declares the shortcode tag and handler function. The function that does this is add_shortcode(). The first parameter will be “ic_add_posts” (sometimes it’s a dynamic tag like “ic_add_{$post_type}s”). The second parameter will be the function that produces the shortcode output. I suspect this code is only executed under certain conditions, like only if the queried object’s post_type is “post”. This is the conditional I referred to earlier.
If you can locate this code so we can figure out how it works, we can then figure out a workaround. Maybe we add our own add_shortcode() call. To do so, we need to know the handler function name. Finding this code can be a challenge. Of course it’s probably with whatever “ic” is. The Linux command “grep” (text search) is useful for this sort of thing. If you don’t have Linux terminal access it’s not much help, but alternative commands are available for other O/S.
I found a file called shortcodes.php inside wp-includes folder, and there a lot in there. I can see the add_shortcode() function but not the ic_add_posts bit. I was hoping that I could attach a document but cant see the option, so have pasted it all below, its a lot so maybe its easier for you if you copy it out of there and paste it in notepad for easy reading.
[excessive code redacted]
-
This reply was modified 9 years, 3 months ago by
bcworkz.
Ummm, OK. I appreciate the effort, but there’s never any reason to paste in an entire file from the core code. Anyone can access it from Trac, plus most devs have local copies of WP they can reference. You can reference any code in Trac by line number like so:
https://core.trac.wordpress.org/browser/trunk/src/wp-includes/shortcodes.php#L89
(each line number on the page is a link you can copy)
In the event you have a lot of non-WP core code to post, please use a resource meant for that, such as pastebin.com or github.com. I like pastebin because it has a syntax highlighting option you can select when saving your paste. Otherwise, as you suggest, I download it and view it with a programmer’s editor because it has its own syntax highlighting.
Finally, I’m afraid I wasn’t clear enough in what I was looking for. Not the add_shortcode() declaration itself. (FYI, source is also available for all functions in the code reference.) I’m interested in the function call where the [ic_add_posts] shortcode is added, and more specifically, any conditional code before it’s added that explains why it doesn’t work on pages.
Oh god sorry, as you can tell Im new to wordpress…
Ok I think I know what you mean, just to say the code in post 3 is all the code within the template, so what your looking for is the code thats surrounding those pages are you?
One thing I did do, is take away all that code to just leave the shortcode, to see if any of the code surrounding it was the cause, and it wasnt, all i got was nothing as in no page design, but the same problem with the shortcode, where it just appeared as a string.
Don’t worry about posting all that code as long as it doesn’t keep happening. Live and learn, eh? π
What I’m after isn’t related to your template code at all. The function call adding the ic_add_posts shortcode would be with the code that comes with whatever plugin or theme is responsible for providing the shortcode. If it’s a theme, it might be a different template, functions.php, or other related PHP code. If it’s a plugin, it should be in the plugin’s PHP code somewhere.
I have managed to get into file manager on the server, and am doing a search for ic_add_ in the theme folder and as far outside as I can go and then only instance I’m finding so far is actually inside my template