• I have a Page that’s a parent page of 2 other pages. I’d like to show a snippet, or the whole child pages content on the parent page.

    Does anyone know what the codex is for displaying a specific pages content on another page?

    I’m also looking to use this codex to display a page’s content without making specific templates, because I’ll be using an e-commerce software, but also be using WordPress as my CMS. So I’ll be entering the codex in the e-commerce page, but once there, I’ll be updating the content through WordPress. Using WordPress makes it easier to update content on the fly, then through my e-commerce software, since I have to be logged on to my server.

Viewing 15 replies - 1 through 15 (of 21 total)
  • You could use https://codex.www.ads-software.com/Class_Reference/WP_Query#Post_.26_Page_Parameters

    This would probably result in something like this in your page template:

    <?
    $the_query = new WP_Query( 'page_id=7' )
    while ( $the_query->have_posts() ) :
    	$the_query->the_post();
            the_title();
            the_content();
    endwhile;
    wp_reset_postdata();
    ?>

    This would show you title and contents of page with the ID 7.

    Thread Starter RedpointCS

    (@redpointcs)

    I’m guessing the page_id is not the universal #7, right? When I hover over the page which contents I want show it says post=17. So I put the page_id as 17, right?

    Then when I look at the page, the only thing show is:
    have_posts() ) : $the_query->the_post(); the_title(); the_content(); endwhile; wp_reset_postdata(); ?>

    So something about “->” my e-commerce site doesn’t like, I guess.

    Thanks for suggesting something though.

    you can wrap this into a shortcode as well. Paste this in your functions.php file and you can now use the shortcode
    ” [my_content id=”Enter your page id number” title=Set this to true if you want to show title /] “

    function get_post_page_content( $atts ) {
    			extract( shortcode_atts( array(
    				'id' => null,
    				'title' => false,
    			), $atts ) );
    
    			$the_query = new WP_Query( 'page_id='.$id );
    			while ( $the_query->have_posts() ) {
    				$the_query->the_post();
    			        if($title == true){
    			        the_title();
    			        }
    			        the_content();
    			}
    			wp_reset_postdata();
    
    		}
    		add_shortcode( 'my_content', 'get_post_page_content' );

    @redpointcs yes you would use 17 for your page with te ID 17.

    You need to add this code in the PHP template of your page. Not via the editor, this will not work.

    Thread Starter RedpointCS

    (@redpointcs)

    @gabrielcastillo, I don’t think I can do that, because I’m using WordPress within an e-commerce thing. That short code won’t work with another kind of software.

    @curlybracket When I place that code in the .php file in the ecommerce folder, I just get a white screen. I didn’t place the code in the page of WordPress I’m trying to show. I placed it in the page with the e-commerce page. I had to go through phpmyadmin to do it though, since that’s the only way I can edit that field.

    I have a feeling I’ll have to pay some developer who understands this crap, and it’ll probably take him/or her all of 10 minutes, and then try to charge a grand for it…

    If you are using wordpress the shortcode should work with any wordpress page, what eCommerce are you using?

    @redpointcs this code will only work from within WordPress.
    If you want to call contents from WP to your ecommerce software, you will indeed need to write a piece of code which would connect to the WP database and get the infos you need.
    Good luck ??

    Thread Starter RedpointCS

    (@redpointcs)

    Xsilva Lightspeed. It’s not a WordPress e-commerce Plugin.

    It’s the only e-commerce solution I can use, because it links directly to my POS system, and I don’t need to update inventory or anything else.

    There is a way to use it with Magento, and I think Magento has a WordPress Plugin, but I haven’t been able to figure out to link Magento with Lightspeed.

    Thread Starter RedpointCS

    (@redpointcs)

    @curly, any suggestions on what to read, or where to begin on how to figure out how to do that?

    Well that is a horse of a different color! The question originally asked was answered with previous posts. Now the issue is integrating custom wordpress functions with lightspeed.

    Thread Starter RedpointCS

    (@redpointcs)

    Sorry, I guess my question started out within WordPress, than I branched off into e-commerce.

    Does anyone know how I can do this, or point me in the direction of some good reading?

    Put content from WordPress, onto a different and I guess separate software?

    Light speed has a developers section, that might be a place to start. I would suggest hiring a developer for this if you feel this is out of your scope. You don’t want to end up breaking some code that will take down your whole site or your pos.

    you could do some research with excerpts.. maybe you could create a function that will allow you to make custom excerpts and post them in a parent page.

    The easiest (and probably also ugliest) way would be to integrate an iframe of your WordPress page into a page of your CMS.

    i know this post is a few months old but I am trying to use the posted PHP to include content onto my homepage through my home.php file.

    <? $the_query = new WP_Query( ‘page_id=149’ )
    while ( $the_query->have_posts() ) :
    $the_query->the_post();
    the_title();
    the_content();
    endwhile;
    wp_reset_postdata();
    ?>

    but I am getting a syntax error (in dreamweaver) on the 2nd line:
    while ( $the_query->have_posts() ) :

    anyone know why this might happen?

    i know this reply is a few weeks old

    Replace first line with below

    <? $the_query = new WP_Query( ‘page_id=149’ );

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘Showing one page's content on another page’ is closed to new replies.