0

I want to have a content area above my posts where I can use the visual composer to edit the content. However, when I go to manage>pages and then to the page which has my blog posts, and try to add text, nothing shows up. I found an answer to this exact question and found this code:

  <?php
  $page_id = 2; // substitute page_id of page you want content included from for "2"
  $page = get_post($page_id);
  echo "<p>$page->post_content</p>";
  ?>

I put it in my index.php and the content I want to add above my posts show up.. but it also puts out a lot of visual composer code, like it doesnt connect with visual composer or the design.. It just puts the image on the far left

http://snag.gy/ZDJ9S.jpg

Any ideas?

0

I have a few thought on this. You can very easily build yourself a dynamic area above your posts for the purpose of information or announcements

I prefer to make use of a non-hierarchical custom post type for this purpose. Just something very simple. No taxonomies attached. The custom post type should also not have single post view or an archive. The simple reasons for this is

  • Custom post types are not included in the main query and they don't appear in navigation menus by default. This makes CPT's excellent for usage as informational post sections outside your normal site setup

  • If you have a new announcement or something new you want to share, you can simply create a new post under your custom post type. No need to edit the same post time after time. The advantage of using a custom post type and having a post for every announement, event, info etc. is that you can keep a record and even later have a dedicated page with some of these posts

You can run a custom query with WP_Query in the area you would like the post to appear, or even incorporate tnis into a custom widget, which brings me to your problem and the actual purpose of the question

I prefer WP-Query over the get_ functions as WP_Query sets up the postdata automatically which enables the use of the template tags like the_content(). In your question, you make use of get_post(), which does not set up postdata, so the template tags won't work. The WP_Post objects returned is unfiltered as well, so you will not see any formatting applied to them

$page->post_content returns unfiltered content. You need to aplly these filteres manually like

$content = apply_filters( 'the_content', $page->post_content );
echo $content;

This will give you filtered content which is exactly the same as the template tag the_content().

  • Thank you for the quick answer. I understand the basics, Im a designer and not so pro with php. How and where and what should a put in to my code to get my image banner visible above my posts? This is how I want the image to appear on my Blog page. snag.gy/CWH1g.jpg – user2323822 Jan 28 '15 at 11:31
  • I'm not quite sure as frankly I have no idea how your structures look like, neither which theme you are using. From your pic, there are some shortcodes involved that is not part of core. What is strange is that the shortcode outputs the shortcode, and not the content.. – Pieter Goosen Jan 28 '15 at 11:45
  • Just a tip, any CSS and styling issues should be asked on stackoverflow.com. These topics are off topic here – Pieter Goosen Jan 28 '15 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.