How to add same text (or text plus image) in multiple pages/posts?
-
Hi
I would like to add the same thing (a text or preferably a text and an image) to multiple pages/posts on my blog? Is there a way to do this either via code or with the help of a plugin?
So I want to be able to select the pages (specify their IDs) and add something on all of them.Thanks a lot.
[ Larry ]
-
Try it with conditional tags.
<?php if(is_page( '42' )) : ?> <p>some text</p> <?php endif; ?>
Or custom fields.
Thanks a lot, keesiemeijer
Unfortunately I’m not very familiar with coding/php.
I mean I have tweaked my site quite a lot even in terms of coding (css and even a little php) but I can only do this if I have all the details: where to insert the code, step by step, etc.So please explain this as for a novice.
My site: http://www.parfumio.ro
Thanks!
Can you provide a link to your theme? Is it always the same text and image you want to show?
Try it with this inside the loop.
<?php $post_and_pages = array(873,461,8,32,54); // ID's of Posts and Pages if(in_array($post->ID, $post_and_pages)) : ?> <p>some text here</p> <?php endif; ?>
I’m not sure if it helps but my theme is a free theme and the basic version can be found here:
http://www.leadcamp.com/content/2009/09/14/cherry-blossom-brances-free-wordpress-template-themes/I have customized it a lot since I started using it (mainly in terms of css) but that is the source.
I’m not sure what it means to add that code in the loop. I have read some things about the loop but I’m not sure I understood ..
In your theme the loop starts here (index.php):
<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?>
and the loop ends here:
<?php endwhile; ?>
Put it in between there. Change the ID’s in the $post_and_pages array to the ID’s where you want to show the text:
example of index.php
I think I got it and I have inserted the code there but nothing happens.
For example, the page http://www.parfumio.ro/chanel/ has the ID=1112 and I think I should see there “some text here”, right? I don’t see it.This is exactly how I inserted the code in index.php:
<?php if ( function_exists( 'get_smooth_slider' ) ) { get_smooth_slider(); } if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="Post"> <div class="Post-tl"></div> <div class="Post-tr"><div></div></div> <div class="Post-bl"><div></div></div> <div class="Post-br"><div></div></div> <div class="Post-tc"><div></div></div> <div class="Post-bc"><div></div></div> <div class="Post-cl"><div></div></div> <div class="Post-cr"><div></div></div> <div class="Post-cc"></div> <div class="Post-body"> <div class="Post-inner article"> <h2 class="PostHeaderIcon-wrapper"> <span class="PostHeader"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>"> <?php the_title(); ?> </a></span> </h2> <?php $post_and_pages = array(1059,1067,1071,1073,1076,1081,1087,1107,1112,1115,1121,1123,1118,1129,1142,1145,1151,1188,1191,2581,2658,2706,2716,2717,2718,2719,2738,2739,2741,2742,2743,2780,2785,2787,2795,2811,2781,2782,2783,2812,2813,2859,2967,2981,2988,2990,2993,2996,2998,3002,3007,3009,3011,3015,3018,3697,3703,3747,3875,4011,4070,4090,4321,4385,4617,4697,4816,4912); // ID's of Posts and Pages if(in_array($post->ID, $post_and_pages)) : ?> <p>some text here</p> <?php endif; ?> <?php $icons = array(); ?> <?php if (!is_page()) : ?> <?php ob_start(); ?>
Try putting it inside the loop on page.php
I think I’m close…
I put it in different spots on page.php but it shows either at the very beginning, before the plugin with the buttons “Like” and “+1” or at the very end.
(please see http://www.parfumio.ro/chanel for instance)I want the text to show inside the page at the beginning but AFTER that “Like” and “+1” plugin.
And it would help a lot if I could also add an image beside the text…
Did you have to insert some code in your theme template files to show those plugin icons? What plugins are you using (link please).
No, for those plugin icons I didn’t have to insert code, I only installed the plugin.
The plugin is called “Tweet, Like, Google +1 and Share” and it is located here:
http://wordpress.org/extend/plugins/only-tweet-like-share-and-google-1/?topic_id=23208Put this in your theme’s functions.php and see if “some text here” gets added to the top of the page content:
function sometext($content){ global $post; $post_and_pages = array(1059,1067,1071,1073,1076,1081,1087,1107,1112,1115,1121,1123,1118,1129,1142,1145,1151,1188,1191,2581,2658,2706,2716,2717,2718,2719,2738,2739,2741,2742,2743,2780,2785,2787,2795,2811,2781,2782,2783,2812,2813,2859,2967,2981,2988,2990,2993,2996,2998,3002,3007,3009,3011,3015,3018,3697,3703,3747,3875,4011,4070,4090,4321,4385,4617,4697,4816,4912); // ID's of Posts and Pages if(in_array($post->ID, $post_and_pages)) { return '<p>some text here</p>'.$content; } } add_filter('the_content', 'sometext');
I did and no matter where I put it, “some text here” gets added at the end of the page.
Do you have any idea if custom fields can be used for this task?
Try it with this in functions.php:
function sometext($content){ global $post; $post_and_pages = array(1059,1067,1071,1073,1076,1081,1087,1107,1112,1115,1121,1123,1118,1129,1142,1145,1151,1188,1191,2581,2658,2706,2716,2717,2718,2719,2738,2739,2741,2742,2743,2780,2785,2787,2795,2811,2781,2782,2783,2812,2813,2859,2967,2981,2988,2990,2993,2996,2998,3002,3007,3009,3011,3015,3018,3697,3703,3747,3875,4011,4070,4090,4321,4385,4617,4697,4816,4912); // ID's of Posts and Pages if(in_array($post->ID, $post_and_pages)) { return '<p>some text here</p>'.$content; } } add_filter('the_content', 'sometext',1);
i tried and unfortunately it still shows either at the very beginning or at the very end, not inside the page content
- The topic ‘How to add same text (or text plus image) in multiple pages/posts?’ is closed to new replies.