How is this plugin creating multiple pages within the same plugin? - php

I'm extending an already existing plugin called Anspress. I'm new to wordpress/web dev and I can't figure out how the author makes different pages show up without creating different page templates. These images show how there is only 1 page template in the dashboard using a single shortcode. Within this "page" created by the plugin, there are links to load other sections of the plugin, such as user profiles, individual questions and their responses, and the main question list.
In a nutshell, his code layout is as follows:
main.php
{
require_once 'FileA.php'
require_once 'FileB.php'
require_once 'FileC.php'
require_once 'FileD.php'
/// Etc...
}
None of the files above are ask.php, which is the PHP file used to hold the HTML for the ask-question page. Yet he can still make this ask.php file somehow generate the page when a user clicks on the "Ask a question" button. How does this work? Below is the code for ask.php
<?php
// Some comment about the HTML code below
?>
<div id="ap-ask-page" class="clearfix">
<?php if (ap_user_can_ask()): ?>
<div id="answer-form-c">
<div class="ap-avatar ap-pull-left">
<a href="<?php echo ap_user_link(get_current_user_id()); ?>"<?php ap_hover_card_attributes(get_current_user_id()); ?>>
<?php echo get_avatar(get_current_user_id(), ap_opt('avatar_size_qquestion')); ?>
</a>
</div>
<div class="ap-a-cells clearfix">
<div class="ap-form-head">
<?php _e('Toggle fullscreen', 'ap'); ?>
<ul class="ap-form-head-tab ap-ul-inline clearfix ap-tab-nav">
<li class="active"><?php _e('Write', 'ap'); ?></li>
<?php if(ap_opt('question_help_page') != '') : ?>
<li><?php _e('How to ask', 'ap'); ?></li>
<?php endif; ?>
</ul>
</div>
<div class="ap-tab-container">
<div id="ap-form-main" class="active ap-tab-item">
<?php ap_ask_form(); ?>
</div>
<div id="ap-form-help" class="ap-tab-item">
<?php if(ap_opt('question_help_page') != ''): ?>
<?php ap_how_to_ask(); ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php elseif (is_user_logged_in()): ?>
<div class="ap-no-permission">
<?php _e('You don\'t have permission to ask question.', 'ap'); ?>
</div>
<?php endif; ?>
<?php ap_get_template_part('login-signup'); ?>
</div>
I can provide more info as needed.

Related

Wordpress WP-PageNavi Not working with specific category post on homepage

I'm using the following code to display recent posts from a specific category on the homepage of my WordPress website.
<div class="frontleft">
<div id="four-columns" class="grid-container" style="display:block;">
<?php $catquery = new WP_Query( 'cat=3&posts_per_page=24' ); ?>
<ul class="rig columns-4">
<?php while($catquery->have_posts()) : $catquery->the_post(); ?>
<li>
<a href="<?php the_permalink() ?>">
<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
</a>
<h3>
<?php the_title(); ?>
</h3>
</li>
<?php endwhile; ?>
</ul>
</div>
<div class="navigation">
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
<?php } ?>
</div>
</div>
Issue: WP-pageNavi plugin isn't working correctly.
Note: I'm able to open website.com/page/2 without having any issues. But the post list is precisely the same on each page.
How to fix it?
If I were you I would just use different Page Templates for homepage and other pages.
It's hard to debug a plugin that we aren't using.
There is a function in Wordpress is_page() where you can input the name of the page in the para. Throwing that in an if statement is also another way to separate the posts.
There are a ton of ways to achieve what your looking for without the use of a plugin.

How to add custom div in wordpress static page

Here I have a Wordpress theme, which is working fine.
Now I want to append my custom div under existing content. here are 2 existing panels which are following:
I'm new comer in WordPress so kindly assist me, how to achieve this requirement. your kind efforts would be heartily appreciated.
STEP 1: Open your wp-content->themes->your Theme Name-> footer.php
at very top beginning add div there but make sure it will show on all page.
Example:
<div class="infooterfile"></div>
<footer>
<div class="footer-wrap">
<div class="icoach-section">
<div class="footer-logo fadeIn animated">
<?php
$icoach_dark_logo=get_theme_mod('icoach_dark_logo');
$icoach_dark_logo=wp_get_attachment_url($icoach_dark_logo);
?>
<?php if($icoach_dark_logo != '' && !empty($icoach_dark_logo)): ?>
<img class="img-responsive" src="<?php echo esc_url($icoach_dark_logo); ?>" alt="<?php esc_attr_e('Logo','icoach');?>">
<?php endif; ?>
</div>
NOTE: If you want to show it only home page then you need to add div above <?php get_footer(); ?> in home page separate template.
EXAMPLE: in homepage separate template
<?php
/**
* The main template file
**/
get_header(); ?>
<div class="heading-wrap blog-heading-wrap" >
<div class="heading-layer">
<div class="heading-title">
<h1><?php _e('Blog ','icoach'); ?></h1>
</div>
</div>
</div>
<div class="yourdiv"></div>
<?php get_template_part('content'); get_footer(); ?>

magento do not display title and logo when manufacturer attribute is set to empty

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.

Link new php page wordpress

I'm trying to use bootstrap tabs in my index.php theme to show diferent content in the main page theme.
I've implemented the tabs in index.php and create new page called popular-post.php linked in the tab Popular.
But when I click in the link to show popular content I get
Fatal error: Call to undefined function get_header() in
This is the code of my index.php
<?php get_header(); ?>
<div class="row" id="content">
<div class="col-sm-8 col-md-8 col-lg-8" id="primary">
<ul class="nav nav-tabs">
<li class="active">Home</li>
<li>Popular</li>
<li>Recientes</li>
</ul>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile;?>
<?php /* Pagnavi plugin support */ wp_pagenavi(); ?>
<?php else: ?>
<?php get_template_part( 'no-results', 'index' ); ?>
<?php endif; ?>
</div>
<div class="col-sm-4 col-md-4 col-lg-4" id="secondary">
<?php get_sidebar(); ?>
</div>
</div><!--/content-->
<?php get_footer(); ?>
An this is the code of popular-post.php
<?php
/*
Template Name: Popular Posts
*/
?>
<?php get_header(); ?>
<div class="row" id="content">
<div class="col-sm-8 col-md-8 col-lg-8" id="primary">
<ul class="nav nav-tabs">
<li>Home</li>
<li class="active">Popular</li>
<li>Recientes</li>
</ul>
<ul class="popular_posts">
<?php $pc = new WP_Query('orderby=comment_count&posts_per_page=10');
while ($pc->have_posts()) : $pc->the_post(); ?>
<li><?php the_title(); ?>
<p>Posted by <strong><?php the_author() ?></strong> with <?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></p></li>
<?php endwhile; ?>
</ul>
</div>
<div class="col-sm-4 col-md-4 col-lg-4" id="secondary">
<?php get_sidebar(); ?>
</div>
</div><!--/content-->
<?php get_footer(); ?>
Thanks in advance
You can't link to a theme file directly like: Popular.
This is an invalid URL: http://example.com/wp-content/themes/YOUR-THEME/any-theme-file.php.
Create a new page, "Popular Posts", select the template (your file already has a Page Template header. Take note of the page ID (in the URL). And link like:
Popular
This produces a valid URL: http://example.com/popular-posts/, which is a piece of your content (a page), that uses the defined page template file.
To get the page ID by its title use get_page_by_title:
$the_page = get_page_by_title('popular-posts');
echo 'Popular';
Reading about the Template Hierarchy will also help.

Displaying threaded comments without wp_list_comments()

I am creating a custom comment layout, therefor I'm not using wp_list_comments(). My problem is that I can't seem to figure out for to effectively display replied comments in one another (threaded).
So far I have it so it only show the top most layer of comments.
<ol class="commentlist">
<?php foreach ($comments as $comment) : ?>
<?php if($comment->comment_parent == 0): ?>
<li class="comment">
<div class="main">
<div class="name">
<?php if(get_comment_author_url()): ?>
<?php comment_author(); ?>
<?php else: ?>
<?php comment_author(); ?>
<?php endif; ?>
</div>
<div class="text"><?php comment_text(); ?></div>
</div>
<div class="info">
<?= get_avatar($comment, $size = '90'); ?>
<div class="month"><?= comment_date('M'); ?></div>
<div class="day"><?= comment_date('dS'); ?></div>
<div class="year"><?= comment_date('Y'); ?></div>
</div>
<div class="clear"></div>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ol>
I know want to display the comments that are replies within this comment.
I have seen your code, i think there is restriction for the child comments. you had condition where parent comments will displaying only.
You need to create one more class OR CSS for child comments and for that also need to run loop inside this FOREACH loop and displaying only that childes where Parent would be the
$comment->comment_parent
.
I think i am right if i get your prob.
Thanks.
I have figured out how to achieve threaded comments while using a custom layout.
Inside of your functions.php file place the following code:
<?php function comment_layout($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
// Your custom layout here
<?php } ?>
Now, inside your comments.php file simply places the following where you would like the comments to appear.
<?php wp_list_comments( array( 'callback' => 'comment_layout' ) ); ?>
What will this do is, loop through all the comments (in the correct order) and call your custom layout to display the comment.

Categories