I'm using a plugin titled "WP Recent Links" which I first learned about via Eric Meyer's site. Eric uses to display a Link Log within his site and I'm doing the same on my test site - http://matala.jorgeledesma.net/ but I'm running into a little situation and that is that I don't know how to limit the output either on the sidebar or the actual page - http://matala.jorgeledesma.net/recent-links/
My goal is to have it echo only the first 5 entries on the sidebar and for the recent-links page only echo the current month. The code below displays the sidebar properly
<?php if (!is_page('48')) { ?>
<aside id="meta" class="widget">
<h1 class="widget-title">Link Log</h1>
<?php if ($links = rp_recentlinks_home()) { ?>
<ul>
<?php foreach ($links as $link) { ?>
<b><li><?php echo wptexturize($link->link_text); ?></b>
<?php if ('' != $link->link_caption) { ?>→
<?php echo wptexturize(convert_smilies($link->link_caption)); ?><?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</aside>
<?php } ?>
and this code display the actual recent-links page
<h1 class="page-title"><?php rp_recentlinks_archive_header(); ?></h1>
</header>
<div class="entry-content">
<?php $links = rp_recentlinks_archive_page(); ?>
</div>
<?php if ($links) { ?>
<ul>
<?php foreach ($links as $link) { ?>
<p id="rlink-<?php echo $link->ID; ?>"><?php echo wptexturize($link->link_text); ?>
<?php if ('' != $link->link_caption) { ?>→
<?php echo wptexturize(convert_smilies($link->link_caption)); ?><?php } ?>
</p>
<?php } ?>
</ul>
<?php } ?>
I tried putting the following code in the body.
$list = array_slice($input, 0, 5); // $list now only having first 5 item.
But I don't know how to apply it, if that's the command at all. So perhaps, someone can guide in the right direction. Thanks in advance, Jorge.
Looks like all you have to add is this before you pass $links to the foreach loop:
$links = array_slice($links,0,5);
Related
I am having problems pulling the pages through in PHP and HTML I have used :-
<li>
<!-- Pulling Categories from the database
dynamically -->
<?php
$nav_subjects = find_all_subjects(['visible' => $visible]);
while($nav_subject =
mysqli_fetch_assoc($nav_subjects)) {
?>
<span class="opener"><?php echo h($nav_subject['menu_name']); ?></span>
Which pulls the categories dynamically from the database and displays them with a drop down arrow just how I wanted but the pages will not show underneath them here's the code I have used for that bit:-
<!-- Categories listed correctly let's pull the pages for each one -->
<?php
if($nav_subject['id'] == $subject_id) {
$nav_pages = find_pages_by_subject_id($nav_subject['id'], ['visible' => $visible]);
while($nav_page = mysqli_fetch_assoc($nav_pages)) {
?>
<ul>
<li>
<?php echo h($nav_page['menu_name']); ?>
</li>
</ul>
<?php } // while $nav_pages
} // if($nav_subject['id'] == $subject_id)
} // while $nav_subjects ?>
</li>
<?php
mysqli_free_result($nav_subjects);
mysqli_free_result($nav_pages);
?>
I am pulling in the SQL from another page which is loaded correctly as the categories load and display correctly.
I will be grateful for any ideas.
I have also tried to echo back the sql result but nothing is shown.
I have now got it working with the following code:-
<li>
<?php $nav_subjects = find_all_subjects(['visible' => $visible]);
while($nav_subject = mysqli_fetch_assoc($nav_subjects)) {?>
<span class="opener"><?php echo h($nav_subject['menu_name']); ?></span>
<ul>
<?php if($nav_subject['id'] == $subject_id);
$nav_pages = find_pages_by_subject_id($nav_subject['id'], ['visible' => $visible]);
while($nav_page = mysqli_fetch_assoc($nav_pages)) { ?>
<li><?php echo h($nav_page['menu_name']); ?></li>
<?php } ?>
<?php } ?>
</ul>
But now it is listing the secondary subjects as a child of the first instead of individual subjects of their own.
*********Resolved**********
please advise if you think the code could be better i've currently used :-
<li>
<?php $nav_subjects = find_all_subjects(['visible' => $visible]);?>
<?php while($nav_subject = mysqli_fetch_assoc($nav_subjects)){?>
<span class="opener"><?php echo h($nav_subject['menu_name']);?></span>
<ul>
<?php if($nav_subject['id'] == $subject_id);
$nav_pages = find_pages_by_subject_id($nav_subject['id'], ['visible' => $visible]);
while($nav_page = mysqli_fetch_assoc($nav_pages)) { ?>
<a href="<?php echo url_for('index.php?id=' . h(u($nav_page['id']))); ?>">
<?php echo h($nav_page['menu_name']); ?></a>
<?php } ?>
<?php mysqli_free_result($nav_pages); ?>
</ul>
<?php } ?>
<?php mysqli_free_result($nav_subjects); ?>
</li>
I'm trying to give structure to my code and i am facing a problem.
I'm looping through a sql query response and for each element i'm trying to retrieve other related elements. It works in my controller without problem but when i'm trying to repeat in the view I always get the same value for the related element
My controller:
<?php
include_once('class/guide.class.php');
$bdd = new DBHandler();
$req = guide::getGuides($bdd,0,5);
foreach ($req as $results => $poi)
{
$req[$results]['id'] = htmlspecialchars($poi['id']);;
$req[$results]['name'] = nl2br(htmlspecialchars($poi['name']));
$guide = new guide($results['name'],$bdd);
$guidePois = $guide->getGuidePois($poi['id']);
foreach ($guidePois as $res => $re)
{
echo $guidePois[$res]['id'];
echo $guidePois[$res]['name'];
$guidePois[$res]['id'] = htmlspecialchars($re['id']);
$guidePois[$res]['name'] = nl2br(htmlspecialchars($re['name']));
}
}
include_once('listing.php');
here, you see that I echo the ids/names of the related list of element and it works well, the output is correct for each element of the first list.
When i do it in my view:
<?php
foreach($req as $poi)
{
?>
<div class="news">
<h3>
<?php echo $poi['id']; ?>
<em>: <?php echo $poi['name']; ?></em>
</h3>
<?php foreach($guidePois as $re)
{
?>
<h4>
<?php echo $re['id']; ?>:
<?php echo $re['name']; ?>
</h4>
<?php
}
?>
</div>
<?php
}
?>
Somehow the first list output are the good elements, but for the 2nd list, i always get the related elements of the first item.
Do you have an idea ?
Thanks a lot for your help
This is because you only set:
$guidePois = $guide->getGuidePois($poi['id']);
once in the controller.
If you want it to work in the view, you need to insert this code right after the closing </h3>
<?php $guidePois = $guide->getGuidePois($poi['id']); ?>
So that $guidePois gets a new value in each iteration.
Complete view code:
<?php
foreach($req as $poi)
{
?>
<div class="news">
<h3>
<?php echo $poi['id']; ?>
<em>: <?php echo $poi['name']; ?></em>
</h3>
<?php
$guidePois = $guide->getGuidePois($poi['id']);
foreach($guidePois as $re)
{
?>
<h4>
<?php echo $re['id']; ?>:
<?php echo $re['name']; ?>
</h4>
<?php
}
?>
</div>
<?php
}
?>
So I'm building a custom breadcrumb nav to list all fundraising options. The pages are using a unique layout called "fundraising_page." Is there a way to grab the pages only if they have the "fundraising_page" layout? So far I have this, which is grabbing every page regardless of the template it is using.
So what I need is only to list the pages that are using the "fundraising_page" template.
<?php $collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());?>
<?php $collection->getSelect()->where('is_active = 1'); ?>
<ul>
<?php foreach ($collection as $page): ?>
<?php $PageData = $page->getData(); ?>
<?php if($PageData['identifier']!='no-route'){ ?>
<li>
<?php echo $PageData['title'] ?>
</li>
<?php } ?>
<?php endforeach; ?>
Here's some well formatted code and using proper methods.
<?php
$collection = Mage::getModel('cms/page')->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addFieldToFilter('is_active', 1)
->addFieldToFilter('root_template', 'fundraising_page');
?>
<?php foreach ($collection as $page): ?>
<?php if ($page->getIdentifier() != 'no-route'): ?>
<li>
<?php echo $page->getTitle() ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
Instead of if($PageData['identifier']!='no-route') try
if($PageData['root_template']=='fundraising_page')
I am attempting to make a sortable list out of list items populated from the database using the jQuery plug in but the effect is only applied to the first item presented:
<?php if(isset($bookmarks)) : foreach($bookmarks as $row) :?>
<div id="makeDrag">
<?php $fixed = preg_replace('#^[^:/.]*[:/]+#i', '', $row->URL); ?>
<li>
<div class="well">
<div><?php echo anchor('http://'.$fixed, $row->Name); ?></div>
<div><strong>Comments:</strong> <?php echo $row->Comments; ?></div>
<h4 class="btn-small">
<?php echo anchor("site/delete/$row->id", "Delete"); ?>
</h4>
</li>
</div>
<?php endforeach; ?>
I can kind of see where this is going wrong but do not know how to fix it. I would obviously like the effect to affect all the populated li not just the first one. Any help would be great. Sorry if I am unclear, I can try and rephrase things if this is confusing.
The cause is likely because you have
$('#makeDrag').sortable();
but you also have a foreach statement that creates multiple #makeDrag elements thus making your HTML invalid.
To fix this:
<?php if(isset($bookmarks)) : ?>
<ul id="makeDrag">
<?php foreach($bookmarks as $row) : ?>
<?php $fixed = preg_replace('#^[^:/.]*[:/]+#i', '', $row->URL); ?>
<li>
<div class="well">
<div><?php echo anchor('http://'.$fixed, $row->Name); ?></div>
<div><strong>Comments:</strong> <?php echo $row->Comments; ?></div>
<h4 class="btn-small"><?php echo anchor("site/delete/$row->id", "Delete"); ?></h4>
</div>
</li>
<? endforeach; ?>
</ul>
<?php endif; ?>
HTH
i want to check via php if a page is a cms_page in Magento. I need diffrent breadcrumbs for cms pages, so im trying to this with a condition, but i have no idea how to or where to look at.
Heres my breadcrumbs.phtml so far.
<?php if(this is a cms page): ?>
<p>some content</p>
<?php else: ?>
<?php if($crumbs && is_array($crumbs)): ?>
<div class="breadcrumbs">
<ul>
<?php $charsges = 0; ?>
<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
<?php
$charsges = strlen($_crumbInfo['label']) + $charsges;
if($charsges > 40){
$chars = 18;
if(strlen($_crumbInfo['label']) > $chars){
$_crumbInfo['label'] = substr($_crumbInfo['label'], 0, $chars);
$_crumbInfo['label'] = $_crumbInfo['label'].'..';
}
}
?>
<li class="<?php echo $_crumbName ?>">
<?php if($_crumbInfo['link']): ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['label']) ?></strong>
<?php else: ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php endif; ?>
<?php if(!$_crumbInfo['last']): ?>
<span> > </span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
greets rito
The following should give you what you want
//from a block or phtml script
$this->getRequest()->getModuleName()
When this returns the string 'cms', you're on a CMS page.
When Magento's frontend and admin routers can't find a match on your URL, the CMS router takes over. If the CMS router finds a match (based on the CMS pages you've setup), it hands off the request to the cms module and Mage_Cms_IndexController controller.