I have a code chunk that is inside the_content(); I'm using acf repeater as well. So when I post a blog, I'll either use the_content(); or the acf field. I have h2 tag ( latest articles ) that I only want printed one time, but it's printing everytime I make a post.
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<div class="container">
<div class="row">
<div class="col-md-4 sidebar-r">
<?php echo the_content(); ?>
</div><!-- end sidebar-r -->
<?php
$i = $wp_query->post_count;
if($i <=1) {
echo '<h2 class="link-title">
<?php the_sub_field('link_title'); ?>,
</h2>';
}else{
echo '';
}
?>
<div class="col-md-8 links-wrap">
<?php if(have_rows('daily_links')): ?>
<?php while(have_rows('daily_links')): the_row(); ?>
<a href="<?php the_sub_field('link_url'); ?>" target="_blank">
<h2 class="link-title">
<?php the_sub_field('link_title'); ?>,
</h2>
<h3 class="link-source">
<?php the_sub_field('link_source'); ?>
</h3>
</a>
<?php endwhile; ?>
<?php endif; ?>
</div><!-- end links wrap -->
</div><!-- end row -->
</div><!-- end container -->
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
You'll see I tried using php to count the posts and if more than one post, don't print the tag, but couldn't figure out the exact logic and syntax.
I am honestly struggling a bit to understand exactly what you are trying to do and since I do not even have the posts and other key pieces of information so that I can properly replicate your issue so that I can help you better, this is a little bit challenging. That being said, looking into some ideas I came across another stackoverflow question/answer that might be relevant for you in catching the first post and does something to it. The answer to the referenced question instance was this:
<?php if (have_posts()) : $postCount = 1; while (have_posts()) : $postCount++; ?>
<?php if($postCount == 2) { ?>
// SOMETHING TO DO WITH FIRST POST
<?php } else { ?>
// SOMETHING TO DO WITH ALL OTHER POSTS
<?php } ?>
This was suggested by user Bora in this answer from 2013.
Let me know if that helped!
Hi I am new to Drupal Development.
I am trying to alter comment section of article content.
My requirement is I want to change the header in [Comment Section] 1 from Add New Comments to to add new review and comments to previous reviews ,and subject to review subject in my subtheme which uses bartik as base theme.
Can anyone help me.
Here is the code which I altered in comment-wrapper-article.tpl.php in sub theme.But I can't alter the display.
<?php
<div id="comments" class="<?php print $classes; ?>"<?php print $attributes; ?>>
<?php if ($node->type == 'article'): && $node->type == 'article');?>
<?php print render($title_prefix); ?>
<h2 class="title"><?php print t('previous Reviews'); ?></h2>
<?php print render($title_suffix); ?>
<?php endif; ?>
<?php print render($content['comments'] ?>
<?php if ($content['comment_form']): ?>
<h2 class="title comment-form"><?php print t('Add New Review'); ?></h2>
<?php print render($content['comment_form']); ?>
<?php endif; ?>
?>
Finally I had Succeed in getting the solution to the problem, in case if any one faces the same problem.Here is the solution.
<div id="comments" class="<?php print $classes; ?>"<?php print $attributes; ?>>
<?php if ($content['comments'] && $node->type != 'forum'): ?>
<?php print render($title_prefix); ?>
<h2 class="title"><?php print t('Previous Reviews'); ?></h2>
<?php print render($title_suffix); ?>
<?php endif; ?>
<?php print render($content['comments']); ?>
<?php if ($content['comment_form']): ?>
<h2 class="title comment-form"><?php print t('Add New Review'); ?></h2>
<?php print render($content['comment_form']); ?>
<?php endif; ?>
</div>
the main requirement is the file name should be in the following format."comment-wrapper--node-contenttype.tpl.php"
I am working with the following codes for Magento inside product page view.phtml.
<div class="manufacturer">
<?php if ($_product->getAttributeText('manufacturer') == "Bellazza" || "Della" || "Pet Zone" || "Spyder Auto" ):?>
<div class="dealer">
<p>Authorized Dealer:</p>
</div>
<div class="logoImg">
<?php echo $this->getLayout()->createBlock('manufacturer/manufacturer')->setProduct($_product)->setTemplate('manufacturer/product_manufacturer.phtml')->toHtml();?>
</div>
<?php elseif ?>
<?php endif;?>
</div>
So I create div.manufacturer to display associated brand logo image started by the title "Authorized Dealer". It works. But not all products have a brand so when I set the manufacturer attribute to empty ( refer to the image below ) I don't need the title "Authorized Dealer" anymore. What is the best practice to approach the elseif. Thank you
manufacturer/manufacturer.phtml
<?php
$maufacturers = Mage::getModel('manufacturer/manufacturer')->getCollection()->addFieldToFilter('status',Array('eq'=>1));
$_columnCount=4;
$i=0;
?>
<div class="manufacturer-list">
<?php foreach($maufacturers as $manufacturer): ?>
<?php if(Mage::getModel('eav/entity_attribute_source_table')->setAttribute(Mage::getModel('eav/entity_attribute')->load(Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product',"manufacturer")))->getOptionText($manufacturer->getMenufecturerName())): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul>
<?php endif; ?>
<li>
<a href="<?php echo $this->getBaseUrl()."catalogsearch/advanced/result/?manufacturer[]=".$manufacturer->getMenufecturerName() ?>">
<?php echo $this->getLayout()->createBlock('core/template')->setmanufacturerimage($manufacturer->getFilename())->setlegend($manufacturer->getLegend())->setListPageFlag(1)->setTemplate('manufacturer/manufacturer_resize.phtml')->toHtml(); ?>
</a>
<div class="manufacturer-name">
<?php echo Mage::getModel('eav/entity_attribute_source_table')->setAttribute(Mage::getModel('eav/entity_attribute')->load(Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product',"manufacturer")))->getOptionText($manufacturer->getMenufecturerName()) ?>
</div>
</li>
<?php if ($i%$_columnCount==0 && $i!=count($maufacturers)): ?>
</ul>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
</div>
product_manufacturer
<?php
$product=$this->getProduct();
if(Mage::getModel('eav/entity_attribute_source_table')->setAttribute(Mage::getModel('eav/entity_attribute')->load(Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product',"manufacturer")))->getOptionText($product->getData('manufacturer'))):
$manufacturers=Mage::getModel('manufacturer/manufacturer')->getCollection()->addFieldToFilter('menufecturer_name',$product->getData('manufacturer'));
foreach($manufacturers as $manufacturer){
$status=$manufacturer->getStatus();
if($status==1){
?>
<div class="manufacturer-img-box">
<a href="<?php echo $this->getBaseUrl()."catalogsearch/advanced/result/?manufacturer[]=".$manufacturer->getMenufecturerName() ?>">
<?php echo $this->getLayout()->createBlock('core/template')->setmanufacturerimage($manufacturer->getFilename())->setlegend($manufacturer->getLegend())->setTemplate('manufacturer/manufacturer_resize.phtml')->toHtml(); ?>
</a>
</div>
<?php }
}
endif;
?>
You need refactoring the code
<div class="manufacturer">
<div class="logoImg">
<?php echo $this->getLayout()->createBlock('manufacturer/manufacturer')->setProduct($_product)->setTemplate('manufacturer/product_manufacturer.phtml')->toHtml();?>
</div>
</div>
and check variable
<?php if(!is_null($manufacturer->getMenufecturerName())): ?>
<div class="manufacturer-name">
<?php
echo Mage::getModel('eav/entity_attribute_source_table')
->setAttribute(Mage::getModel('eav/entity_attribute')
->load(Mage::getModel('eav/entity_attribute')
->getIdByCode('catalog_product',"manufacturer")))
->getOptionText($manufacturer->getMenufecturerName())
?>
</div>
<?php endif; ?>
And you need refactoring your code. Because I loock much excess code in your template. You need get data in you block and in phtml you need render this data by API blocks. getImageSrc(); getManufactures() and more over methods for get processed information.
I'm trying to create a different layout on my blog posts page depending on when the post is created. so blog post 1 will have one class while post two will have another and post 3 will have a final class. hard to explain but here is my code hopefully it will make more sense:
<?php
if(have_posts()):
while(have_posts()): the_post();
$counter = 1;
?>
<?php if($counter == 1){ ?>
<div class="new-row">
<div class="boxes picture-box contact-smaller-box">
<?php the_post_thumbnail(); ?>
</div><!--/.picture box-->
<div class="boxes white-box contact-smaller-box">
<div class="box-inner right-side">
<h2><?php the_title(); ?></h2>
<p><?php echo substr(get_the_excerpt(), 0,70); ?></p>
Read More
</div><!--/.box inner-->
<div class="arrow arrow-left"><img src="..."></div>
</div><!--/.white box-->
</div><!--/.new row-->
<?php $counter = $counter++; ?>
<?php } if($counter == 2){?>
<!-- second section of the blog post content -->
<div class="new-row">
<div class="boxes pink-box contact-smaller-box">
<div class="box-inner">
<h2><?php the_title(); ?></h2>
<p><?php echo substr(get_the_excerpt(), 0,70); ?></p>
Read More
</div><!--/.box inner-->
<div class="arrow arrow-right"><img src="..."></div>
</div><!--/.pink box-->
<div class="boxes picture-box contact-smaller-box">
<img src="..." alt="hearing aids for adults">
</div><!--/.picture box-->
</div><!--/.new row-->
<?php } ?>
<?php
endwhile;
endif;
?>
At the moment both of my test posts are showing as the first type of post, so im thinking my counter is not working correctly, or i have my divs in the wrong position to make this work. im new at working with php so i dont know where i am going wrong. any advice would be brilliant.
After about 4 hours of research and testing different things out i have found a solution (credit):
<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php if ($count == 1) : ?>
Add your Custom Post Divs Here for the 1st post.
<?php elseif ($count == 2) : ?>
Add your Custom Post Divs Here for the 2nd post.
<?php elseif ($count == 3) : ?>
Add your Custom Post Divs Here for the 3rd post.
<?php elseif ($count == 4) : ?>
Add your Custom Post Divs Here for the 4th post.
<?php else : ?>
Add your Custom Post Divs Here for the rest of the posts.
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
hope it helps someone else out.
I am trying to setup a custom page, you can take a look here:
http://dageniusmarketer.com/download-the-book-now
and im using this code for my custom page. The sidebars as far as i can tell have IDs of "navigation", and "sidebar", however, the rules i am applying to them are not working. I tried a test rule with the ID "content", and it works as expected. Why am i not able to hide the sidebars? Something isn't making sense.
<?php
/*
* Template Name: My Custom Page
* Description: A Page Template with No Sidebars.
*/
?>
<?php get_header(); ?>
<!--single.php-->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post">
<h2 id="post-<?php the_ID(); ?>">
<a href="<?php echo get_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
<?php the_title(); ?></a></h2>
<?php the_content(); ?>
<?php wp_link_pages(); ?>
<p class="metadata">
<?php printf(__('%1$s %2$s', 'mtsgossip'), $time_since, get_the_time(__('l, F jS, Y', 'mtsjourney')), get_the_time()); ?>,
<?php _e('by ','mtsjourney');?> <?php the_author();?>
<?php _e('and is filed under','mtsjourney'); ?> "<?php the_category(', ') ?> ".
<?php if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
// Kommentare und Pingen erlaubt ?>
<?php _e('You can','mtsjourney'); ?> <?php _e('leave a response here','mtsjourney'); ?>,
<?php _e('or send a','mtsjourney'); ?>
<a href="<?php trackback_url(true); ?>" ><?php _e('Trackback','mtsjourney'); ?></a>
<?php _e('from your own site','mtsjourney'); ?>.
<?php } elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
// Nur Pingen erlaubt ?>
<?php _e('Responses are currently closed, but you can send a','mtsjourney'); ?>
<a href="<?php trackback_url(true); ?>" >
<?php _e('Trackback','mtsjourney'); ?></a>
<?php _e('from your own site','mtsjourney'); ?>.
<?php } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
// Kommentare geschlossen, Pingen erlaubt ?>
<?php _e('You can','mtsjourney'); ?>
<?php _e('leave a response here','mtsjourney'); ?>.
<?php _e('Pinging is currently not allowed','mtsjourney'); ?>.
<?php } elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
// Kommentare und Pings sind nicht erlaubt. ?>
<?php _e('Both comments and pings are currently closed','mtsjourney'); ?>.
<?php } edit_post_link('E','',''); ?>
</p>
</div>
<div id="navigation" style="margin-left:200px;"></div>
<div id="sidebar" style="display:none"></div>
<div id="content" style="width:900px"></div>
<!--postend-->
<p class="navigate">
<?php previous_post_link('« %link') ?>
||
<?php next_post_link(' %link »') ?>
</p>
<?php endwhile; endif;?>
<!--post end-->
<!--single.php end-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Looking at the page structure, I tried to remove left and right sidebar by adding following styles.
Put the following styles as inline css in the desired template, so that it don't affect the layout of any other page. Hope this helps.
div#navigation
{
display:none;
}
div#sidebar
{
display:none;
}
div#content
{
margin: 5px 0 75px 0;
}
Your sidebar is being called with this line:
<?php get_sidebar(); ?>
You can try commenting it out to hide the sidebar:
<?php //get_sidebar(); ?>
You have two divs with the "sidebar" id, the one we can see in the code you posted (Which has the styles) and the one that eventually gets created by <?php get_sidebar(); ?>
These are not the same elements, so to fix your problem just remove that superfluous sidebar and apply the styles in your stylesheet.
Why dont you delete all the content of sidebar.php? so, all other files that call it will show nothing.
your sidebar is being called with this line
<?php get_sidebar(); ?>
try to comment it