Wordpress Customize the_content - wordpress

I am quite new to Wordpress and try to customize my Wordpress theme. My posts are always different. But basically there is a title, a text and a NivoSlider/Image/Vimeo Video.
If I use the basic the_content function it displays the post like that:
<h2>Title of the Post</h2>
<p><div class="slider-wrapper">Slider</div>Text</p>
It always includes the Slider/Image/Video in the Tag. How can I split the_content object?
I would like to have my posts display like that e.g. for the NivoSlider:
<div class="slider-wrapper">Slider</div>
<h2>Title of the Post</h2>
<p><Text</p>
It would be really great if somebody could tell me the easiest way to do for all the different kinds of posts.
I hope you understand my explanation, if you need more details, just tell me.
Thanks in advanced.
Best,
Brigi

Personally, I would take the shortcode out from your Content Body altogether, and place it in a Custom Field (named something like "postSlider"). Then you can structure your template like so:
<?php
do_shortcode(get_post_meta(get_the_ID(), 'postSlider'));
?>
<h2><?php the_title(); ?></h2>
<p><?php the_content(); ?></p>

You needs to create a custom page template for your posts. In that page template you can define your slider. Then just put your text in the content section.
Before doing serious coding refer this: Stepping Into Templates

Thanks again for your answer. Finally I used the Types plugin for Wordpress. You can easily customize your own field and use it in your index.php file with the following code:
Custom Field Image:
<?php echo(types_render_field("field-slug-image", array("alt"=>"Product image", "width"=>"600","height"=>"300","proportional"=>"true"))); ?>
Shortcode Custom Field for the Slider:
<?php echo apply_filters('the_content', get_post_meta($post->ID, 'field-slug-slider', true)); ?>
Shortcode Custom Field for the Vimeo video:
<?php echo apply_filters('the_content', get_post_meta($post->ID, 'field-slug-video', true)); ?>
Title and Content:
<h2><?php the_title(); ?></h2>
<?php the_content('Read the full post',true);?>

Related

Angular + WordPress

I have a ticket sales form written in Angular. How can I insert this form on the main page of Wordpress site? May be with usingthe tag iframe or can there be better solutions for this task? Thank you for attention!
I think a best solution to this is to create a new page template (you can google it to get more accurate info), see what is page templates here.
Basically, you will create a new file on your theme root, with the prefix page-, e.g: page-tickets.php. And then the very first thing that must appear on your page is a comment,like this: // Template Name: Tickets Page. Your page will be something like this:
<?php
// Template Name: Tickets Page
get_header();
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
// Angular + Html codes here!
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<script>angular and js imports</script>
<?php get_footer(); ?>
With that, when you will create a new page in Pages -> New (or edit), in the right bottom side will be available an option to you to choose a page template, like this:
That's all, I hope it helps you.

How to display list categories in wordpress integration magento

Can help somebody. I spent several hours to find solution but without results
I tried to display the list of categories on homepage wordpress blog thru following code
<?php $category = Mage::registry('wordpress_category') ?>
<?php if ($category): ?>
<?php echo $category->getId() ?>: <?php echo $category->getName() ?>
<?php endif; ?>
But the method
Mage::registry('wordpress_category')
always return null.
I found that, i should probably be using the Fishpig_Wordpress_Block_Category_View. But i dont know where i should put it.
The following code will retrieve the current category when viewing a category page in your blog:
<?php Mage::registry('wordpress_category') ?>
This is not what you need. To view a list of categories, you could create a custom collection using the following:
<?php $categories = Mage::getResourceModel('wordpress/post_category_collection') ?>
A better way would be to use the category widget block:
<block type="wordpress/sidebar_widget_categories" name="wp.categories" template="wordpress/sidebar/widget/categories.phtml" />
You can create this in PHP using the following code:
<?php echo Mage::getSingleton('core/layout')
->createBlock('wordpress/sidebar_widget_categories')
->setTemplate('wordpress/sidebar/widget/categories.phtml')
->toHtml() ?>
The above code uses the default template, however, feel free to use your own custom template.

How to retrieve all custom posts from all the categories in portfolio

I have created custom post type portfolio in wordpress. I have created categories like web-design, logo design, e-commerce, photography... etc. I have retrieved all these category as the navigation menu in portfolio template file (assigned to the portfolio page). Now I want there should be a link(view all) in the navigation menu which will retrieve all the posts from all the categories in portfolio. Basically I want a way for making default category which will retrieve all the posts. Can anybody please help me!!!
So, basically, you want to create a Custom Post Type Archive page.
A way to achieve this, as explained at WPBeginner.com, is like the following:
Create a custom page template (the PHP file could have any name you want) and Add the Template Name comment at the beginning of the file:
<?php /* Template Name: Custom Post Type Archive */ ?>
Create a custom loop:
<?php
/* Template Name: Custom Post Type Archive */
get_header();
?>
<?php
global $query_string;
query_posts($query_string . "post_type={YOUR-CUSTOM-POST-TYPE}&post_status=publish&posts_per_page=10");
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<?php
endwhile;
endif;
?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('Previous entries') ?></div>
<div class="alignright"><?php previous_posts_link('Next entries') ?></div>
</div>
<?php wp_reset_query(); ?>
<?php get_sidebar(); ?>
<?php get_footer();?>
Create a new page and select the template you just created in the Page Attributes box
You should be able to use the archive page template to list them all then. Try going to http://yourdomain.com/portfolio and see if that brings it up. You will need to have enabled archives for the post type when you created it though. Look for 'has_archive' => true, if you created the post type manually by dropping in the code in your functions.php file. If you see that, but its set to "false", you'll need to change it to true.
You could also create a custom archive template for this post type if you wanted to. If you create a new file in your theme directory called archive-portfolio.php and then put a custom loop in there the post type will automatically target that template file when accessing the post type archive.
Then to link from your nav menu to this archive, just create a custom menu item in your menu editor with the url http://yourdomain.com/portfolio. You won't need to create any sort of "default" category if you take advantage of the post type archives.
Let me know if you have any other questions.

Get excerpt and permalink outside loop in wordpress

I'm trying to get the post excerpt and permalink outside a wordpress loop, pulling the thumbnail and the title work fine but when trying to get the excerpt it doesn't work? And how would I get the permalink? My code so far is below.
Thanks!
<div id="featured">
<?php
$ftid = 104;
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ftid) );
?>
<img src="<?php echo $url; ?>" style="float:left;" />
<div class="featured-info">
<h2 class="post-title"><?php echo get_the_title($ftid); ?></h2>
<?php $my_post = get_post($ftid); echo $my_post->post_excerpt; ?>
</div>
</div>
And maybe if there is a better way of doing this you can point me in the right direction? :)
The permalink should work as is:
$permalink = get_permalink($ftid);
The excerpt though, when accessing the page object directly there actually has to be excerpt content (not just post content). If you didn't manually type in an excerpt on the post then nothing will appear. Inside the loop, the_excerpt() will automatically generate from the content if an excerpt hasn't been manually typed. Did you type a separate excerpt in the WP admin?
Look at wp_get_attachment_url() - you left the $ off the name of the $ftid variable.

Views title is blank

I'm using the Drupal views module to create an overview of nodes. In the view i created i configured the Title. But now when the page is rendered the title isn't shown. It is shown in the breadcrumb etc. But not in the grid template, also if i use another template it still doesn't show. Any idea what this can be? I tried looking for it, but my experience with Drupal is very limited.
I checked the drupal_get_title etc. and it is always returning the title, i think something goes wrong in the views module, but i don't know what :s
Kind regards,
Daan
The problem is most likely how you print the page title. If you want it to happen globally, you should print it in the page.tpl.php. Have you inspected the $title variable in the page template? That is what it's usually called.
i idd removed the title from page.tpl.php, but i did this because i thought it should be printed in the views template. When you check views-view-unformatted.tpl.php etc you see this:
<?php if (!empty($title)): ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
<div class="<?php print $classes[$id]; ?>">
<?php print $row; ?>
</div>
<?php endforeach; ?>
so i thought $title would print the title, but it is fixed just by adding it in my page.tpl.php

Resources