WordPress.org

Ready to get started?Download WordPress

Forums

Showing one page's content on another page (22 posts)

  1. RedpointCS
    Member
    Posted 1 year ago #

    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.

  2. curlybracket
    Member
    Posted 1 year ago #

    You could use https://codex.wordpress.org/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.

  3. RedpointCS
    Member
    Posted 1 year ago #

    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.

  4. gabrielcastillo
    Member
    Posted 1 year ago #

    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' );
  5. curlybracket
    Member
    Posted 1 year ago #

    @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.

  6. RedpointCS
    Member
    Posted 1 year ago #

    @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...

  7. gabrielcastillo
    Member
    Posted 1 year ago #

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

  8. curlybracket
    Member
    Posted 1 year ago #

    @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 :)

  9. RedpointCS
    Member
    Posted 1 year ago #

    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.

  10. RedpointCS
    Member
    Posted 1 year ago #

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

  11. gabrielcastillo
    Member
    Posted 1 year ago #

    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.

  12. RedpointCS
    Member
    Posted 1 year ago #

    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?

  13. gabrielcastillo
    Member
    Posted 1 year ago #

    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.

  14. curlybracket
    Member
    Posted 1 year ago #

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

  15. theregoesjb
    Member
    Posted 1 year ago #

    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?

  16. Prasanth Panicker
    Member
    Posted 11 months ago #

    i know this reply is a few weeks old

    Replace first line with below

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

  17. russcoon
    Member
    Posted 10 months ago #

    Inserting the shortcut in the main content pane of the page loaded the other page's content. But it outputted that 2nd page's content before the content of the page itself. Even though I placed the shortcode after all of the content. Is there a way to render the page content before the shortcode? That is to have the content targeted by the shortcode appear where the shortcut is places (rather than first).

  18. c0mp
    Member
    Posted 8 months ago #

    Hello everybody.
    @gabrielcastillo, thanks for your snippet. It works but not perfectly. I have the same problems as russcoon.

    I use the shortcode within another shortcode (tables, accordion,...) and within normal html code.

    Although I putted your shortcode hierarchically underneath these elements, it appears above.
    Do you have an idea to fix this? Thanks.

  19. strakez
    Member
    Posted 8 months ago #

    @c0mp, you need to return the values as a statement at the end of the function. Right now the values are outputted as the function runs. I believe something like this should do the trick:

    <? $the_query = new WP_Query( 'page_id=149' );
    $output = "";
    while ( $the_query->have_posts() ) :
    $the_query->the_post();
    $output .= get_the_title();
    $output .= get_the_content();
    endwhile;
    wp_reset_postdata();
    return $output;
    ?>

    Now the values are caught by the "output" variable and gets outputted where you place the shortcode.

  20. strakez
    Member
    Posted 8 months ago #

    FYI, the code in my previous post is intended within the scope of @gabrielcastillo's shortcode function

  21. iShervin
    Member
    Posted 7 months ago #

    @ gabrielcastillo

    you are a genius :D thanks :D worked perfectly after searching for 3 days this done the job for me

    Thank a million

  22. massiace
    Member
    Posted 6 months ago #

    Thanks guys that has been really helpful. what would be the php code to put in footer page by example, I've tried that different variations of codes but it doesn't work... the [my_content id="33" title=false/] didn't work either though it works well when I paste it on a page.

    I've tried that without success:

    <div id="footer">
    <?php get_post_page_content (my_content id="33", title=false) ?>
    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic