• Resolved foochuck

    (@foochuck)


    I’m working on a WordPress site that is going to cover two sub-sites included under one main site.

    Some of the pages on the two sub-sites will have duplicate page content where I’d like to pull from the same content for both pages. This will also allow me to edit the duplicate content in one place so that it updates on every page that uses that content.

    Here’s an example:

    Site 1 About Us Page: https://www.mysite.com/site-1/about-us

    Site 2 About Us Page: https://www.mysite.com/site-2/about-us

    So although these are two different pages, I’d like to pull the same content to go on each of these pages. Is there a trick to do this or a plugin that someone knows of that could help me accomplish this?

    If I were doing this outside of WordPress, I’d simply do a PHP include and pull from the same file on each page – however I’m not sure how to accomplish that with WordPress.

    Thanks

    -foo

Viewing 11 replies - 1 through 11 (of 11 total)
  • One possibility – create a Custom Post type for shared posts and use a special query to include the same custom post on every page where it is needed.

    Thread Starter foochuck

    (@foochuck)

    @vtxyzzy – How can I create a custom post type?

    I’m also not sure what query I can use to include a custom post. Do you know of any examples I could use for this?

    The Custom Post Type UI plugin makes it easy to create custom post types.

    As for the query, it is just like any other query except that you would use the ‘post_type’ argument as shown in the Codex here under Page Parameters.

    Thread Starter foochuck

    (@foochuck)

    For the query, do I need to make a page template or can I run that query in the content area of my pages using PHP?

    Not quite sure what you are asking, but I think you could do it either way. Try to think of it as a standard query, just using one different argument (post_type). Where ever you would put a regular query, you can put the custom one.

    Thread Starter foochuck

    (@foochuck)

    Option 1. Can I put a regular query right into the content of a page?

    Option 2. Would I need to create a page template and insert the query in the template since it’s using PHP?

    From my experience, I don’t think you can use PHP in the content of a page or post, so I’m guessing I have to go with option #2, since I want the same content to appear on multiple pages. I would apply the page template to those pages.

    Thread Starter foochuck

    (@foochuck)

    Okay here’s what I’ve tried.

    I created a custom post type called “builders”.

    Under builders, I created a post called “associate builders”.

    Now for the page template I created, I’m trying to query it like so:

    <?php query_posts( array( 'post_type' => array('builders', 'associate builders') ) ); ?>
    
    				<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    					<div class="entry-content">
    						<?php the_content(); ?>
    						<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    						<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
    					</div><!-- .entry-content -->
    				</div><!-- #post-## -->

    This query pulls no data. So first off, I think I’m not doing the query correctly. Any suggestions on this?

    Under builders, I created a post called “associate builders”.

    The query is not quite right. ‘associate builders’, based on your comment above, is a post, not a post_type. Therefore, you do not include it in the array of post_types.

    <?php query_posts( array( 'post_type' => array('builders') ) ); ?>

    Option 1. Can I put a regular query right into the content of a page?

    Option 2. Would I need to create a page template and insert the query in the template since it’s using PHP?

    Option 1 is possible using a plugin like Exec PHP, but I would recommend Option 2.

    Thread Starter foochuck

    (@foochuck)

    Okay, I’ve updated my code on my page template:

    <?php query_posts( array( 'post_type' => array('builders') ) ); ?>
    
    				<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    					<div class="entry-content">
    						<?php the_content(); ?>
    						<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    						<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
    					</div><!-- .entry-content -->
    				</div><!-- #post-## -->

    The page using this template is showing no content, although I do have a post setup at:

    https://www.mysite.com/builders/associate-builders

    And that post displays content. Something else I could be doing wrong? Perhaps I need a loop on this page?

    You definitely need a loop after all query_post() calls. You probably also want to retrieve only 1 post, so add the posts_per_page argument to the query:

    <?php query_posts( array( 'post_type' => array('builders'), 'posts_per_page' => 1 ) );
    if (have_posts()) {
       while (have_posts()) {
          the_post();?>
          <!-- rest of your code from above here -->
       <?php } // endwhile
    } // endif ?>
    Thread Starter foochuck

    (@foochuck)

    Ahhhhhh. Works like a charm. Thanks so very much vtxyzzy!

    -foo

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Including the Same Content on Multiple Pages’ is closed to new replies.