• 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 ]

Viewing 15 replies - 1 through 15 (of 15 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with conditional tags.

    <?php if(is_page( '42' )) : ?>
    <p>some text</p>
    <?php endif; ?>

    Or custom fields.

    Thread Starter parfumio

    (@parfumio)

    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: https://www.parfumio.ro

    Thanks!

    Moderator keesiemeijer

    (@keesiemeijer)

    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; ?>

    Thread Starter parfumio

    (@parfumio)

    I’m not sure if it helps but my theme is a free theme and the basic version can be found here:
    https://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 ..

    Moderator keesiemeijer

    (@keesiemeijer)

    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

    Thread Starter parfumio

    (@parfumio)

    I think I got it and I have inserted the code there but nothing happens.
    For example, the page https://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(); ?>
    Moderator keesiemeijer

    (@keesiemeijer)

    Try putting it inside the loop on page.php

    Thread Starter parfumio

    (@parfumio)

    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 https://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.

    Thread Starter parfumio

    (@parfumio)

    And it would help a lot if I could also add an image beside the text…

    Moderator keesiemeijer

    (@keesiemeijer)

    Did you have to insert some code in your theme template files to show those plugin icons? What plugins are you using (link please).

    Thread Starter parfumio

    (@parfumio)

    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:
    https://www.ads-software.com/extend/plugins/only-tweet-like-share-and-google-1/?topic_id=23208

    Moderator keesiemeijer

    (@keesiemeijer)

    Put 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');
    Thread Starter parfumio

    (@parfumio)

    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?

    Moderator keesiemeijer

    (@keesiemeijer)

    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);

    Thread Starter parfumio

    (@parfumio)

    i tried and unfortunately it still shows either at the very beginning or at the very end, not inside the page content

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘How to add same text (or text plus image) in multiple pages/posts?’ is closed to new replies.