WordPress Gallery Displays Code - wordpress

I inserted a gallery into a post of mine on WordPress but when I view the gallery on the website it comes up like this:
[gallery size="medium" ids="110,109,108"]
I've made the post go to a certain page of the website in the code:
<?php
$post_id = 5;
$queried_post = get_post($post_id);
echo $queried_post->post_content;
?>
could this affect it?Why does this happen? How can I fix this?
(I've also discovered for any shortcodes it does the same thing)
Thanks

For that you can use the Wordpress Loop as they are in default or another way is you have to use like add_filter('the_content', $queried_post->post_content);. Thanks!

Related

How to add extra Widgets in wordpress?

In my current WordPress theme, i have some 5 widgets.
I tried with plugins available on internet but that not solved my problem.
I want to use more widgets in my theme in single sidebar.
How can i add more widgets in WP theme?
Thanks
Most widgets give you a shortcode to put into one of the pages that wil be echoed out through the the_content(); function.
So if you would like to process those shortcodes in the PHP to make them in custom places would probably be your best bet.
You can do that like this:
<?php echo do_shortcode( $content ) ?>
Here is the reference

Basic Fishpig Wordpress Integration - Display Custom Post on Homepage

I'm trying to create a slider on the homepage of my Magento site. I am totally new to Magento and have someone else on our team coding most of that stuff after realizing how far into the deep end I jumped.
My issue: I'm trying to pull custom posts from WP (with the paid advanced custom fields extension) to display an image that will go into a slider.
I'm stuck at the most basic part - pulling in a list of Wordpress posts.
I created a new file: mytemplatedirectory/default/template/home/slider.phtml with
<?php $posts = $this->getPosts() ?>
<?php foreach ($posts as $_post) : ?>
<?php echo $post->getPostContent() ?>
<?php endforeach ?>
and I put this into the CMS page in the Magento admin:
{{block type="core/template" template="home/slider.phtml"}}
But not even the default post is showing up.
If anyone has any guidance that would be extremely helpful. The beginning steps are what are throwing me off but it would also be nice to have help pulling the custom post and the advanced custom field (although it seems that Fishpig's documentation makes this pretty simple).
Thanks in advance! Sorry for such an amateur question.
The block type you're using does not include the getPosts() method, which is the reason your call to this returns nothing. If you change the block type to 'wordpress/sidebar_widget_posts' then the call to getPosts will return a post collection object.
The following link explains a little bit more about how to include this block and what you can do with it:
Display WordPress Blog Posts on the Magento homepage
Figured this out with Ben's help (who I believe is the creator of the excellent Fishpig extension).
I created a custom post (with the Custom Post Type UI plugin for WP) and a custom field (with the Advanced Custom Fields plugin for WP).
On my Homepage in the CMS I added in the content area
{{block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" post_count="5" post_type="slider_home" template="wordpress/sidebar/widget/slider_home.phtml"}}
In that block, slider_home is my post type and slider_home.phtml is a new file I created that pulls the code from wordpress/sidebar/widget/posts.phtml but customizes it to my need.
Within the loop in slider_home.phtml I took out what was currently there and added:
<?php $image = $post->getMetaValue('image'); ?>
<?php $url = $post->getMetaValue('url'); ?>
<a href="<?php echo $url; ?>" target="_blank">
<img src="<?php echo $image; ?>" />
</a>
which is pulling in the custom fields I made in Wordpress. works perfectly and now my client will be able to update their Magento site through the Wordpress CMS.

Enable shortcodes in a wordpress theme

I develop a new theme for wordpress 3.3.1 from scratch and shortcodes are not working on it.
As I searched until now it is a matter of filtering the content containing the shortcode, filter code added in a theme specific location(shorcodes are working with another theme).
So, my question is : What is the code for a general shortcode theme enable ?
To execute a single shortcode, run it with
echo do_shortcode('[your_short_code]');
If the shortcode(s) are in the post content, make sure you're displaying it with
<?php the_content();?>
Or
<?php echo apply_filters('the_content',$post_content);?>
Or
<?php echo apply_filters('the_content',$wp_query->post->post_content);?>
The important thing is: if you aren't using the function "the_content()" you need this line <?php echo apply_filters('the_content',$wp_query->post->post_content);?> where in the second argument you have to put the variable of the post content you want to show.
I had to save the theme's content to a variable and then use the second example.. Worked like a charm.
$mycontent = ot_get_option('rightcontent');
echo apply_filters('the_content',$mycontent);

wordpress <!--more--> not rendering a link

I am using the <!--more--> tag in my wordpress copy to create an excerpt from the main content and also echo a link, however it is totally disregarding this tag and just posting the full article, below is hope I am implementing it in my templates,
<?php the_content("Read more about this article..."); ?> am I doing something wrong? Currently it is showing the while post when I use the above code, however it is my belief that it should only only show everything above the <!--more--> tag?
As per the official WordPress support site:
From the use of your PHP code, it looks like you want to use the more tag on pages. More works with blog posts but not pages. Please add the following code to your document above your PHP line you provided to make it work:
<?php
global $more;
$more = 0;
?>
Also, be sure that you are not simply in preview mode and that you have actually published the article and previewed it:
[T]he more tag is not displayed in post previews, since previews display
posts in entirety, but the more tag will appear once the post has been
published.
Perhaps you are using custom page template to display archives. "More" tag doesn't work in pages. If you want to turn it on in Pages...
<?php the_content("Read more about this article..."); ?>
you should use the code like this if you wanna show the to work in a page
<?php
global $more;
$more = 0;
the_content("Read more about this article...");
?>

adding single.php page to wordpress or if condition for main page or post detail page

I use Barecity Theme for WordPress. i built everything, but now i need to add a single.php file to theme. now it displays all post content at homepage, I created a short_desc Custom Field. and I call it from code with;
<?php //get_post_meta($post->ID, 'short_desc', true); ?>
it is fine. but i need to display this short desc at home page listing, and the main content at details page. how can do that?
I appreciate helps!!
It sounds like what you are trying to do is show a custom field that you have set on a post on the index page (which lists all the posts).
To do that you'll need to modify index.php by adding your snippet where you would like to have the short description.
<?php echo get_post_meta($post->ID, 'short_desc', true); ?>
You need to use echo to display the results from the get_post_meta function.
Depending on how your posts are setup you can also use the More button when you write your posts. This will cut off your post at a certain point that you decide and only show that short part on the index and archive pages.
Another option would be to use
<?php the_excerpt(); ?>
Which shows the first 55 words (this can be adjusted though) of the post.
Hope that helps,
Paul

Resources